Deprecation warnings for scripted fields (#9193)

* Add deprecation notice to scripted field creation page

* Add deprecation warning to scripted field list

* Review updates

* Added painless doc link to field editor deprecation warning
* Extracted scripting lang logic into a reuseable module
* Fixed issue where deprecation warning showed on field editor page if
  scripting was completely disabled in ES
This commit is contained in:
Matt Bargar 2016-12-12 16:33:09 -05:00 committed by GitHub
parent 1668d740c7
commit 3aea8e23c5
5 changed files with 61 additions and 10 deletions

View file

@ -11,6 +11,19 @@
</a>
</header>
<div class="hintbox" ng-if="getDeprecatedLanguagesInUse().length !== 0">
<h4>
<i class="fa fa-warning text-warning"></i> Deprecation Warning
</h4>
<p>
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 target="_window" ng-href="{{docLinks.painless}}">Painless <i class="fa-link fa"></i></a>.
</p>
</div>
<paginated-table
columns="columns"
rows="rows"

View file

@ -5,6 +5,8 @@ import controlsHtml from 'plugins/kibana/management/sections/indices/_field_cont
import dateScripts from 'plugins/kibana/management/sections/indices/_date_scripts';
import uiModules from 'ui/modules';
import scriptedFieldsTemplate from 'plugins/kibana/management/sections/indices/_scripted_fields.html';
import { getSupportedScriptingLangs } from 'ui/scripting_langs';
import { scriptedFields as docLinks } from 'ui/documentation_links/documentation_links';
uiModules.get('apps/management')
.directive('scriptedFields', function (kbnUrl, Notifier, $filter) {
@ -22,6 +24,7 @@ uiModules.get('apps/management')
const fieldCreatorPath = '/management/kibana/indices/{{ indexPattern }}/scriptedField';
const fieldEditorPath = fieldCreatorPath + '/{{ fieldName }}';
$scope.docLinks = docLinks;
$scope.perPage = 25;
$scope.columns = [
{ title: 'name' },
@ -99,6 +102,12 @@ uiModules.get('apps/management')
$scope.remove = function (field) {
$scope.indexPattern.removeScriptedField(field.name);
};
$scope.getDeprecatedLanguagesInUse = function () {
const fields = $scope.indexPattern.getScriptedFields();
const langsInUse = _.uniq(_.map(fields, 'lang'));
return _.difference(langsInUse, getSupportedScriptingLangs());
};
}
};
});

View file

@ -26,6 +26,17 @@
<div ng-if="editor.field.scripted" class="form-group">
<label>Language</label>
<div class="hintbox" ng-if="editor.field.lang && !editor.isSupportedLang(editor.field.lang)">
<h4>
<i class="fa fa-warning text-warning"></i> Deprecation Warning
</h4>
<p>
<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 target="_window" ng-href="{{editor.docLinks.painless}}">Painless <i class="fa-link fa"></i></a>
for new scripted fields.
</p>
</div>
<select
ng-model="editor.field.lang"
ng-options="lang as lang for lang in editor.scriptingLangs"

View file

@ -10,12 +10,14 @@ import chrome from 'ui/chrome';
import IndexPatternsCastMappingTypeProvider from 'ui/index_patterns/_cast_mapping_type';
import { scriptedFields as docLinks } from '../documentation_links/documentation_links';
import './field_editor.less';
import { GetEnabledScriptingLangsProvider, getSupportedScriptingLangs } from '../scripting_langs';
uiModules
.get('kibana', ['colorpicker.module'])
.directive('fieldEditor', function (Private, $sce) {
let fieldFormats = Private(RegistryFieldFormatsProvider);
let Field = Private(IndexPatternsFieldProvider);
let getEnabledScriptingLangs = Private(GetEnabledScriptingLangsProvider);
const fieldTypesByLang = {
painless: ['number', 'string', 'date', 'boolean'],
@ -36,7 +38,7 @@ uiModules
let notify = new Notifier({ location: 'Field Editor' });
self.docLinks = docLinks;
getScriptingLangs().then((langs) => {
getEnabledScriptingLangs().then((langs) => {
self.scriptingLangs = langs;
if (!_.includes(self.scriptingLangs, self.field.lang)) {
self.field.lang = undefined;
@ -87,6 +89,10 @@ uiModules
});
};
self.isSupportedLang = function (lang) {
return _.contains(getSupportedScriptingLangs(), lang);
};
$scope.$watch('editor.selectedFormatId', function (cur, prev) {
let format = self.field.format;
let changedFormat = cur !== prev;
@ -158,15 +164,6 @@ uiModules
else return fieldFormats.getDefaultType(self.field.type);
}
function getScriptingLangs() {
return $http.get(chrome.addBasePath('/api/kibana/scripts/languages'))
.then((res) => res.data)
.catch(() => {
notify.error('Error getting available scripting languages from Elasticsearch');
return [];
});
}
function initDefaultFormat() {
let def = Object.create(fieldFormats.getDefaultType(self.field.type));

View file

@ -0,0 +1,21 @@
import chrome from 'ui/chrome';
import Notifier from 'ui/notify/notifier';
import { intersection } from 'lodash';
const notify = new Notifier({ location: 'Scripting Lang Service' });
export function getSupportedScriptingLangs() {
return ['expression', 'painless'];
}
export function GetEnabledScriptingLangsProvider($http) {
return () => {
return $http.get(chrome.addBasePath('/api/kibana/scripts/languages'))
.then((res) => res.data)
.catch(() => {
notify.error('Error getting available scripting languages from Elasticsearch');
return [];
});
};
}