Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate expression based scripted fields #14281

Merged
merged 3 commits into from
Nov 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,48 @@ <h3 class="kuiTextTitle kuiVerticalRhythm">
These scripted fields are computed on the fly from your data. They can be used in visualizations and displayed in your documents, however they can not be searched. You can manage them here and add new ones as you see fit, but be careful, scripts can be tricky!
</p>

<div class="kuiInfoPanel kuiInfoPanel--warning kuiVerticalRhythm" ng-if="getDeprecatedLanguagesInUse().length !== 0">
<div class="kuiInfoPanelHeader">
<span
class="kuiInfoPanelHeader__icon kuiIcon kuiIcon--warning fa-bolt"
aria-label="Warning"
role="img"
></span>
<span class="kuiInfoPanelHeader__title">
Deprecation Warning
</span>
</div>

<div class="kuiInfoPanelBody">
<div class="kuiInfoPanelBody__message">
We've detected that the following deprecated languages are in use: {{ getDeprecatedLanguagesInUse().join(', ') }}.
Support for these languages will be removed in the next major version of Kibana and Elasticsearch.
We recommend converting your scripted fields to
<a class="kuiLink" ng-href="{{docLinks.painless}}">Painless</a>.
</div>
</div>
</div>

<div class="kuiInfoPanel kuiInfoPanel--error kuiVerticalRhythm" ng-if="getUnsupportedLanguagesInUse().length !== 0">
<div class="kuiInfoPanelHeader">
<span
class="kuiInfoPanelHeader__icon kuiIcon kuiIcon--error fa-warning"
aria-label="Error"
role="img"
></span>
<span class="kuiInfoPanelHeader__title">
Unsupported Languages
</span>
</div>

<div class="kuiInfoPanelBody">
<div class="kuiInfoPanelBody__message">
We've detected that the following unsupported languages are in use: {{ getUnsupportedLanguagesInUse().join(', ') }}.
All scripted fields should be converted to <a class="kuiLink" ng-href="{{docLinks.painless}}">Painless</a>.
</div>
</div>
</div>

<a
data-test-subj="addScriptedFieldLink"
ng-href="{{ kbnUrl.getRouteHref(indexPattern, 'addField') }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import fieldControlsHtml from '../field_controls.html';
import { dateScripts } from './date_scripts';
import { uiModules } from 'ui/modules';
import template from './scripted_fields_table.html';
import { getSupportedScriptingLanguages, getDeprecatedScriptingLanguages } from 'ui/scripting_languages';
import { documentationLinks } from 'ui/documentation_links/documentation_links';

uiModules.get('apps/management')
.directive('scriptedFieldsTable', function (kbnUrl, Notifier, $filter, confirmModal) {
Expand All @@ -21,6 +23,7 @@ uiModules.get('apps/management')
const fieldCreatorPath = '/management/kibana/indices/{{ indexPattern }}/scriptedField';
const fieldEditorPath = fieldCreatorPath + '/{{ fieldName }}';

$scope.docLinks = documentationLinks.scriptedFields;
$scope.perPage = 25;
$scope.columns = [
{ title: 'name' },
Expand Down Expand Up @@ -110,6 +113,19 @@ uiModules.get('apps/management')
};
confirmModal(`Are you sure want to delete ${field.name}? This action is irreversible!`, confirmModalOptions);
};

function getLanguagesInUse() {
const fields = $scope.indexPattern.getScriptedFields();
return _.uniq(_.map(fields, 'lang'));
}

$scope.getDeprecatedLanguagesInUse = function () {
return _.intersection(getLanguagesInUse(), getDeprecatedScriptingLanguages());
};

$scope.getUnsupportedLanguagesInUse = function () {
return _.difference(getLanguagesInUse(), _.union(getSupportedScriptingLanguages(), getDeprecatedScriptingLanguages()));
};
}
};
});
23 changes: 22 additions & 1 deletion src/ui/public/field_editor/field_editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,33 @@

<div ng-if="editor.field.scripted" class="form-group">
<label for="scriptedFieldLang">Language</label>
<div class="kuiInfoPanel kuiInfoPanel--warning kuiVerticalRhythm" ng-if="editor.field.lang && editor.isDeprecatedLang(editor.field.lang)">
<div class="kuiInfoPanelHeader">
<span
class="kuiInfoPanelHeader__icon kuiIcon kuiIcon--warning fa-bolt"
aria-label="Warning"
role="img"
></span>
<span class="kuiInfoPanelHeader__title">
Deprecation Warning
</span>
</div>

<div class="kuiInfoPanelBody">
<div class="kuiInfoPanelBody__message">
<span class="text-capitalize">{{editor.field.lang}}</span> is deprecated and support will be removed in the
next major version of Kibana and Elasticsearch. We recommend using
<a class="kuiLink" ng-href="{{editor.docLinks.painless}}">Painless</a>
for new scripted fields.
</div>
</div>
</div>
<select
ng-model="editor.field.lang"
id="scriptedFieldLang"
ng-options="lang as lang for lang in editor.scriptingLangs"
required
class="form-control"
class="form-control kuiVerticalRhythm"
data-test-subj="editorFieldLang">
<option value="">-- Select Language --</option>
</select>
Expand Down
14 changes: 11 additions & 3 deletions src/ui/public/field_editor/field_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import { uiModules } from 'ui/modules';
import fieldEditorTemplate from 'ui/field_editor/field_editor.html';
import '../directives/documentation_href';
import './field_editor.less';
import { GetEnabledScriptingLanguagesProvider, getSupportedScriptingLanguages } from '../scripting_languages';
import {
GetEnabledScriptingLanguagesProvider,
getSupportedScriptingLanguages,
getDeprecatedScriptingLanguages
} from '../scripting_languages';
import { getKbnTypeNames } from '../../../utils';

uiModules
Expand Down Expand Up @@ -38,7 +42,7 @@ uiModules
const notify = new Notifier({ location: 'Field Editor' });

getScriptingLangs().then((langs) => {
self.scriptingLangs = _.intersection(langs, ['expression', 'painless']);
self.scriptingLangs = langs;
if (!_.includes(self.scriptingLangs, self.field.lang)) {
self.field.lang = undefined;
}
Expand Down Expand Up @@ -103,6 +107,10 @@ uiModules
);
};

self.isDeprecatedLang = function (lang) {
return _.contains(getDeprecatedScriptingLanguages(), lang);
};

$scope.$watch('editor.selectedFormatId', function (cur, prev) {
const format = self.field.format;
const changedFormat = cur !== prev;
Expand Down Expand Up @@ -179,7 +187,7 @@ uiModules
function getScriptingLangs() {
return getEnabledScriptingLanguages()
.then((enabledLanguages) => {
return _.intersection(enabledLanguages, getSupportedScriptingLanguages());
return _.intersection(enabledLanguages, _.union(getSupportedScriptingLanguages(), getDeprecatedScriptingLanguages()));
});
}

Expand Down
6 changes: 5 additions & 1 deletion src/ui/public/scripting_languages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { Notifier } from 'ui/notify/notifier';
const notify = new Notifier({ location: 'Scripting Language Service' });

export function getSupportedScriptingLanguages() {
return ['expression', 'painless'];
return ['painless'];
}

export function getDeprecatedScriptingLanguages() {
return ['expression'];
}

export function GetEnabledScriptingLanguagesProvider($http) {
Expand Down