From 001dc1ae55364d99774a8065c66827670a30d174 Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Tue, 18 Jun 2019 16:41:19 +0300 Subject: [PATCH 01/25] Shim server side to new platform --- .../metrics/{index.js => index.ts} | 23 ++++++------ .../search_strategies_register.js | 2 +- .../search_strategies_register.test.js | 4 ++- .../core_plugins/metrics/server/np/index.ts | 25 +++++++++++++ .../core_plugins/metrics/server/np/plugin.ts | 35 +++++++++++++++++++ .../metrics/server/routes/fields.js | 2 +- .../core_plugins/metrics/server/routes/vis.js | 2 +- 7 files changed, 79 insertions(+), 14 deletions(-) rename src/legacy/core_plugins/metrics/{index.js => index.ts} (70%) create mode 100644 src/legacy/core_plugins/metrics/server/np/index.ts create mode 100644 src/legacy/core_plugins/metrics/server/np/plugin.ts diff --git a/src/legacy/core_plugins/metrics/index.js b/src/legacy/core_plugins/metrics/index.ts similarity index 70% rename from src/legacy/core_plugins/metrics/index.js rename to src/legacy/core_plugins/metrics/index.ts index 0771bf9726c27..f4baf7a9e2a9b 100644 --- a/src/legacy/core_plugins/metrics/index.js +++ b/src/legacy/core_plugins/metrics/index.ts @@ -18,13 +18,16 @@ */ import { resolve } from 'path'; +import { Legacy } from 'kibana'; +import { PluginInitializerContext } from 'src/core/server'; +import { InternalCoreSetup } from 'src/core/server'; +import { metricPlugin } from './server/np/'; -import { fieldsRoutes } from './server/routes/fields'; -import { visDataRoutes } from './server/routes/vis'; -import { SearchStrategiesRegister } from './server/lib/search_strategies/search_strategies_register'; - -export default function(kibana) { +// eslint-disable-next-line import/no-default-export +export default function(kibana: any) { return new kibana.Plugin({ + id: 'metrics', + require: ['kibana', 'elasticsearch'], uiExports: { @@ -33,7 +36,7 @@ export default function(kibana) { styleSheetPaths: resolve(__dirname, 'public/index.scss'), }, - config(Joi) { + config(Joi: any) { return Joi.object({ enabled: Joi.boolean().default(true), chartResolution: Joi.number().default(150), @@ -41,11 +44,11 @@ export default function(kibana) { }).default(); }, - init(server) { - fieldsRoutes(server); - visDataRoutes(server); + init(server: Legacy.Server) { + const initializerContext = {} as PluginInitializerContext; + const core = { http: { server } } as InternalCoreSetup; - SearchStrategiesRegister.init(server); + metricPlugin(initializerContext).setup(core); }, }); } diff --git a/src/legacy/core_plugins/metrics/server/lib/search_strategies/search_strategies_register.js b/src/legacy/core_plugins/metrics/server/lib/search_strategies/search_strategies_register.js index 5fbb4060862a4..6a40ead99aca5 100644 --- a/src/legacy/core_plugins/metrics/server/lib/search_strategies/search_strategies_register.js +++ b/src/legacy/core_plugins/metrics/server/lib/search_strategies/search_strategies_register.js @@ -33,7 +33,7 @@ const addStrategy = searchStrategy => { }; export class SearchStrategiesRegister { - static init(server) { + static init({ http: { server } }) { server.expose('AbstractSearchStrategy', AbstractSearchStrategy); server.expose('AbstractSearchRequest', AbstractSearchRequest); server.expose('DefaultSearchCapabilities', DefaultSearchCapabilities); diff --git a/src/legacy/core_plugins/metrics/server/lib/search_strategies/search_strategies_register.test.js b/src/legacy/core_plugins/metrics/server/lib/search_strategies/search_strategies_register.test.js index e03d776b8ee0c..3239c961244ce 100644 --- a/src/legacy/core_plugins/metrics/server/lib/search_strategies/search_strategies_register.test.js +++ b/src/legacy/core_plugins/metrics/server/lib/search_strategies/search_strategies_register.test.js @@ -32,6 +32,7 @@ class MockSearchStrategy extends AbstractSearchStrategy { } describe('SearchStrategiesRegister', () => { + let core; let server; let strategies; let anotherSearchStrategy; @@ -42,6 +43,7 @@ describe('SearchStrategiesRegister', () => { server[strategy] = func; }), }; + core = { http: { server } }; strategies = [ ['AbstractSearchStrategy', AbstractSearchStrategy], ['AbstractSearchRequest', AbstractSearchRequest], @@ -49,7 +51,7 @@ describe('SearchStrategiesRegister', () => { ['addSearchStrategy', expect.any(Function)], ]; - SearchStrategiesRegister.init(server); + SearchStrategiesRegister.init(core); }); test('should init strategies register', () => { diff --git a/src/legacy/core_plugins/metrics/server/np/index.ts b/src/legacy/core_plugins/metrics/server/np/index.ts new file mode 100644 index 0000000000000..be9c4b49565b4 --- /dev/null +++ b/src/legacy/core_plugins/metrics/server/np/index.ts @@ -0,0 +1,25 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { PluginInitializerContext } from 'src/core/server'; +import { MetricsPlugin } from './plugin'; + +export function metricPlugin(initializerContext: PluginInitializerContext) { + return new MetricsPlugin(); +} diff --git a/src/legacy/core_plugins/metrics/server/np/plugin.ts b/src/legacy/core_plugins/metrics/server/np/plugin.ts new file mode 100644 index 0000000000000..eca2a3161b5ab --- /dev/null +++ b/src/legacy/core_plugins/metrics/server/np/plugin.ts @@ -0,0 +1,35 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { InternalCoreSetup } from 'kibana/server'; +// @ts-ignore +import { fieldsRoutes } from '../routes/fields'; +// @ts-ignore +import { visDataRoutes } from '../routes/vis'; +// @ts-ignore +import { SearchStrategiesRegister } from '../lib/search_strategies/search_strategies_register'; + +export class MetricsPlugin { + public setup(core: InternalCoreSetup) { + fieldsRoutes(core); + visDataRoutes(core); + + SearchStrategiesRegister.init(core); + } +} diff --git a/src/legacy/core_plugins/metrics/server/routes/fields.js b/src/legacy/core_plugins/metrics/server/routes/fields.js index d984868afb0b0..951add2dace50 100644 --- a/src/legacy/core_plugins/metrics/server/routes/fields.js +++ b/src/legacy/core_plugins/metrics/server/routes/fields.js @@ -20,7 +20,7 @@ import { getFields } from '../lib/get_fields'; import { getIndexPatternService } from '../lib/get_index_pattern_service'; -export const fieldsRoutes = server => { +export const fieldsRoutes = ({ http: { server } }) => { server.route({ config: { pre: [getIndexPatternService], diff --git a/src/legacy/core_plugins/metrics/server/routes/vis.js b/src/legacy/core_plugins/metrics/server/routes/vis.js index 15ff7b9a6c90b..cc96e86a41e8a 100644 --- a/src/legacy/core_plugins/metrics/server/routes/vis.js +++ b/src/legacy/core_plugins/metrics/server/routes/vis.js @@ -20,7 +20,7 @@ import { getVisData } from '../lib/get_vis_data'; import Boom from 'boom'; -export const visDataRoutes = server => { +export const visDataRoutes = ({ http: { server } }) => { server.route({ path: '/api/metrics/vis/data', method: 'POST', From ae523fbc59a154028e40055fa6bc55ff7f317cd9 Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Fri, 21 Jun 2019 14:20:16 +0300 Subject: [PATCH 02/25] Shim public to new platfrom --- src/legacy/core_plugins/metrics/index.ts | 7 ++-- .../metrics/public/kbn_vis_types/index.js | 4 --- .../core_plugins/metrics/public/np/index.ts | 22 ++++++++++++ .../core_plugins/metrics/public/np/plugin.ts | 35 +++++++++++++++++++ .../core_plugins/metrics/public/tsvb_fn.js | 3 -- .../core_plugins/metrics/server/np/index.ts | 2 +- 6 files changed, 61 insertions(+), 12 deletions(-) create mode 100644 src/legacy/core_plugins/metrics/public/np/index.ts create mode 100644 src/legacy/core_plugins/metrics/public/np/plugin.ts diff --git a/src/legacy/core_plugins/metrics/index.ts b/src/legacy/core_plugins/metrics/index.ts index f4baf7a9e2a9b..240db0b913574 100644 --- a/src/legacy/core_plugins/metrics/index.ts +++ b/src/legacy/core_plugins/metrics/index.ts @@ -21,7 +21,7 @@ import { resolve } from 'path'; import { Legacy } from 'kibana'; import { PluginInitializerContext } from 'src/core/server'; import { InternalCoreSetup } from 'src/core/server'; -import { metricPlugin } from './server/np/'; +import { metricsPlugin } from './server/np/'; // eslint-disable-next-line import/no-default-export export default function(kibana: any) { @@ -31,9 +31,8 @@ export default function(kibana: any) { require: ['kibana', 'elasticsearch'], uiExports: { - visTypes: ['plugins/metrics/kbn_vis_types'], - interpreter: ['plugins/metrics/tsvb_fn'], styleSheetPaths: resolve(__dirname, 'public/index.scss'), + hacks: ['plugins/metrics/np'], }, config(Joi: any) { @@ -48,7 +47,7 @@ export default function(kibana: any) { const initializerContext = {} as PluginInitializerContext; const core = { http: { server } } as InternalCoreSetup; - metricPlugin(initializerContext).setup(core); + metricsPlugin(initializerContext).setup(core); }, }); } diff --git a/src/legacy/core_plugins/metrics/public/kbn_vis_types/index.js b/src/legacy/core_plugins/metrics/public/kbn_vis_types/index.js index 1ffcb2b2db924..fc680f14ea8e7 100644 --- a/src/legacy/core_plugins/metrics/public/kbn_vis_types/index.js +++ b/src/legacy/core_plugins/metrics/public/kbn_vis_types/index.js @@ -25,10 +25,6 @@ import { defaultFeedbackMessage } from 'ui/vis/default_feedback_message'; import { PANEL_TYPES } from '../../common/panel_types'; -// register the provider with the visTypes registry so that other know it exists -import { VisTypesRegistryProvider } from 'ui/registry/vis_types'; -VisTypesRegistryProvider.register(MetricsVisProvider); - export function MetricsVisProvider(Private) { const VisFactory = Private(VisFactoryProvider); const ReactEditorController = Private(ReactEditorControllerProvider).handler; diff --git a/src/legacy/core_plugins/metrics/public/np/index.ts b/src/legacy/core_plugins/metrics/public/np/index.ts new file mode 100644 index 0000000000000..ea7bc869540e1 --- /dev/null +++ b/src/legacy/core_plugins/metrics/public/np/index.ts @@ -0,0 +1,22 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { Plugin } from './plugin'; + +new Plugin().setup(); diff --git a/src/legacy/core_plugins/metrics/public/np/plugin.ts b/src/legacy/core_plugins/metrics/public/np/plugin.ts new file mode 100644 index 0000000000000..cefd3effd9051 --- /dev/null +++ b/src/legacy/core_plugins/metrics/public/np/plugin.ts @@ -0,0 +1,35 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +// @ts-ignore +import { functionsRegistry } from 'plugins/interpreter/registries'; +// @ts-ignore +import { VisTypesRegistryProvider } from 'ui/registry/vis_types'; +// @ts-ignore +import { tsvb } from '../tsvb_fn'; +// @ts-ignore +import { MetricsVisProvider } from '../kbn_vis_types'; + +export class Plugin { + public setup() { + functionsRegistry.register(tsvb); + // register the provider with the visTypes registry so that other know it exists + VisTypesRegistryProvider.register(MetricsVisProvider); + } +} diff --git a/src/legacy/core_plugins/metrics/public/tsvb_fn.js b/src/legacy/core_plugins/metrics/public/tsvb_fn.js index 983443a1574cd..7660e9f213a3f 100644 --- a/src/legacy/core_plugins/metrics/public/tsvb_fn.js +++ b/src/legacy/core_plugins/metrics/public/tsvb_fn.js @@ -17,7 +17,6 @@ * under the License. */ -import { functionsRegistry } from 'plugins/interpreter/registries'; import { get } from 'lodash'; import { i18n } from '@kbn/i18n'; import { MetricsRequestHandlerProvider } from './kbn_vis_types/request_handler'; @@ -75,5 +74,3 @@ export const tsvb = () => ({ }; }, }); - -functionsRegistry.register(tsvb); diff --git a/src/legacy/core_plugins/metrics/server/np/index.ts b/src/legacy/core_plugins/metrics/server/np/index.ts index be9c4b49565b4..a1ac702e661b8 100644 --- a/src/legacy/core_plugins/metrics/server/np/index.ts +++ b/src/legacy/core_plugins/metrics/server/np/index.ts @@ -20,6 +20,6 @@ import { PluginInitializerContext } from 'src/core/server'; import { MetricsPlugin } from './plugin'; -export function metricPlugin(initializerContext: PluginInitializerContext) { +export function metricsPlugin(initializerContext: PluginInitializerContext) { return new MetricsPlugin(); } From 1aeb0be3b3787fd1b2f47e60e5eb1164dc9b5a90 Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Fri, 21 Jun 2019 16:20:21 +0300 Subject: [PATCH 03/25] Break by services --- .../metrics/public/interpreter/index.ts | 32 +++++++++++++++++++ .../core_plugins/metrics/public/np/plugin.ts | 18 +++++++---- 2 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 src/legacy/core_plugins/metrics/public/interpreter/index.ts diff --git a/src/legacy/core_plugins/metrics/public/interpreter/index.ts b/src/legacy/core_plugins/metrics/public/interpreter/index.ts new file mode 100644 index 0000000000000..7fabf6c50e931 --- /dev/null +++ b/src/legacy/core_plugins/metrics/public/interpreter/index.ts @@ -0,0 +1,32 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +// @ts-ignore +import { functionsRegistry } from 'plugins/interpreter/registries'; + +/** + * Interpreter Service + */ +export class InterpreterService { + public setup() { + return { + functionsRegistry, + }; + } +} diff --git a/src/legacy/core_plugins/metrics/public/np/plugin.ts b/src/legacy/core_plugins/metrics/public/np/plugin.ts index cefd3effd9051..5112fc1aa0bc9 100644 --- a/src/legacy/core_plugins/metrics/public/np/plugin.ts +++ b/src/legacy/core_plugins/metrics/public/np/plugin.ts @@ -17,19 +17,25 @@ * under the License. */ -// @ts-ignore -import { functionsRegistry } from 'plugins/interpreter/registries'; -// @ts-ignore -import { VisTypesRegistryProvider } from 'ui/registry/vis_types'; // @ts-ignore import { tsvb } from '../tsvb_fn'; // @ts-ignore import { MetricsVisProvider } from '../kbn_vis_types'; +import { TypesService } from '../../../visualizations/public/types/types_service'; +import { InterpreterService } from '../interpreter'; export class Plugin { + private readonly visTypes: TypesService; + private readonly interpreter: InterpreterService; + + constructor() { + this.visTypes = new TypesService(); + this.interpreter = new InterpreterService(); + } + public setup() { - functionsRegistry.register(tsvb); + this.interpreter.setup().functionsRegistry.register(tsvb); // register the provider with the visTypes registry so that other know it exists - VisTypesRegistryProvider.register(MetricsVisProvider); + this.visTypes.setup().VisTypesRegistryProvider.register(MetricsVisProvider); } } From 60db353218b28e48110a9367d43f5321ccc13d15 Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Mon, 24 Jun 2019 13:16:18 +0300 Subject: [PATCH 04/25] Add dependencies to the TSVB plugin --- src/legacy/core_plugins/metrics/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/legacy/core_plugins/metrics/index.ts b/src/legacy/core_plugins/metrics/index.ts index 240db0b913574..1727d7e3d9f78 100644 --- a/src/legacy/core_plugins/metrics/index.ts +++ b/src/legacy/core_plugins/metrics/index.ts @@ -28,7 +28,7 @@ export default function(kibana: any) { return new kibana.Plugin({ id: 'metrics', - require: ['kibana', 'elasticsearch'], + require: ['kibana', 'elasticsearch', 'visualizations', 'data'], uiExports: { styleSheetPaths: resolve(__dirname, 'public/index.scss'), From 9444061b7f19b42317cb75d0ecf5c773efeaa162 Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Mon, 24 Jun 2019 14:01:29 +0300 Subject: [PATCH 05/25] Change folder structure for the shim --- src/legacy/core_plugins/metrics/index.ts | 2 +- .../{kbn_vis_types => }/editor_controller.js | 2 +- .../metrics/public/{np/plugin.ts => index.ts} | 10 +++++---- .../index.js => kbn_vis_type.js} | 6 ++--- .../core_plugins/metrics/public/np/index.ts | 22 ------------------- .../{kbn_vis_types => }/request_handler.js | 2 +- .../core_plugins/metrics/public/tsvb_fn.js | 2 +- 7 files changed, 13 insertions(+), 33 deletions(-) rename src/legacy/core_plugins/metrics/public/{kbn_vis_types => }/editor_controller.js (97%) rename src/legacy/core_plugins/metrics/public/{np/plugin.ts => index.ts} (85%) rename src/legacy/core_plugins/metrics/public/{kbn_vis_types/index.js => kbn_vis_type.js} (94%) delete mode 100644 src/legacy/core_plugins/metrics/public/np/index.ts rename src/legacy/core_plugins/metrics/public/{kbn_vis_types => }/request_handler.js (97%) diff --git a/src/legacy/core_plugins/metrics/index.ts b/src/legacy/core_plugins/metrics/index.ts index 1727d7e3d9f78..addcde4b0baad 100644 --- a/src/legacy/core_plugins/metrics/index.ts +++ b/src/legacy/core_plugins/metrics/index.ts @@ -32,7 +32,7 @@ export default function(kibana: any) { uiExports: { styleSheetPaths: resolve(__dirname, 'public/index.scss'), - hacks: ['plugins/metrics/np'], + hacks: ['plugins/metrics/'], }, config(Joi: any) { diff --git a/src/legacy/core_plugins/metrics/public/kbn_vis_types/editor_controller.js b/src/legacy/core_plugins/metrics/public/editor_controller.js similarity index 97% rename from src/legacy/core_plugins/metrics/public/kbn_vis_types/editor_controller.js rename to src/legacy/core_plugins/metrics/public/editor_controller.js index 2639eba49a1ec..0cd7fff8b7e55 100644 --- a/src/legacy/core_plugins/metrics/public/kbn_vis_types/editor_controller.js +++ b/src/legacy/core_plugins/metrics/public/editor_controller.js @@ -21,7 +21,7 @@ import React from 'react'; import { render, unmountComponentAtNode } from 'react-dom'; import { I18nContext } from 'ui/i18n'; import chrome from 'ui/chrome'; -import { fetchIndexPatternFields } from '../lib/fetch_fields'; +import { fetchIndexPatternFields } from './lib/fetch_fields'; function ReactEditorControllerProvider(config) { class ReactEditorController { diff --git a/src/legacy/core_plugins/metrics/public/np/plugin.ts b/src/legacy/core_plugins/metrics/public/index.ts similarity index 85% rename from src/legacy/core_plugins/metrics/public/np/plugin.ts rename to src/legacy/core_plugins/metrics/public/index.ts index 5112fc1aa0bc9..e8303efc4458c 100644 --- a/src/legacy/core_plugins/metrics/public/np/plugin.ts +++ b/src/legacy/core_plugins/metrics/public/index.ts @@ -18,11 +18,11 @@ */ // @ts-ignore -import { tsvb } from '../tsvb_fn'; +import { tsvb } from './tsvb_fn'; // @ts-ignore -import { MetricsVisProvider } from '../kbn_vis_types'; -import { TypesService } from '../../../visualizations/public/types/types_service'; -import { InterpreterService } from '../interpreter'; +import { MetricsVisProvider } from './kbn_vis_type'; +import { TypesService } from '../../visualizations/public/types'; +import { InterpreterService } from './interpreter'; export class Plugin { private readonly visTypes: TypesService; @@ -39,3 +39,5 @@ export class Plugin { this.visTypes.setup().VisTypesRegistryProvider.register(MetricsVisProvider); } } + +new Plugin().setup(); diff --git a/src/legacy/core_plugins/metrics/public/kbn_vis_types/index.js b/src/legacy/core_plugins/metrics/public/kbn_vis_type.js similarity index 94% rename from src/legacy/core_plugins/metrics/public/kbn_vis_types/index.js rename to src/legacy/core_plugins/metrics/public/kbn_vis_type.js index fc680f14ea8e7..dfe7dd55be892 100644 --- a/src/legacy/core_plugins/metrics/public/kbn_vis_types/index.js +++ b/src/legacy/core_plugins/metrics/public/kbn_vis_type.js @@ -23,7 +23,7 @@ import { ReactEditorControllerProvider } from './editor_controller'; import { VisFactoryProvider } from 'ui/vis/vis_factory'; import { defaultFeedbackMessage } from 'ui/vis/default_feedback_message'; -import { PANEL_TYPES } from '../../common/panel_types'; +import { PANEL_TYPES } from '../common/panel_types'; export function MetricsVisProvider(Private) { const VisFactory = Private(VisFactoryProvider); @@ -72,11 +72,11 @@ export function MetricsVisProvider(Private) { show_legend: 1, show_grid: 1, }, - component: require('../components/vis_editor').VisEditor, + component: require('./components/vis_editor').VisEditor, }, editor: ReactEditorController, editorConfig: { - component: require('../components/vis_editor').VisEditor, + component: require('./components/vis_editor').VisEditor, }, options: { showQueryBar: false, diff --git a/src/legacy/core_plugins/metrics/public/np/index.ts b/src/legacy/core_plugins/metrics/public/np/index.ts deleted file mode 100644 index ea7bc869540e1..0000000000000 --- a/src/legacy/core_plugins/metrics/public/np/index.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { Plugin } from './plugin'; - -new Plugin().setup(); diff --git a/src/legacy/core_plugins/metrics/public/kbn_vis_types/request_handler.js b/src/legacy/core_plugins/metrics/public/request_handler.js similarity index 97% rename from src/legacy/core_plugins/metrics/public/kbn_vis_types/request_handler.js rename to src/legacy/core_plugins/metrics/public/request_handler.js index ce0ed0f919924..fe97265d07506 100644 --- a/src/legacy/core_plugins/metrics/public/kbn_vis_types/request_handler.js +++ b/src/legacy/core_plugins/metrics/public/request_handler.js @@ -17,7 +17,7 @@ * under the License. */ -import { validateInterval } from '../lib/validate_interval'; +import { validateInterval } from './lib/validate_interval'; import { timezoneProvider } from 'ui/vis/lib/timezone'; import { timefilter } from 'ui/timefilter'; import { kfetch } from 'ui/kfetch'; diff --git a/src/legacy/core_plugins/metrics/public/tsvb_fn.js b/src/legacy/core_plugins/metrics/public/tsvb_fn.js index 7660e9f213a3f..45d2761fb34c8 100644 --- a/src/legacy/core_plugins/metrics/public/tsvb_fn.js +++ b/src/legacy/core_plugins/metrics/public/tsvb_fn.js @@ -19,7 +19,7 @@ import { get } from 'lodash'; import { i18n } from '@kbn/i18n'; -import { MetricsRequestHandlerProvider } from './kbn_vis_types/request_handler'; +import { MetricsRequestHandlerProvider } from './request_handler'; import { PersistedState } from 'ui/persisted_state'; import chrome from 'ui/chrome'; From 2a7174b763bb286ca97593f8c640a97c0763c70d Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Mon, 24 Jun 2019 16:10:13 +0300 Subject: [PATCH 06/25] Pass services as a second argument of setup() and small fixes --- src/legacy/core_plugins/metrics/index.ts | 4 +-- .../core_plugins/metrics/public/index.ts | 34 +++++++++++-------- .../metrics/public/interpreter/index.ts | 32 ----------------- .../search_strategies_register.js | 2 +- .../core_plugins/metrics/server/np/plugin.ts | 10 +++--- .../metrics/server/routes/fields.js | 2 +- .../core_plugins/metrics/server/routes/vis.js | 2 +- 7 files changed, 29 insertions(+), 57 deletions(-) delete mode 100644 src/legacy/core_plugins/metrics/public/interpreter/index.ts diff --git a/src/legacy/core_plugins/metrics/index.ts b/src/legacy/core_plugins/metrics/index.ts index addcde4b0baad..9ededd4a55e12 100644 --- a/src/legacy/core_plugins/metrics/index.ts +++ b/src/legacy/core_plugins/metrics/index.ts @@ -20,7 +20,6 @@ import { resolve } from 'path'; import { Legacy } from 'kibana'; import { PluginInitializerContext } from 'src/core/server'; -import { InternalCoreSetup } from 'src/core/server'; import { metricsPlugin } from './server/np/'; // eslint-disable-next-line import/no-default-export @@ -45,9 +44,8 @@ export default function(kibana: any) { init(server: Legacy.Server) { const initializerContext = {} as PluginInitializerContext; - const core = { http: { server } } as InternalCoreSetup; - metricsPlugin(initializerContext).setup(core); + metricsPlugin(initializerContext).setup(server); }, }); } diff --git a/src/legacy/core_plugins/metrics/public/index.ts b/src/legacy/core_plugins/metrics/public/index.ts index e8303efc4458c..fb25c8ab95fc3 100644 --- a/src/legacy/core_plugins/metrics/public/index.ts +++ b/src/legacy/core_plugins/metrics/public/index.ts @@ -17,27 +17,33 @@ * under the License. */ +// @ts-ignore +import { functionsRegistry } from 'plugins/interpreter/registries'; // @ts-ignore import { tsvb } from './tsvb_fn'; // @ts-ignore import { MetricsVisProvider } from './kbn_vis_type'; -import { TypesService } from '../../visualizations/public/types'; -import { InterpreterService } from './interpreter'; +import { visualizations } from '../../visualizations/public'; export class Plugin { - private readonly visTypes: TypesService; - private readonly interpreter: InterpreterService; - - constructor() { - this.visTypes = new TypesService(); - this.interpreter = new InterpreterService(); - } - - public setup() { - this.interpreter.setup().functionsRegistry.register(tsvb); + // @ts-ignore + public setup(core, plugins) { + plugins.data.expressions.functionsRegistry.register(tsvb); // register the provider with the visTypes registry so that other know it exists - this.visTypes.setup().VisTypesRegistryProvider.register(MetricsVisProvider); + plugins.visualizations.types.VisTypesRegistryProvider.register(MetricsVisProvider); } + + public stop() {} } -new Plugin().setup(); +const core = {}; +const plugins = { + data: { + expressions: { + functionsRegistry, + }, + }, + visualizations, +}; + +new Plugin().setup(core, plugins); diff --git a/src/legacy/core_plugins/metrics/public/interpreter/index.ts b/src/legacy/core_plugins/metrics/public/interpreter/index.ts deleted file mode 100644 index 7fabf6c50e931..0000000000000 --- a/src/legacy/core_plugins/metrics/public/interpreter/index.ts +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -// @ts-ignore -import { functionsRegistry } from 'plugins/interpreter/registries'; - -/** - * Interpreter Service - */ -export class InterpreterService { - public setup() { - return { - functionsRegistry, - }; - } -} diff --git a/src/legacy/core_plugins/metrics/server/lib/search_strategies/search_strategies_register.js b/src/legacy/core_plugins/metrics/server/lib/search_strategies/search_strategies_register.js index 6a40ead99aca5..5fbb4060862a4 100644 --- a/src/legacy/core_plugins/metrics/server/lib/search_strategies/search_strategies_register.js +++ b/src/legacy/core_plugins/metrics/server/lib/search_strategies/search_strategies_register.js @@ -33,7 +33,7 @@ const addStrategy = searchStrategy => { }; export class SearchStrategiesRegister { - static init({ http: { server } }) { + static init(server) { server.expose('AbstractSearchStrategy', AbstractSearchStrategy); server.expose('AbstractSearchRequest', AbstractSearchRequest); server.expose('DefaultSearchCapabilities', DefaultSearchCapabilities); diff --git a/src/legacy/core_plugins/metrics/server/np/plugin.ts b/src/legacy/core_plugins/metrics/server/np/plugin.ts index eca2a3161b5ab..cd87fef34e87d 100644 --- a/src/legacy/core_plugins/metrics/server/np/plugin.ts +++ b/src/legacy/core_plugins/metrics/server/np/plugin.ts @@ -17,7 +17,7 @@ * under the License. */ -import { InternalCoreSetup } from 'kibana/server'; +import { Legacy } from 'kibana'; // @ts-ignore import { fieldsRoutes } from '../routes/fields'; // @ts-ignore @@ -26,10 +26,10 @@ import { visDataRoutes } from '../routes/vis'; import { SearchStrategiesRegister } from '../lib/search_strategies/search_strategies_register'; export class MetricsPlugin { - public setup(core: InternalCoreSetup) { - fieldsRoutes(core); - visDataRoutes(core); + public setup(server: Legacy.Server) { + fieldsRoutes(server); + visDataRoutes(server); - SearchStrategiesRegister.init(core); + SearchStrategiesRegister.init(server); } } diff --git a/src/legacy/core_plugins/metrics/server/routes/fields.js b/src/legacy/core_plugins/metrics/server/routes/fields.js index 951add2dace50..d984868afb0b0 100644 --- a/src/legacy/core_plugins/metrics/server/routes/fields.js +++ b/src/legacy/core_plugins/metrics/server/routes/fields.js @@ -20,7 +20,7 @@ import { getFields } from '../lib/get_fields'; import { getIndexPatternService } from '../lib/get_index_pattern_service'; -export const fieldsRoutes = ({ http: { server } }) => { +export const fieldsRoutes = server => { server.route({ config: { pre: [getIndexPatternService], diff --git a/src/legacy/core_plugins/metrics/server/routes/vis.js b/src/legacy/core_plugins/metrics/server/routes/vis.js index cc96e86a41e8a..15ff7b9a6c90b 100644 --- a/src/legacy/core_plugins/metrics/server/routes/vis.js +++ b/src/legacy/core_plugins/metrics/server/routes/vis.js @@ -20,7 +20,7 @@ import { getVisData } from '../lib/get_vis_data'; import Boom from 'boom'; -export const visDataRoutes = ({ http: { server } }) => { +export const visDataRoutes = server => { server.route({ path: '/api/metrics/vis/data', method: 'POST', From a90d699c01ad0936708626114fffe1c917854ec2 Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Mon, 24 Jun 2019 17:40:15 +0300 Subject: [PATCH 07/25] Add start() to the Plugin --- src/legacy/core_plugins/metrics/public/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/legacy/core_plugins/metrics/public/index.ts b/src/legacy/core_plugins/metrics/public/index.ts index fb25c8ab95fc3..cb86adcb443dd 100644 --- a/src/legacy/core_plugins/metrics/public/index.ts +++ b/src/legacy/core_plugins/metrics/public/index.ts @@ -33,6 +33,8 @@ export class Plugin { plugins.visualizations.types.VisTypesRegistryProvider.register(MetricsVisProvider); } + public start() {} + public stop() {} } From 3b91dccd20dce570def72383cf14025066bcdf2d Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Mon, 24 Jun 2019 18:18:23 +0300 Subject: [PATCH 08/25] Get rid of the Private --- src/legacy/core_plugins/metrics/public/index.ts | 4 ++-- .../core_plugins/metrics/public/kbn_vis_type.js | 14 ++++++++------ .../core_plugins/metrics/public/request_handler.js | 4 ++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/legacy/core_plugins/metrics/public/index.ts b/src/legacy/core_plugins/metrics/public/index.ts index cb86adcb443dd..a302b2e93fc20 100644 --- a/src/legacy/core_plugins/metrics/public/index.ts +++ b/src/legacy/core_plugins/metrics/public/index.ts @@ -22,7 +22,7 @@ import { functionsRegistry } from 'plugins/interpreter/registries'; // @ts-ignore import { tsvb } from './tsvb_fn'; // @ts-ignore -import { MetricsVisProvider } from './kbn_vis_type'; +import { MetricsVis } from './kbn_vis_type'; import { visualizations } from '../../visualizations/public'; export class Plugin { @@ -30,7 +30,7 @@ export class Plugin { public setup(core, plugins) { plugins.data.expressions.functionsRegistry.register(tsvb); // register the provider with the visTypes registry so that other know it exists - plugins.visualizations.types.VisTypesRegistryProvider.register(MetricsVisProvider); + plugins.visualizations.types.VisTypesRegistryProvider.register(MetricsVis); } public start() {} diff --git a/src/legacy/core_plugins/metrics/public/kbn_vis_type.js b/src/legacy/core_plugins/metrics/public/kbn_vis_type.js index dfe7dd55be892..d5e2974e55893 100644 --- a/src/legacy/core_plugins/metrics/public/kbn_vis_type.js +++ b/src/legacy/core_plugins/metrics/public/kbn_vis_type.js @@ -17,20 +17,22 @@ * under the License. */ +import chrome from 'ui/chrome'; import { MetricsRequestHandlerProvider } from './request_handler'; import { i18n } from '@kbn/i18n'; import { ReactEditorControllerProvider } from './editor_controller'; -import { VisFactoryProvider } from 'ui/vis/vis_factory'; import { defaultFeedbackMessage } from 'ui/vis/default_feedback_message'; +import { visFactory } from '../../visualizations/public'; import { PANEL_TYPES } from '../common/panel_types'; -export function MetricsVisProvider(Private) { - const VisFactory = Private(VisFactoryProvider); - const ReactEditorController = Private(ReactEditorControllerProvider).handler; - const metricsRequestHandler = Private(MetricsRequestHandlerProvider).handler; +const uiSettings = chrome.getUiSettingsClient(); - return VisFactory.createReactVisualization({ +export function MetricsVis() { + const ReactEditorController = new ReactEditorControllerProvider(uiSettings).handler; + const metricsRequestHandler = new MetricsRequestHandlerProvider(uiSettings).handler; + + return visFactory.createReactVisualization({ name: 'metrics', title: i18n.translate('tsvb.kbnVisTypes.metricsTitle', { defaultMessage: 'TSVB' }), description: i18n.translate('tsvb.kbnVisTypes.metricsDescription', { diff --git a/src/legacy/core_plugins/metrics/public/request_handler.js b/src/legacy/core_plugins/metrics/public/request_handler.js index fe97265d07506..ce4229274190d 100644 --- a/src/legacy/core_plugins/metrics/public/request_handler.js +++ b/src/legacy/core_plugins/metrics/public/request_handler.js @@ -22,8 +22,8 @@ import { timezoneProvider } from 'ui/vis/lib/timezone'; import { timefilter } from 'ui/timefilter'; import { kfetch } from 'ui/kfetch'; -const MetricsRequestHandlerProvider = function(Private, config) { - const timezone = Private(timezoneProvider)(); +const MetricsRequestHandlerProvider = function(config) { + const timezone = timezoneProvider(); return { name: 'metrics', From 69d0affcc3977aabb438675451e1223cad15be62 Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Tue, 25 Jun 2019 13:15:20 +0300 Subject: [PATCH 09/25] Pass the core to setup() --- src/legacy/core_plugins/metrics/index.ts | 4 +++- .../search_strategies_register.test.js | 4 +--- src/legacy/core_plugins/metrics/server/np/plugin.ts | 11 ++++++----- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/legacy/core_plugins/metrics/index.ts b/src/legacy/core_plugins/metrics/index.ts index 9ededd4a55e12..addcde4b0baad 100644 --- a/src/legacy/core_plugins/metrics/index.ts +++ b/src/legacy/core_plugins/metrics/index.ts @@ -20,6 +20,7 @@ import { resolve } from 'path'; import { Legacy } from 'kibana'; import { PluginInitializerContext } from 'src/core/server'; +import { InternalCoreSetup } from 'src/core/server'; import { metricsPlugin } from './server/np/'; // eslint-disable-next-line import/no-default-export @@ -44,8 +45,9 @@ export default function(kibana: any) { init(server: Legacy.Server) { const initializerContext = {} as PluginInitializerContext; + const core = { http: { server } } as InternalCoreSetup; - metricsPlugin(initializerContext).setup(server); + metricsPlugin(initializerContext).setup(core); }, }); } diff --git a/src/legacy/core_plugins/metrics/server/lib/search_strategies/search_strategies_register.test.js b/src/legacy/core_plugins/metrics/server/lib/search_strategies/search_strategies_register.test.js index 3239c961244ce..e03d776b8ee0c 100644 --- a/src/legacy/core_plugins/metrics/server/lib/search_strategies/search_strategies_register.test.js +++ b/src/legacy/core_plugins/metrics/server/lib/search_strategies/search_strategies_register.test.js @@ -32,7 +32,6 @@ class MockSearchStrategy extends AbstractSearchStrategy { } describe('SearchStrategiesRegister', () => { - let core; let server; let strategies; let anotherSearchStrategy; @@ -43,7 +42,6 @@ describe('SearchStrategiesRegister', () => { server[strategy] = func; }), }; - core = { http: { server } }; strategies = [ ['AbstractSearchStrategy', AbstractSearchStrategy], ['AbstractSearchRequest', AbstractSearchRequest], @@ -51,7 +49,7 @@ describe('SearchStrategiesRegister', () => { ['addSearchStrategy', expect.any(Function)], ]; - SearchStrategiesRegister.init(core); + SearchStrategiesRegister.init(server); }); test('should init strategies register', () => { diff --git a/src/legacy/core_plugins/metrics/server/np/plugin.ts b/src/legacy/core_plugins/metrics/server/np/plugin.ts index cd87fef34e87d..57c7008485acf 100644 --- a/src/legacy/core_plugins/metrics/server/np/plugin.ts +++ b/src/legacy/core_plugins/metrics/server/np/plugin.ts @@ -17,7 +17,7 @@ * under the License. */ -import { Legacy } from 'kibana'; +import { InternalCoreSetup } from 'kibana/server'; // @ts-ignore import { fieldsRoutes } from '../routes/fields'; // @ts-ignore @@ -26,10 +26,11 @@ import { visDataRoutes } from '../routes/vis'; import { SearchStrategiesRegister } from '../lib/search_strategies/search_strategies_register'; export class MetricsPlugin { - public setup(server: Legacy.Server) { - fieldsRoutes(server); - visDataRoutes(server); + public setup(core: InternalCoreSetup) { + const { http } = core; + fieldsRoutes(http.server); + visDataRoutes(http.server); - SearchStrategiesRegister.init(server); + SearchStrategiesRegister.init(http.server); } } From bbb4c491004aef81a39a0557d552e8586bf44637 Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Wed, 26 Jun 2019 12:12:02 +0300 Subject: [PATCH 10/25] Get rid of NP folder --- src/legacy/core_plugins/metrics/index.ts | 2 +- src/legacy/core_plugins/metrics/server/{np => }/index.ts | 0 src/legacy/core_plugins/metrics/server/{np => }/plugin.ts | 6 +++--- 3 files changed, 4 insertions(+), 4 deletions(-) rename src/legacy/core_plugins/metrics/server/{np => }/index.ts (100%) rename src/legacy/core_plugins/metrics/server/{np => }/plugin.ts (85%) diff --git a/src/legacy/core_plugins/metrics/index.ts b/src/legacy/core_plugins/metrics/index.ts index addcde4b0baad..6c291e8849a4c 100644 --- a/src/legacy/core_plugins/metrics/index.ts +++ b/src/legacy/core_plugins/metrics/index.ts @@ -21,7 +21,7 @@ import { resolve } from 'path'; import { Legacy } from 'kibana'; import { PluginInitializerContext } from 'src/core/server'; import { InternalCoreSetup } from 'src/core/server'; -import { metricsPlugin } from './server/np/'; +import { metricsPlugin } from './server/'; // eslint-disable-next-line import/no-default-export export default function(kibana: any) { diff --git a/src/legacy/core_plugins/metrics/server/np/index.ts b/src/legacy/core_plugins/metrics/server/index.ts similarity index 100% rename from src/legacy/core_plugins/metrics/server/np/index.ts rename to src/legacy/core_plugins/metrics/server/index.ts diff --git a/src/legacy/core_plugins/metrics/server/np/plugin.ts b/src/legacy/core_plugins/metrics/server/plugin.ts similarity index 85% rename from src/legacy/core_plugins/metrics/server/np/plugin.ts rename to src/legacy/core_plugins/metrics/server/plugin.ts index 57c7008485acf..73bbe1a774a07 100644 --- a/src/legacy/core_plugins/metrics/server/np/plugin.ts +++ b/src/legacy/core_plugins/metrics/server/plugin.ts @@ -19,11 +19,11 @@ import { InternalCoreSetup } from 'kibana/server'; // @ts-ignore -import { fieldsRoutes } from '../routes/fields'; +import { fieldsRoutes } from './routes/fields'; // @ts-ignore -import { visDataRoutes } from '../routes/vis'; +import { visDataRoutes } from './routes/vis'; // @ts-ignore -import { SearchStrategiesRegister } from '../lib/search_strategies/search_strategies_register'; +import { SearchStrategiesRegister } from './lib/search_strategies/search_strategies_register'; export class MetricsPlugin { public setup(core: InternalCoreSetup) { From 263378bc9454cc9d87255665093952f1812a3196 Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Wed, 26 Jun 2019 12:54:32 +0300 Subject: [PATCH 11/25] Set config to timezoneProvider() --- .../core_plugins/metrics/public/index.ts | 2 +- .../metrics/public/kbn_vis_type.js | 116 +++++++++--------- .../metrics/public/request_handler.js | 5 +- 3 files changed, 62 insertions(+), 61 deletions(-) diff --git a/src/legacy/core_plugins/metrics/public/index.ts b/src/legacy/core_plugins/metrics/public/index.ts index a302b2e93fc20..64da3e39df583 100644 --- a/src/legacy/core_plugins/metrics/public/index.ts +++ b/src/legacy/core_plugins/metrics/public/index.ts @@ -30,7 +30,7 @@ export class Plugin { public setup(core, plugins) { plugins.data.expressions.functionsRegistry.register(tsvb); // register the provider with the visTypes registry so that other know it exists - plugins.visualizations.types.VisTypesRegistryProvider.register(MetricsVis); + plugins.visualizations.types.VisTypesRegistryProvider.register(() => MetricsVis); } public start() {} diff --git a/src/legacy/core_plugins/metrics/public/kbn_vis_type.js b/src/legacy/core_plugins/metrics/public/kbn_vis_type.js index d5e2974e55893..8c8edae876c70 100644 --- a/src/legacy/core_plugins/metrics/public/kbn_vis_type.js +++ b/src/legacy/core_plugins/metrics/public/kbn_vis_type.js @@ -28,64 +28,62 @@ import { PANEL_TYPES } from '../common/panel_types'; const uiSettings = chrome.getUiSettingsClient(); -export function MetricsVis() { - const ReactEditorController = new ReactEditorControllerProvider(uiSettings).handler; - const metricsRequestHandler = new MetricsRequestHandlerProvider(uiSettings).handler; +const ReactEditorController = new ReactEditorControllerProvider(uiSettings).handler; +const metricsRequestHandler = new MetricsRequestHandlerProvider(uiSettings).handler; - return visFactory.createReactVisualization({ - name: 'metrics', - title: i18n.translate('tsvb.kbnVisTypes.metricsTitle', { defaultMessage: 'TSVB' }), - description: i18n.translate('tsvb.kbnVisTypes.metricsDescription', { - defaultMessage: 'Build time-series using a visual pipeline interface', - }), - icon: 'visVisualBuilder', - feedbackMessage: defaultFeedbackMessage, - visConfig: { - defaults: { - id: '61ca57f0-469d-11e7-af02-69e470af7417', - type: PANEL_TYPES.TIMESERIES, - series: [ - { - id: '61ca57f1-469d-11e7-af02-69e470af7417', - color: '#68BC00', - split_mode: 'everything', - metrics: [ - { - id: '61ca57f2-469d-11e7-af02-69e470af7417', - type: 'count', - }, - ], - separate_axis: 0, - axis_position: 'right', - formatter: 'number', - chart_type: 'line', - line_width: 1, - point_size: 1, - fill: 0.5, - stacked: 'none', - }, - ], - time_field: '', - index_pattern: '', - interval: '', - axis_position: 'left', - axis_formatter: 'number', - axis_scale: 'normal', - show_legend: 1, - show_grid: 1, - }, - component: require('./components/vis_editor').VisEditor, +export const MetricsVis = visFactory.createReactVisualization({ + name: 'metrics', + title: i18n.translate('tsvb.kbnVisTypes.metricsTitle', { defaultMessage: 'TSVB' }), + description: i18n.translate('tsvb.kbnVisTypes.metricsDescription', { + defaultMessage: 'Build time-series using a visual pipeline interface', + }), + icon: 'visVisualBuilder', + feedbackMessage: defaultFeedbackMessage, + visConfig: { + defaults: { + id: '61ca57f0-469d-11e7-af02-69e470af7417', + type: PANEL_TYPES.TIMESERIES, + series: [ + { + id: '61ca57f1-469d-11e7-af02-69e470af7417', + color: '#68BC00', + split_mode: 'everything', + metrics: [ + { + id: '61ca57f2-469d-11e7-af02-69e470af7417', + type: 'count', + }, + ], + separate_axis: 0, + axis_position: 'right', + formatter: 'number', + chart_type: 'line', + line_width: 1, + point_size: 1, + fill: 0.5, + stacked: 'none', + }, + ], + time_field: '', + index_pattern: '', + interval: '', + axis_position: 'left', + axis_formatter: 'number', + axis_scale: 'normal', + show_legend: 1, + show_grid: 1, }, - editor: ReactEditorController, - editorConfig: { - component: require('./components/vis_editor').VisEditor, - }, - options: { - showQueryBar: false, - showFilterBar: false, - showIndexSelection: false, - }, - requestHandler: metricsRequestHandler, - responseHandler: 'none', - }); -} + component: require('./components/vis_editor').VisEditor, + }, + editor: ReactEditorController, + editorConfig: { + component: require('./components/vis_editor').VisEditor, + }, + options: { + showQueryBar: false, + showFilterBar: false, + showIndexSelection: false, + }, + requestHandler: metricsRequestHandler, + responseHandler: 'none', +}); diff --git a/src/legacy/core_plugins/metrics/public/request_handler.js b/src/legacy/core_plugins/metrics/public/request_handler.js index ce4229274190d..49d569565aaa1 100644 --- a/src/legacy/core_plugins/metrics/public/request_handler.js +++ b/src/legacy/core_plugins/metrics/public/request_handler.js @@ -21,9 +21,12 @@ import { validateInterval } from './lib/validate_interval'; import { timezoneProvider } from 'ui/vis/lib/timezone'; import { timefilter } from 'ui/timefilter'; import { kfetch } from 'ui/kfetch'; +import chrome from 'ui/chrome'; + +const uiSettings = chrome.getUiSettingsClient(); const MetricsRequestHandlerProvider = function(config) { - const timezone = timezoneProvider(); + const timezone = timezoneProvider(uiSettings)(); return { name: 'metrics', From 847f90b09863e9e76a56dbfef3e7e9136551a458 Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Wed, 26 Jun 2019 13:19:13 +0300 Subject: [PATCH 12/25] Take an external dependency from EditorController --- .../metrics/public/editor_controller.js | 13 ++----------- .../core_plugins/metrics/public/kbn_vis_type.js | 7 ++++--- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/legacy/core_plugins/metrics/public/editor_controller.js b/src/legacy/core_plugins/metrics/public/editor_controller.js index 0cd7fff8b7e55..16e64322d21c4 100644 --- a/src/legacy/core_plugins/metrics/public/editor_controller.js +++ b/src/legacy/core_plugins/metrics/public/editor_controller.js @@ -20,11 +20,10 @@ import React from 'react'; import { render, unmountComponentAtNode } from 'react-dom'; import { I18nContext } from 'ui/i18n'; -import chrome from 'ui/chrome'; import { fetchIndexPatternFields } from './lib/fetch_fields'; -function ReactEditorControllerProvider(config) { - class ReactEditorController { +export function createEditorController(config, savedObjectsClient) { + return class EditorController { constructor(el, savedObj) { this.el = el; @@ -36,7 +35,6 @@ function ReactEditorControllerProvider(config) { } fetchDefaultIndexPattern = async () => { - const savedObjectsClient = chrome.getSavedObjectsClient(); const indexPattern = await savedObjectsClient.get( 'index-pattern', config.get('defaultIndex') @@ -85,12 +83,5 @@ function ReactEditorControllerProvider(config) { destroy() { unmountComponentAtNode(this.el); } - } - - return { - name: 'react_editor', - handler: ReactEditorController, }; } - -export { ReactEditorControllerProvider }; diff --git a/src/legacy/core_plugins/metrics/public/kbn_vis_type.js b/src/legacy/core_plugins/metrics/public/kbn_vis_type.js index 8c8edae876c70..10196fd1eb4e2 100644 --- a/src/legacy/core_plugins/metrics/public/kbn_vis_type.js +++ b/src/legacy/core_plugins/metrics/public/kbn_vis_type.js @@ -20,15 +20,16 @@ import chrome from 'ui/chrome'; import { MetricsRequestHandlerProvider } from './request_handler'; import { i18n } from '@kbn/i18n'; -import { ReactEditorControllerProvider } from './editor_controller'; +import { createEditorController } from './editor_controller'; import { defaultFeedbackMessage } from 'ui/vis/default_feedback_message'; import { visFactory } from '../../visualizations/public'; import { PANEL_TYPES } from '../common/panel_types'; const uiSettings = chrome.getUiSettingsClient(); +const savedObjectsClient = chrome.getSavedObjectsClient(); -const ReactEditorController = new ReactEditorControllerProvider(uiSettings).handler; +const EditorController = createEditorController(uiSettings, savedObjectsClient); const metricsRequestHandler = new MetricsRequestHandlerProvider(uiSettings).handler; export const MetricsVis = visFactory.createReactVisualization({ @@ -75,7 +76,7 @@ export const MetricsVis = visFactory.createReactVisualization({ }, component: require('./components/vis_editor').VisEditor, }, - editor: ReactEditorController, + editor: EditorController, editorConfig: { component: require('./components/vis_editor').VisEditor, }, From 335b5af3736d38a97265b636a2fe56fd444501f5 Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Wed, 26 Jun 2019 13:32:02 +0300 Subject: [PATCH 13/25] Take an extra dependency out from Request Handler --- .../metrics/public/kbn_vis_type.js | 4 +- .../metrics/public/request_handler.js | 77 ++++++++----------- .../core_plugins/metrics/public/tsvb_fn.js | 8 +- 3 files changed, 40 insertions(+), 49 deletions(-) diff --git a/src/legacy/core_plugins/metrics/public/kbn_vis_type.js b/src/legacy/core_plugins/metrics/public/kbn_vis_type.js index 10196fd1eb4e2..cc8d6ff7f2019 100644 --- a/src/legacy/core_plugins/metrics/public/kbn_vis_type.js +++ b/src/legacy/core_plugins/metrics/public/kbn_vis_type.js @@ -18,7 +18,7 @@ */ import chrome from 'ui/chrome'; -import { MetricsRequestHandlerProvider } from './request_handler'; +import { createMetricsRequestHandler } from './request_handler'; import { i18n } from '@kbn/i18n'; import { createEditorController } from './editor_controller'; import { defaultFeedbackMessage } from 'ui/vis/default_feedback_message'; @@ -30,7 +30,7 @@ const uiSettings = chrome.getUiSettingsClient(); const savedObjectsClient = chrome.getSavedObjectsClient(); const EditorController = createEditorController(uiSettings, savedObjectsClient); -const metricsRequestHandler = new MetricsRequestHandlerProvider(uiSettings).handler; +const metricsRequestHandler = createMetricsRequestHandler(uiSettings); export const MetricsVis = visFactory.createReactVisualization({ name: 'metrics', diff --git a/src/legacy/core_plugins/metrics/public/request_handler.js b/src/legacy/core_plugins/metrics/public/request_handler.js index 49d569565aaa1..cbfbb3c13bcfa 100644 --- a/src/legacy/core_plugins/metrics/public/request_handler.js +++ b/src/legacy/core_plugins/metrics/public/request_handler.js @@ -21,55 +21,46 @@ import { validateInterval } from './lib/validate_interval'; import { timezoneProvider } from 'ui/vis/lib/timezone'; import { timefilter } from 'ui/timefilter'; import { kfetch } from 'ui/kfetch'; -import chrome from 'ui/chrome'; -const uiSettings = chrome.getUiSettingsClient(); +export const createMetricsRequestHandler = function(config) { + const timezone = timezoneProvider(config)(); -const MetricsRequestHandlerProvider = function(config) { - const timezone = timezoneProvider(uiSettings)(); + return async ({ uiState, timeRange, filters, query, visParams }) => { + const uiStateObj = uiState.get(visParams.type, {}); + const parsedTimeRange = timefilter.calculateBounds(timeRange); + const scaledDataFormat = config.get('dateFormat:scaled'); + const dateFormat = config.get('dateFormat'); - return { - name: 'metrics', + if (visParams && visParams.id) { + try { + const maxBuckets = config.get('metrics:max_buckets'); - handler: async ({ uiState, timeRange, filters, query, visParams }) => { - const uiStateObj = uiState.get(visParams.type, {}); - const parsedTimeRange = timefilter.calculateBounds(timeRange); - const scaledDataFormat = config.get('dateFormat:scaled'); - const dateFormat = config.get('dateFormat'); + validateInterval(parsedTimeRange, visParams, maxBuckets); - if (visParams && visParams.id) { - try { - const maxBuckets = config.get('metrics:max_buckets'); + const resp = await kfetch({ + pathname: '/api/metrics/vis/data', + method: 'POST', + body: JSON.stringify({ + timerange: { + timezone, + ...parsedTimeRange, + }, + query, + filters, + panels: [visParams], + state: uiStateObj, + }), + }); - validateInterval(parsedTimeRange, visParams, maxBuckets); - - const resp = await kfetch({ - pathname: '/api/metrics/vis/data', - method: 'POST', - body: JSON.stringify({ - timerange: { - timezone, - ...parsedTimeRange, - }, - query, - filters, - panels: [visParams], - state: uiStateObj, - }), - }); - - return { - dateFormat, - scaledDataFormat, - timezone, - ...resp, - }; - } catch (error) { - return Promise.reject(error); - } + return { + dateFormat, + scaledDataFormat, + timezone, + ...resp, + }; + } catch (error) { + return Promise.reject(error); } - }, + } }; }; - -export { MetricsRequestHandlerProvider }; diff --git a/src/legacy/core_plugins/metrics/public/tsvb_fn.js b/src/legacy/core_plugins/metrics/public/tsvb_fn.js index 45d2761fb34c8..53135c1e1b420 100644 --- a/src/legacy/core_plugins/metrics/public/tsvb_fn.js +++ b/src/legacy/core_plugins/metrics/public/tsvb_fn.js @@ -19,11 +19,13 @@ import { get } from 'lodash'; import { i18n } from '@kbn/i18n'; -import { MetricsRequestHandlerProvider } from './request_handler'; +import { createMetricsRequestHandler } from './request_handler'; import { PersistedState } from 'ui/persisted_state'; import chrome from 'ui/chrome'; +const uiSettings = chrome.getUiSettingsClient(); + export const tsvb = () => ({ name: 'tsvb', type: 'render', @@ -44,9 +46,7 @@ export const tsvb = () => ({ }, }, async fn(context, args) { - const $injector = await chrome.dangerouslyGetActiveInjector(); - const Private = $injector.get('Private'); - const metricsRequestHandler = Private(MetricsRequestHandlerProvider).handler; + const metricsRequestHandler = createMetricsRequestHandler(uiSettings); const params = JSON.parse(args.params); const uiStateParams = JSON.parse(args.uiState); From 5310184abea485f2dc3b19f5930949a552d3e93a Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Thu, 27 Jun 2019 13:07:48 +0300 Subject: [PATCH 14/25] Rename metricsPlugin to Plugin --- src/legacy/core_plugins/metrics/index.ts | 4 ++-- src/legacy/core_plugins/metrics/server/index.ts | 6 +++--- src/legacy/core_plugins/metrics/server/plugin.ts | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/legacy/core_plugins/metrics/index.ts b/src/legacy/core_plugins/metrics/index.ts index 6c291e8849a4c..9d37c7b0b57bd 100644 --- a/src/legacy/core_plugins/metrics/index.ts +++ b/src/legacy/core_plugins/metrics/index.ts @@ -21,7 +21,7 @@ import { resolve } from 'path'; import { Legacy } from 'kibana'; import { PluginInitializerContext } from 'src/core/server'; import { InternalCoreSetup } from 'src/core/server'; -import { metricsPlugin } from './server/'; +import { plugin } from './server/'; // eslint-disable-next-line import/no-default-export export default function(kibana: any) { @@ -47,7 +47,7 @@ export default function(kibana: any) { const initializerContext = {} as PluginInitializerContext; const core = { http: { server } } as InternalCoreSetup; - metricsPlugin(initializerContext).setup(core); + plugin(initializerContext).setup(core); }, }); } diff --git a/src/legacy/core_plugins/metrics/server/index.ts b/src/legacy/core_plugins/metrics/server/index.ts index a1ac702e661b8..1448a82a7f39c 100644 --- a/src/legacy/core_plugins/metrics/server/index.ts +++ b/src/legacy/core_plugins/metrics/server/index.ts @@ -18,8 +18,8 @@ */ import { PluginInitializerContext } from 'src/core/server'; -import { MetricsPlugin } from './plugin'; +import { Plugin } from './plugin'; -export function metricsPlugin(initializerContext: PluginInitializerContext) { - return new MetricsPlugin(); +export function plugin(initializerContext: PluginInitializerContext) { + return new Plugin(); } diff --git a/src/legacy/core_plugins/metrics/server/plugin.ts b/src/legacy/core_plugins/metrics/server/plugin.ts index 73bbe1a774a07..0d8c467d5ad96 100644 --- a/src/legacy/core_plugins/metrics/server/plugin.ts +++ b/src/legacy/core_plugins/metrics/server/plugin.ts @@ -25,7 +25,7 @@ import { visDataRoutes } from './routes/vis'; // @ts-ignore import { SearchStrategiesRegister } from './lib/search_strategies/search_strategies_register'; -export class MetricsPlugin { +export class Plugin { public setup(core: InternalCoreSetup) { const { http } = core; fieldsRoutes(http.server); From 05a09738fa04be9fb4290b70966f6750be1a69a8 Mon Sep 17 00:00:00 2001 From: "art.gospodarsky" Date: Thu, 27 Jun 2019 16:54:02 +0300 Subject: [PATCH 15/25] Fix reviews --- src/legacy/core_plugins/metrics/index.ts | 2 +- .../metrics/public/{index.ts => plugin.ts} | 19 +++------- .../core_plugins/metrics/public/setup.ts | 35 +++++++++++++++++++ 3 files changed, 40 insertions(+), 16 deletions(-) rename src/legacy/core_plugins/metrics/public/{index.ts => plugin.ts} (79%) create mode 100644 src/legacy/core_plugins/metrics/public/setup.ts diff --git a/src/legacy/core_plugins/metrics/index.ts b/src/legacy/core_plugins/metrics/index.ts index 9d37c7b0b57bd..07dd3b1f3b638 100644 --- a/src/legacy/core_plugins/metrics/index.ts +++ b/src/legacy/core_plugins/metrics/index.ts @@ -32,7 +32,7 @@ export default function(kibana: any) { uiExports: { styleSheetPaths: resolve(__dirname, 'public/index.scss'), - hacks: ['plugins/metrics/'], + hacks: ['plugins/metrics/setup'], }, config(Joi: any) { diff --git a/src/legacy/core_plugins/metrics/public/index.ts b/src/legacy/core_plugins/metrics/public/plugin.ts similarity index 79% rename from src/legacy/core_plugins/metrics/public/index.ts rename to src/legacy/core_plugins/metrics/public/plugin.ts index 64da3e39df583..d946f040a8ba7 100644 --- a/src/legacy/core_plugins/metrics/public/index.ts +++ b/src/legacy/core_plugins/metrics/public/plugin.ts @@ -17,15 +17,12 @@ * under the License. */ -// @ts-ignore -import { functionsRegistry } from 'plugins/interpreter/registries'; // @ts-ignore import { tsvb } from './tsvb_fn'; // @ts-ignore import { MetricsVis } from './kbn_vis_type'; -import { visualizations } from '../../visualizations/public'; -export class Plugin { +class Plugin { // @ts-ignore public setup(core, plugins) { plugins.data.expressions.functionsRegistry.register(tsvb); @@ -38,14 +35,6 @@ export class Plugin { public stop() {} } -const core = {}; -const plugins = { - data: { - expressions: { - functionsRegistry, - }, - }, - visualizations, -}; - -new Plugin().setup(core, plugins); +export function plugin() { + return new Plugin(); +} diff --git a/src/legacy/core_plugins/metrics/public/setup.ts b/src/legacy/core_plugins/metrics/public/setup.ts new file mode 100644 index 0000000000000..3f46302ef5598 --- /dev/null +++ b/src/legacy/core_plugins/metrics/public/setup.ts @@ -0,0 +1,35 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +// @ts-ignore +import { functionsRegistry } from 'plugins/interpreter/registries'; +import { visualizations } from '../../visualizations/public'; +import { plugin } from './plugin'; + +const core = {}; +const plugins = { + data: { + expressions: { + functionsRegistry, + }, + }, + visualizations, +}; + +plugin().setup(core, plugins); From 214e6f607ba601df2917864b9cbb66f5872d6e28 Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Mon, 1 Jul 2019 13:06:02 +0300 Subject: [PATCH 16/25] Add types to .setup() --- src/legacy/core_plugins/metrics/index.ts | 4 ++-- src/legacy/core_plugins/metrics/public/plugin.ts | 5 +++-- src/legacy/core_plugins/metrics/public/setup.ts | 5 +++-- src/legacy/core_plugins/metrics/server/plugin.ts | 5 +++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/legacy/core_plugins/metrics/index.ts b/src/legacy/core_plugins/metrics/index.ts index 07dd3b1f3b638..28420459a1b47 100644 --- a/src/legacy/core_plugins/metrics/index.ts +++ b/src/legacy/core_plugins/metrics/index.ts @@ -20,7 +20,7 @@ import { resolve } from 'path'; import { Legacy } from 'kibana'; import { PluginInitializerContext } from 'src/core/server'; -import { InternalCoreSetup } from 'src/core/server'; +import { CoreSetup } from 'src/core/server'; import { plugin } from './server/'; // eslint-disable-next-line import/no-default-export @@ -45,7 +45,7 @@ export default function(kibana: any) { init(server: Legacy.Server) { const initializerContext = {} as PluginInitializerContext; - const core = { http: { server } } as InternalCoreSetup; + const core = { http: { server } } as CoreSetup | any; // TODO: Remove 'any' as soon as CoreSetup is completed. plugin(initializerContext).setup(core); }, diff --git a/src/legacy/core_plugins/metrics/public/plugin.ts b/src/legacy/core_plugins/metrics/public/plugin.ts index d946f040a8ba7..7ac3984328243 100644 --- a/src/legacy/core_plugins/metrics/public/plugin.ts +++ b/src/legacy/core_plugins/metrics/public/plugin.ts @@ -17,14 +17,15 @@ * under the License. */ +import { CoreSetup, PluginsServiceSetup } from 'src/core/server'; // @ts-ignore import { tsvb } from './tsvb_fn'; // @ts-ignore import { MetricsVis } from './kbn_vis_type'; class Plugin { - // @ts-ignore - public setup(core, plugins) { + // TODO: Remove 'any' as soon as PluginsServiceSetup is completed. + public setup(core: CoreSetup, plugins: PluginsServiceSetup | any) { plugins.data.expressions.functionsRegistry.register(tsvb); // register the provider with the visTypes registry so that other know it exists plugins.visualizations.types.VisTypesRegistryProvider.register(() => MetricsVis); diff --git a/src/legacy/core_plugins/metrics/public/setup.ts b/src/legacy/core_plugins/metrics/public/setup.ts index 3f46302ef5598..17c7278eec724 100644 --- a/src/legacy/core_plugins/metrics/public/setup.ts +++ b/src/legacy/core_plugins/metrics/public/setup.ts @@ -19,10 +19,11 @@ // @ts-ignore import { functionsRegistry } from 'plugins/interpreter/registries'; +import { CoreSetup, PluginsServiceSetup } from 'src/core/server'; import { visualizations } from '../../visualizations/public'; import { plugin } from './plugin'; -const core = {}; +const core = {} as CoreSetup; const plugins = { data: { expressions: { @@ -30,6 +31,6 @@ const plugins = { }, }, visualizations, -}; +} as PluginsServiceSetup | any; // TODO: Remove 'any' as soon as PluginsServiceSetup is completed. plugin().setup(core, plugins); diff --git a/src/legacy/core_plugins/metrics/server/plugin.ts b/src/legacy/core_plugins/metrics/server/plugin.ts index 0d8c467d5ad96..3a09c1fd489e5 100644 --- a/src/legacy/core_plugins/metrics/server/plugin.ts +++ b/src/legacy/core_plugins/metrics/server/plugin.ts @@ -17,7 +17,7 @@ * under the License. */ -import { InternalCoreSetup } from 'kibana/server'; +import { CoreSetup } from 'src/core/server'; // @ts-ignore import { fieldsRoutes } from './routes/fields'; // @ts-ignore @@ -26,7 +26,8 @@ import { visDataRoutes } from './routes/vis'; import { SearchStrategiesRegister } from './lib/search_strategies/search_strategies_register'; export class Plugin { - public setup(core: InternalCoreSetup) { + // TODO: Remove 'any' as soon as CoreSetup is completed. + public setup(core: CoreSetup | any) { const { http } = core; fieldsRoutes(http.server); visDataRoutes(http.server); From 486917c791ff1ec6ad01049852a90436d829d77f Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Tue, 2 Jul 2019 17:18:30 +0300 Subject: [PATCH 17/25] Change types of TSVB --- src/legacy/core_plugins/metrics/index.ts | 4 +++- src/legacy/core_plugins/metrics/public/plugin.ts | 13 ++++++++++--- src/legacy/core_plugins/metrics/public/setup.ts | 6 +++--- src/legacy/core_plugins/metrics/server/plugin.ts | 6 +++--- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/legacy/core_plugins/metrics/index.ts b/src/legacy/core_plugins/metrics/index.ts index 28420459a1b47..a834d7e6beb0d 100644 --- a/src/legacy/core_plugins/metrics/index.ts +++ b/src/legacy/core_plugins/metrics/index.ts @@ -45,7 +45,9 @@ export default function(kibana: any) { init(server: Legacy.Server) { const initializerContext = {} as PluginInitializerContext; - const core = { http: { server } } as CoreSetup | any; // TODO: Remove 'any' as soon as CoreSetup is completed. + // TODO: Remove '@ts-ignore' as soon as CoreSetup is completed. + // @ts-ignore + const core = { http: { server } } as CoreSetup; plugin(initializerContext).setup(core); }, diff --git a/src/legacy/core_plugins/metrics/public/plugin.ts b/src/legacy/core_plugins/metrics/public/plugin.ts index 7ac3984328243..e5eb1e6fe44b1 100644 --- a/src/legacy/core_plugins/metrics/public/plugin.ts +++ b/src/legacy/core_plugins/metrics/public/plugin.ts @@ -17,15 +17,22 @@ * under the License. */ -import { CoreSetup, PluginsServiceSetup } from 'src/core/server'; +import { DataSetup } from 'plugins/data'; +import { VisualizationsSetup } from 'plugins/visualizations'; +import { CoreSetup } from 'src/core/public'; // @ts-ignore import { tsvb } from './tsvb_fn'; // @ts-ignore import { MetricsVis } from './kbn_vis_type'; +export interface TsvbSetupPlugins { + // TODO: Remove `any` as functionsRegistry will be added to the DataSetup. + data: DataSetup | any; + visualizations: VisualizationsSetup; +} + class Plugin { - // TODO: Remove 'any' as soon as PluginsServiceSetup is completed. - public setup(core: CoreSetup, plugins: PluginsServiceSetup | any) { + public setup(core: CoreSetup, plugins: TsvbSetupPlugins) { plugins.data.expressions.functionsRegistry.register(tsvb); // register the provider with the visTypes registry so that other know it exists plugins.visualizations.types.VisTypesRegistryProvider.register(() => MetricsVis); diff --git a/src/legacy/core_plugins/metrics/public/setup.ts b/src/legacy/core_plugins/metrics/public/setup.ts index 17c7278eec724..e4ba8265b3a0c 100644 --- a/src/legacy/core_plugins/metrics/public/setup.ts +++ b/src/legacy/core_plugins/metrics/public/setup.ts @@ -19,9 +19,9 @@ // @ts-ignore import { functionsRegistry } from 'plugins/interpreter/registries'; -import { CoreSetup, PluginsServiceSetup } from 'src/core/server'; +import { CoreSetup } from 'src/core/public'; import { visualizations } from '../../visualizations/public'; -import { plugin } from './plugin'; +import { plugin, TsvbSetupPlugins } from './plugin'; const core = {} as CoreSetup; const plugins = { @@ -31,6 +31,6 @@ const plugins = { }, }, visualizations, -} as PluginsServiceSetup | any; // TODO: Remove 'any' as soon as PluginsServiceSetup is completed. +} as TsvbSetupPlugins; plugin().setup(core, plugins); diff --git a/src/legacy/core_plugins/metrics/server/plugin.ts b/src/legacy/core_plugins/metrics/server/plugin.ts index 3a09c1fd489e5..8abc991d8231d 100644 --- a/src/legacy/core_plugins/metrics/server/plugin.ts +++ b/src/legacy/core_plugins/metrics/server/plugin.ts @@ -17,7 +17,6 @@ * under the License. */ -import { CoreSetup } from 'src/core/server'; // @ts-ignore import { fieldsRoutes } from './routes/fields'; // @ts-ignore @@ -26,8 +25,9 @@ import { visDataRoutes } from './routes/vis'; import { SearchStrategiesRegister } from './lib/search_strategies/search_strategies_register'; export class Plugin { - // TODO: Remove 'any' as soon as CoreSetup is completed. - public setup(core: CoreSetup | any) { + // TODO: Add the CoreSetup type as soon as it is completed. + // @ts-ignore + public setup(core) { const { http } = core; fieldsRoutes(http.server); visDataRoutes(http.server); From b5891c4ec1850dbbf8c1391d0c76124d3e42a7dd Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Thu, 4 Jul 2019 16:24:43 +0300 Subject: [PATCH 18/25] Divide the plugin, its setup config and and entry point --- src/legacy/core_plugins/metrics/index.ts | 2 +- .../core_plugins/metrics/public/index.ts | 27 +++++++++++++++++++ .../core_plugins/metrics/public/plugin.ts | 12 +++------ .../core_plugins/metrics/public/setup.ts | 8 +++--- 4 files changed, 35 insertions(+), 14 deletions(-) create mode 100644 src/legacy/core_plugins/metrics/public/index.ts diff --git a/src/legacy/core_plugins/metrics/index.ts b/src/legacy/core_plugins/metrics/index.ts index a834d7e6beb0d..416434d6f6255 100644 --- a/src/legacy/core_plugins/metrics/index.ts +++ b/src/legacy/core_plugins/metrics/index.ts @@ -32,7 +32,7 @@ export default function(kibana: any) { uiExports: { styleSheetPaths: resolve(__dirname, 'public/index.scss'), - hacks: ['plugins/metrics/setup'], + hacks: ['plugins/metrics/'], }, config(Joi: any) { diff --git a/src/legacy/core_plugins/metrics/public/index.ts b/src/legacy/core_plugins/metrics/public/index.ts new file mode 100644 index 0000000000000..8527e3ff9def7 --- /dev/null +++ b/src/legacy/core_plugins/metrics/public/index.ts @@ -0,0 +1,27 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { Plugin } from './plugin'; +import { core, plugins } from './setup'; + +export function plugin() { + return new Plugin(); +} + +plugin().setup(core, plugins); diff --git a/src/legacy/core_plugins/metrics/public/plugin.ts b/src/legacy/core_plugins/metrics/public/plugin.ts index e5eb1e6fe44b1..66f9d7afe845d 100644 --- a/src/legacy/core_plugins/metrics/public/plugin.ts +++ b/src/legacy/core_plugins/metrics/public/plugin.ts @@ -17,9 +17,9 @@ * under the License. */ -import { DataSetup } from 'plugins/data'; -import { VisualizationsSetup } from 'plugins/visualizations'; -import { CoreSetup } from 'src/core/public'; +import { CoreSetup } from 'kibana/public'; +import { DataSetup } from '../../data/public'; +import { VisualizationsSetup } from '../../visualizations/public'; // @ts-ignore import { tsvb } from './tsvb_fn'; // @ts-ignore @@ -31,7 +31,7 @@ export interface TsvbSetupPlugins { visualizations: VisualizationsSetup; } -class Plugin { +export class Plugin { public setup(core: CoreSetup, plugins: TsvbSetupPlugins) { plugins.data.expressions.functionsRegistry.register(tsvb); // register the provider with the visTypes registry so that other know it exists @@ -42,7 +42,3 @@ class Plugin { public stop() {} } - -export function plugin() { - return new Plugin(); -} diff --git a/src/legacy/core_plugins/metrics/public/setup.ts b/src/legacy/core_plugins/metrics/public/setup.ts index e4ba8265b3a0c..53ef6c6bfde99 100644 --- a/src/legacy/core_plugins/metrics/public/setup.ts +++ b/src/legacy/core_plugins/metrics/public/setup.ts @@ -21,10 +21,10 @@ import { functionsRegistry } from 'plugins/interpreter/registries'; import { CoreSetup } from 'src/core/public'; import { visualizations } from '../../visualizations/public'; -import { plugin, TsvbSetupPlugins } from './plugin'; +import { TsvbSetupPlugins } from './plugin'; -const core = {} as CoreSetup; -const plugins = { +export const core = {} as CoreSetup; +export const plugins = { data: { expressions: { functionsRegistry, @@ -32,5 +32,3 @@ const plugins = { }, visualizations, } as TsvbSetupPlugins; - -plugin().setup(core, plugins); From c36da2c4da7dd8e3c38859e75a61097f8e5e7e58 Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Thu, 4 Jul 2019 17:50:32 +0300 Subject: [PATCH 19/25] Get rid of @ts-ignore --- src/legacy/core_plugins/metrics/index.ts | 5 ++--- src/legacy/core_plugins/metrics/server/plugin.ts | 12 +++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/legacy/core_plugins/metrics/index.ts b/src/legacy/core_plugins/metrics/index.ts index 416434d6f6255..2aa0a2d76dec0 100644 --- a/src/legacy/core_plugins/metrics/index.ts +++ b/src/legacy/core_plugins/metrics/index.ts @@ -22,6 +22,7 @@ import { Legacy } from 'kibana'; import { PluginInitializerContext } from 'src/core/server'; import { CoreSetup } from 'src/core/server'; import { plugin } from './server/'; +import { CustomCoreSetup } from './server/plugin'; // eslint-disable-next-line import/no-default-export export default function(kibana: any) { @@ -45,9 +46,7 @@ export default function(kibana: any) { init(server: Legacy.Server) { const initializerContext = {} as PluginInitializerContext; - // TODO: Remove '@ts-ignore' as soon as CoreSetup is completed. - // @ts-ignore - const core = { http: { server } } as CoreSetup; + const core = { http: { server } } as CoreSetup & CustomCoreSetup; plugin(initializerContext).setup(core); }, diff --git a/src/legacy/core_plugins/metrics/server/plugin.ts b/src/legacy/core_plugins/metrics/server/plugin.ts index 8abc991d8231d..727490351f951 100644 --- a/src/legacy/core_plugins/metrics/server/plugin.ts +++ b/src/legacy/core_plugins/metrics/server/plugin.ts @@ -17,6 +17,7 @@ * under the License. */ +import { CoreSetup } from 'src/core/server'; // @ts-ignore import { fieldsRoutes } from './routes/fields'; // @ts-ignore @@ -24,10 +25,15 @@ import { visDataRoutes } from './routes/vis'; // @ts-ignore import { SearchStrategiesRegister } from './lib/search_strategies/search_strategies_register'; +// TODO: Remove as CoreSetup is completed. +export interface CustomCoreSetup { + http: { + server: any; + }; +} + export class Plugin { - // TODO: Add the CoreSetup type as soon as it is completed. - // @ts-ignore - public setup(core) { + public setup(core: CoreSetup & CustomCoreSetup) { const { http } = core; fieldsRoutes(http.server); visDataRoutes(http.server); From 9801e7c68f3e98584c84965059f6e0570b3583ed Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Fri, 5 Jul 2019 13:08:10 +0300 Subject: [PATCH 20/25] Add a server type to the CustomCoreSetup interface --- src/legacy/core_plugins/metrics/server/plugin.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/legacy/core_plugins/metrics/server/plugin.ts b/src/legacy/core_plugins/metrics/server/plugin.ts index 727490351f951..f94d619fd5212 100644 --- a/src/legacy/core_plugins/metrics/server/plugin.ts +++ b/src/legacy/core_plugins/metrics/server/plugin.ts @@ -17,6 +17,7 @@ * under the License. */ +import { Legacy } from 'kibana'; import { CoreSetup } from 'src/core/server'; // @ts-ignore import { fieldsRoutes } from './routes/fields'; @@ -28,7 +29,7 @@ import { SearchStrategiesRegister } from './lib/search_strategies/search_strateg // TODO: Remove as CoreSetup is completed. export interface CustomCoreSetup { http: { - server: any; + server: Legacy.Server; }; } From 669c09808b7a462708818687c30fcda207b470d8 Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Tue, 9 Jul 2019 12:29:48 +0300 Subject: [PATCH 21/25] Revert kbn_vis_type settings --- .../metrics/public/editor_controller.js | 2 +- .../metrics/public/kbn_vis_type.js | 121 +++++++++--------- .../core_plugins/metrics/public/plugin.ts | 2 +- .../core_plugins/metrics/public/tsvb_fn.js | 4 +- 4 files changed, 64 insertions(+), 65 deletions(-) diff --git a/src/legacy/core_plugins/metrics/public/editor_controller.js b/src/legacy/core_plugins/metrics/public/editor_controller.js index 16e64322d21c4..464cec744eed7 100644 --- a/src/legacy/core_plugins/metrics/public/editor_controller.js +++ b/src/legacy/core_plugins/metrics/public/editor_controller.js @@ -23,7 +23,7 @@ import { I18nContext } from 'ui/i18n'; import { fetchIndexPatternFields } from './lib/fetch_fields'; export function createEditorController(config, savedObjectsClient) { - return class EditorController { + return class { constructor(el, savedObj) { this.el = el; diff --git a/src/legacy/core_plugins/metrics/public/kbn_vis_type.js b/src/legacy/core_plugins/metrics/public/kbn_vis_type.js index cc8d6ff7f2019..f24f6e8d3e9e9 100644 --- a/src/legacy/core_plugins/metrics/public/kbn_vis_type.js +++ b/src/legacy/core_plugins/metrics/public/kbn_vis_type.js @@ -26,65 +26,66 @@ import { visFactory } from '../../visualizations/public'; import { PANEL_TYPES } from '../common/panel_types'; -const uiSettings = chrome.getUiSettingsClient(); -const savedObjectsClient = chrome.getSavedObjectsClient(); +export const MetricsVis = () => { + const uiSettings = chrome.getUiSettingsClient(); + const savedObjectsClient = chrome.getSavedObjectsClient(); + const EditorController = createEditorController(uiSettings, savedObjectsClient); + const metricsRequestHandler = createMetricsRequestHandler(uiSettings); -const EditorController = createEditorController(uiSettings, savedObjectsClient); -const metricsRequestHandler = createMetricsRequestHandler(uiSettings); - -export const MetricsVis = visFactory.createReactVisualization({ - name: 'metrics', - title: i18n.translate('tsvb.kbnVisTypes.metricsTitle', { defaultMessage: 'TSVB' }), - description: i18n.translate('tsvb.kbnVisTypes.metricsDescription', { - defaultMessage: 'Build time-series using a visual pipeline interface', - }), - icon: 'visVisualBuilder', - feedbackMessage: defaultFeedbackMessage, - visConfig: { - defaults: { - id: '61ca57f0-469d-11e7-af02-69e470af7417', - type: PANEL_TYPES.TIMESERIES, - series: [ - { - id: '61ca57f1-469d-11e7-af02-69e470af7417', - color: '#68BC00', - split_mode: 'everything', - metrics: [ - { - id: '61ca57f2-469d-11e7-af02-69e470af7417', - type: 'count', - }, - ], - separate_axis: 0, - axis_position: 'right', - formatter: 'number', - chart_type: 'line', - line_width: 1, - point_size: 1, - fill: 0.5, - stacked: 'none', - }, - ], - time_field: '', - index_pattern: '', - interval: '', - axis_position: 'left', - axis_formatter: 'number', - axis_scale: 'normal', - show_legend: 1, - show_grid: 1, + return visFactory.createReactVisualization({ + name: 'metrics', + title: i18n.translate('tsvb.kbnVisTypes.metricsTitle', { defaultMessage: 'TSVB' }), + description: i18n.translate('tsvb.kbnVisTypes.metricsDescription', { + defaultMessage: 'Build time-series using a visual pipeline interface', + }), + icon: 'visVisualBuilder', + feedbackMessage: defaultFeedbackMessage, + visConfig: { + defaults: { + id: '61ca57f0-469d-11e7-af02-69e470af7417', + type: PANEL_TYPES.TIMESERIES, + series: [ + { + id: '61ca57f1-469d-11e7-af02-69e470af7417', + color: '#68BC00', + split_mode: 'everything', + metrics: [ + { + id: '61ca57f2-469d-11e7-af02-69e470af7417', + type: 'count', + }, + ], + separate_axis: 0, + axis_position: 'right', + formatter: 'number', + chart_type: 'line', + line_width: 1, + point_size: 1, + fill: 0.5, + stacked: 'none', + }, + ], + time_field: '', + index_pattern: '', + interval: '', + axis_position: 'left', + axis_formatter: 'number', + axis_scale: 'normal', + show_legend: 1, + show_grid: 1, + }, + component: require('./components/vis_editor').VisEditor, + }, + editor: EditorController, + editorConfig: { + component: require('./components/vis_editor').VisEditor, + }, + options: { + showQueryBar: false, + showFilterBar: false, + showIndexSelection: false, }, - component: require('./components/vis_editor').VisEditor, - }, - editor: EditorController, - editorConfig: { - component: require('./components/vis_editor').VisEditor, - }, - options: { - showQueryBar: false, - showFilterBar: false, - showIndexSelection: false, - }, - requestHandler: metricsRequestHandler, - responseHandler: 'none', -}); + requestHandler: metricsRequestHandler, + responseHandler: 'none', + }); +}; diff --git a/src/legacy/core_plugins/metrics/public/plugin.ts b/src/legacy/core_plugins/metrics/public/plugin.ts index 66f9d7afe845d..77692e5b8e25d 100644 --- a/src/legacy/core_plugins/metrics/public/plugin.ts +++ b/src/legacy/core_plugins/metrics/public/plugin.ts @@ -35,7 +35,7 @@ export class Plugin { public setup(core: CoreSetup, plugins: TsvbSetupPlugins) { plugins.data.expressions.functionsRegistry.register(tsvb); // register the provider with the visTypes registry so that other know it exists - plugins.visualizations.types.VisTypesRegistryProvider.register(() => MetricsVis); + plugins.visualizations.types.VisTypesRegistryProvider.register(MetricsVis); } public start() {} diff --git a/src/legacy/core_plugins/metrics/public/tsvb_fn.js b/src/legacy/core_plugins/metrics/public/tsvb_fn.js index 53135c1e1b420..a4ddfe7f2086c 100644 --- a/src/legacy/core_plugins/metrics/public/tsvb_fn.js +++ b/src/legacy/core_plugins/metrics/public/tsvb_fn.js @@ -24,8 +24,6 @@ import { PersistedState } from 'ui/persisted_state'; import chrome from 'ui/chrome'; -const uiSettings = chrome.getUiSettingsClient(); - export const tsvb = () => ({ name: 'tsvb', type: 'render', @@ -46,8 +44,8 @@ export const tsvb = () => ({ }, }, async fn(context, args) { + const uiSettings = chrome.getUiSettingsClient(); const metricsRequestHandler = createMetricsRequestHandler(uiSettings); - const params = JSON.parse(args.params); const uiStateParams = JSON.parse(args.uiState); const uiState = new PersistedState(uiStateParams); From e1055fd0b39e42ba5000b2b97bea2a65a2642f71 Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Thu, 11 Jul 2019 13:56:10 +0300 Subject: [PATCH 22/25] Restructure public assets --- src/legacy/core_plugins/metrics/index.ts | 2 +- .../core_plugins/metrics/public/index.ts | 10 +++---- .../core_plugins/metrics/public/legacy.ts | 26 +++++++++++++++++ .../core_plugins/metrics/public/plugin.ts | 28 +++++++++++++++---- 4 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 src/legacy/core_plugins/metrics/public/legacy.ts diff --git a/src/legacy/core_plugins/metrics/index.ts b/src/legacy/core_plugins/metrics/index.ts index 2aa0a2d76dec0..5017a943896dc 100644 --- a/src/legacy/core_plugins/metrics/index.ts +++ b/src/legacy/core_plugins/metrics/index.ts @@ -33,7 +33,7 @@ export default function(kibana: any) { uiExports: { styleSheetPaths: resolve(__dirname, 'public/index.scss'), - hacks: ['plugins/metrics/'], + hacks: ['plugins/metrics/legacy'], }, config(Joi: any) { diff --git a/src/legacy/core_plugins/metrics/public/index.ts b/src/legacy/core_plugins/metrics/public/index.ts index 8527e3ff9def7..9be2e6e239f37 100644 --- a/src/legacy/core_plugins/metrics/public/index.ts +++ b/src/legacy/core_plugins/metrics/public/index.ts @@ -17,11 +17,9 @@ * under the License. */ -import { Plugin } from './plugin'; -import { core, plugins } from './setup'; +import { PluginInitializerContext } from 'kibana/public'; +import { TsvbPlugin } from './plugin'; -export function plugin() { - return new Plugin(); +export function plugin(initializerContext: PluginInitializerContext) { + return new TsvbPlugin(initializerContext); } - -plugin().setup(core, plugins); diff --git a/src/legacy/core_plugins/metrics/public/legacy.ts b/src/legacy/core_plugins/metrics/public/legacy.ts new file mode 100644 index 0000000000000..e160db2b43b55 --- /dev/null +++ b/src/legacy/core_plugins/metrics/public/legacy.ts @@ -0,0 +1,26 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { PluginInitializerContext } from 'kibana/public'; +import { core, plugins } from './setup'; +import { plugin } from '.'; + +const pluginInstance = plugin({} as PluginInitializerContext); + +export const setup = pluginInstance.setup(core, plugins); diff --git a/src/legacy/core_plugins/metrics/public/plugin.ts b/src/legacy/core_plugins/metrics/public/plugin.ts index 77692e5b8e25d..f375dd7100355 100644 --- a/src/legacy/core_plugins/metrics/public/plugin.ts +++ b/src/legacy/core_plugins/metrics/public/plugin.ts @@ -17,7 +17,7 @@ * under the License. */ -import { CoreSetup } from 'kibana/public'; +import { CoreSetup, CoreStart, Plugin, PluginInitializerContext } from 'kibana/public'; import { DataSetup } from '../../data/public'; import { VisualizationsSetup } from '../../visualizations/public'; // @ts-ignore @@ -25,20 +25,38 @@ import { tsvb } from './tsvb_fn'; // @ts-ignore import { MetricsVis } from './kbn_vis_type'; +/** @public */ +export type TsvbSetup = void; +/** @public */ +export type TsvbStart = void; + +/** @internal */ export interface TsvbSetupPlugins { - // TODO: Remove `any` as functionsRegistry will be added to the DataSetup. + // TODO: Remove `any` as functionsRegistry is added to the DataSetup. data: DataSetup | any; visualizations: VisualizationsSetup; } -export class Plugin { - public setup(core: CoreSetup, plugins: TsvbSetupPlugins) { +/** @internal */ +export interface TsvbStartPlugins { + foo: any; +} + +export class TsvbPlugin + implements Plugin { + initializerContext: PluginInitializerContext; + + constructor(initializerContext: PluginInitializerContext) { + this.initializerContext = initializerContext; + } + + public setup(core: CoreSetup, plugins: TsvbSetupPlugins): TsvbSetup { plugins.data.expressions.functionsRegistry.register(tsvb); // register the provider with the visTypes registry so that other know it exists plugins.visualizations.types.VisTypesRegistryProvider.register(MetricsVis); } - public start() {} + public start(core: CoreStart, plugins: TsvbStartPlugins): TsvbStart {} public stop() {} } From 5eee9872b22ec19f24c6da731383851575405048 Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Mon, 15 Jul 2019 12:19:53 +0300 Subject: [PATCH 23/25] Move setup.js inner to the legacy.ts --- .../core_plugins/metrics/public/legacy.ts | 16 ++++++++- .../core_plugins/metrics/public/plugin.ts | 5 ++- .../core_plugins/metrics/public/setup.ts | 34 ------------------- 3 files changed, 17 insertions(+), 38 deletions(-) delete mode 100644 src/legacy/core_plugins/metrics/public/setup.ts diff --git a/src/legacy/core_plugins/metrics/public/legacy.ts b/src/legacy/core_plugins/metrics/public/legacy.ts index e160db2b43b55..59d31f6abf931 100644 --- a/src/legacy/core_plugins/metrics/public/legacy.ts +++ b/src/legacy/core_plugins/metrics/public/legacy.ts @@ -17,10 +17,24 @@ * under the License. */ +// @ts-ignore +import { functionsRegistry } from 'plugins/interpreter/registries'; import { PluginInitializerContext } from 'kibana/public'; -import { core, plugins } from './setup'; +import { CoreSetup } from 'src/core/public'; +import { visualizations } from '../../visualizations/public'; +import { TsvbSetupPlugins } from './plugin'; import { plugin } from '.'; +export const core = {} as CoreSetup; +export const plugins = { + data: { + expressions: { + functionsRegistry, + }, + }, + visualizations, +} as TsvbSetupPlugins; + const pluginInstance = plugin({} as PluginInitializerContext); export const setup = pluginInstance.setup(core, plugins); diff --git a/src/legacy/core_plugins/metrics/public/plugin.ts b/src/legacy/core_plugins/metrics/public/plugin.ts index f375dd7100355..d9c95b8075745 100644 --- a/src/legacy/core_plugins/metrics/public/plugin.ts +++ b/src/legacy/core_plugins/metrics/public/plugin.ts @@ -38,9 +38,8 @@ export interface TsvbSetupPlugins { } /** @internal */ -export interface TsvbStartPlugins { - foo: any; -} +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface TsvbStartPlugins {} export class TsvbPlugin implements Plugin { diff --git a/src/legacy/core_plugins/metrics/public/setup.ts b/src/legacy/core_plugins/metrics/public/setup.ts deleted file mode 100644 index 53ef6c6bfde99..0000000000000 --- a/src/legacy/core_plugins/metrics/public/setup.ts +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -// @ts-ignore -import { functionsRegistry } from 'plugins/interpreter/registries'; -import { CoreSetup } from 'src/core/public'; -import { visualizations } from '../../visualizations/public'; -import { TsvbSetupPlugins } from './plugin'; - -export const core = {} as CoreSetup; -export const plugins = { - data: { - expressions: { - functionsRegistry, - }, - }, - visualizations, -} as TsvbSetupPlugins; From f5143e2d42ea6c02f0231d5b32f04aef6f09ecd6 Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Thu, 1 Aug 2019 12:23:32 +0300 Subject: [PATCH 24/25] clean up --- src/legacy/core_plugins/metrics/index.ts | 32 ++++++++------- .../core_plugins/metrics/public/index.ts | 6 +-- .../core_plugins/metrics/public/legacy.ts | 21 ++++------ .../public/{tsvb_fn.js => metrics_fn.ts} | 13 ++++--- .../{kbn_vis_type.js => metrics_type.ts} | 11 ++++-- .../core_plugins/metrics/public/plugin.ts | 39 +++++++------------ .../core_plugins/metrics/server/index.ts | 6 +-- .../core_plugins/metrics/server/plugin.ts | 12 +++++- 8 files changed, 69 insertions(+), 71 deletions(-) rename src/legacy/core_plugins/metrics/public/{tsvb_fn.js => metrics_fn.ts} (94%) rename src/legacy/core_plugins/metrics/public/{kbn_vis_type.js => metrics_type.ts} (96%) diff --git a/src/legacy/core_plugins/metrics/index.ts b/src/legacy/core_plugins/metrics/index.ts index 5017a943896dc..128f8d6a72944 100644 --- a/src/legacy/core_plugins/metrics/index.ts +++ b/src/legacy/core_plugins/metrics/index.ts @@ -21,21 +21,28 @@ import { resolve } from 'path'; import { Legacy } from 'kibana'; import { PluginInitializerContext } from 'src/core/server'; import { CoreSetup } from 'src/core/server'; + import { plugin } from './server/'; import { CustomCoreSetup } from './server/plugin'; -// eslint-disable-next-line import/no-default-export -export default function(kibana: any) { - return new kibana.Plugin({ - id: 'metrics', - - require: ['kibana', 'elasticsearch', 'visualizations', 'data'], +import { LegacyPluginApi, LegacyPluginInitializer } from '../../../../src/legacy/types'; +const metricsPluginInitializer: LegacyPluginInitializer = ({ Plugin }: LegacyPluginApi) => + new Plugin({ + id: 'metrics', + require: ['kibana', 'elasticsearch', 'visualizations', 'interpreter', 'data'], + publicDir: resolve(__dirname, 'public'), uiExports: { styleSheetPaths: resolve(__dirname, 'public/index.scss'), - hacks: ['plugins/metrics/legacy'], + hacks: [resolve(__dirname, 'public/legacy')], + injectDefaultVars: server => ({}), }, + init: (server: Legacy.Server) => { + const initializerContext = {} as PluginInitializerContext; + const core = { http: { server } } as CoreSetup & CustomCoreSetup; + plugin(initializerContext).setup(core); + }, config(Joi: any) { return Joi.object({ enabled: Joi.boolean().default(true), @@ -43,12 +50,7 @@ export default function(kibana: any) { minimumBucketSize: Joi.number().default(10), }).default(); }, + } as Legacy.PluginSpecOptions); - init(server: Legacy.Server) { - const initializerContext = {} as PluginInitializerContext; - const core = { http: { server } } as CoreSetup & CustomCoreSetup; - - plugin(initializerContext).setup(core); - }, - }); -} +// eslint-disable-next-line import/no-default-export +export default metricsPluginInitializer; diff --git a/src/legacy/core_plugins/metrics/public/index.ts b/src/legacy/core_plugins/metrics/public/index.ts index 9be2e6e239f37..16b099ba16ae9 100644 --- a/src/legacy/core_plugins/metrics/public/index.ts +++ b/src/legacy/core_plugins/metrics/public/index.ts @@ -17,9 +17,9 @@ * under the License. */ -import { PluginInitializerContext } from 'kibana/public'; -import { TsvbPlugin } from './plugin'; +import { PluginInitializerContext } from '../../../../core/public'; +import { MetricsPlugin as Plugin } from './plugin'; export function plugin(initializerContext: PluginInitializerContext) { - return new TsvbPlugin(initializerContext); + return new Plugin(initializerContext); } diff --git a/src/legacy/core_plugins/metrics/public/legacy.ts b/src/legacy/core_plugins/metrics/public/legacy.ts index 59d31f6abf931..49420e4b51273 100644 --- a/src/legacy/core_plugins/metrics/public/legacy.ts +++ b/src/legacy/core_plugins/metrics/public/legacy.ts @@ -17,24 +17,19 @@ * under the License. */ -// @ts-ignore -import { functionsRegistry } from 'plugins/interpreter/registries'; import { PluginInitializerContext } from 'kibana/public'; -import { CoreSetup } from 'src/core/public'; +import { npSetup, npStart } from 'ui/new_platform'; + import { visualizations } from '../../visualizations/public'; -import { TsvbSetupPlugins } from './plugin'; +import { MetricsPluginSetupDependencies } from './plugin'; import { plugin } from '.'; -export const core = {} as CoreSetup; -export const plugins = { - data: { - expressions: { - functionsRegistry, - }, - }, +const plugins: Readonly = { visualizations, -} as TsvbSetupPlugins; + data: npSetup.plugins.data, +}; const pluginInstance = plugin({} as PluginInitializerContext); -export const setup = pluginInstance.setup(core, plugins); +export const setup = pluginInstance.setup(npSetup.core, plugins); +export const start = pluginInstance.start(npStart.core); diff --git a/src/legacy/core_plugins/metrics/public/tsvb_fn.js b/src/legacy/core_plugins/metrics/public/metrics_fn.ts similarity index 94% rename from src/legacy/core_plugins/metrics/public/tsvb_fn.js rename to src/legacy/core_plugins/metrics/public/metrics_fn.ts index a4ddfe7f2086c..9d49d4e5784b8 100644 --- a/src/legacy/core_plugins/metrics/public/tsvb_fn.js +++ b/src/legacy/core_plugins/metrics/public/metrics_fn.ts @@ -19,12 +19,13 @@ import { get } from 'lodash'; import { i18n } from '@kbn/i18n'; -import { createMetricsRequestHandler } from './request_handler'; import { PersistedState } from 'ui/persisted_state'; - import chrome from 'ui/chrome'; -export const tsvb = () => ({ +// @ts-ignore +import { createMetricsRequestHandler } from './request_handler'; + +export const createMetricsFn = () => ({ name: 'tsvb', type: 'render', context: { @@ -43,7 +44,7 @@ export const tsvb = () => ({ default: '"{}"', }, }, - async fn(context, args) { + async fn(context: any, args: any) { const uiSettings = chrome.getUiSettingsClient(); const metricsRequestHandler = createMetricsRequestHandler(uiSettings); const params = JSON.parse(args.params); @@ -55,7 +56,7 @@ export const tsvb = () => ({ query: get(context, 'query', null), filters: get(context, 'filters', null), visParams: params, - uiState: uiState, + uiState, }); response.visType = 'metrics'; @@ -66,7 +67,7 @@ export const tsvb = () => ({ value: { visType: 'metrics', visConfig: params, - uiState: uiState, + uiState, visData: response, }, }; diff --git a/src/legacy/core_plugins/metrics/public/kbn_vis_type.js b/src/legacy/core_plugins/metrics/public/metrics_type.ts similarity index 96% rename from src/legacy/core_plugins/metrics/public/kbn_vis_type.js rename to src/legacy/core_plugins/metrics/public/metrics_type.ts index f24f6e8d3e9e9..35182fbe25265 100644 --- a/src/legacy/core_plugins/metrics/public/kbn_vis_type.js +++ b/src/legacy/core_plugins/metrics/public/metrics_type.ts @@ -18,15 +18,20 @@ */ import chrome from 'ui/chrome'; -import { createMetricsRequestHandler } from './request_handler'; import { i18n } from '@kbn/i18n'; -import { createEditorController } from './editor_controller'; +// @ts-ignore import { defaultFeedbackMessage } from 'ui/vis/default_feedback_message'; + import { visFactory } from '../../visualizations/public'; +// @ts-ignore +import { createMetricsRequestHandler } from './request_handler'; +// @ts-ignore +import { createEditorController } from './editor_controller'; +// @ts-ignore import { PANEL_TYPES } from '../common/panel_types'; -export const MetricsVis = () => { +export const createMetricsTypeDefinition = () => { const uiSettings = chrome.getUiSettingsClient(); const savedObjectsClient = chrome.getSavedObjectsClient(); const EditorController = createEditorController(uiSettings, savedObjectsClient); diff --git a/src/legacy/core_plugins/metrics/public/plugin.ts b/src/legacy/core_plugins/metrics/public/plugin.ts index d9c95b8075745..e1eca37970604 100644 --- a/src/legacy/core_plugins/metrics/public/plugin.ts +++ b/src/legacy/core_plugins/metrics/public/plugin.ts @@ -16,46 +16,33 @@ * specific language governing permissions and limitations * under the License. */ - -import { CoreSetup, CoreStart, Plugin, PluginInitializerContext } from 'kibana/public'; -import { DataSetup } from '../../data/public'; +import { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from '../../../../core/public'; +import { Plugin as DataPublicPlugin } from '../../../../plugins/data/public'; import { VisualizationsSetup } from '../../visualizations/public'; -// @ts-ignore -import { tsvb } from './tsvb_fn'; -// @ts-ignore -import { MetricsVis } from './kbn_vis_type'; -/** @public */ -export type TsvbSetup = void; -/** @public */ -export type TsvbStart = void; +import { createMetricsFn } from './metrics_fn'; +import { createMetricsTypeDefinition } from './metrics_type'; /** @internal */ -export interface TsvbSetupPlugins { - // TODO: Remove `any` as functionsRegistry is added to the DataSetup. - data: DataSetup | any; +export interface MetricsPluginSetupDependencies { + data: ReturnType; visualizations: VisualizationsSetup; } /** @internal */ -// eslint-disable-next-line @typescript-eslint/no-empty-interface -export interface TsvbStartPlugins {} - -export class TsvbPlugin - implements Plugin { +export class MetricsPlugin implements Plugin, void> { initializerContext: PluginInitializerContext; constructor(initializerContext: PluginInitializerContext) { this.initializerContext = initializerContext; } - public setup(core: CoreSetup, plugins: TsvbSetupPlugins): TsvbSetup { - plugins.data.expressions.functionsRegistry.register(tsvb); - // register the provider with the visTypes registry so that other know it exists - plugins.visualizations.types.VisTypesRegistryProvider.register(MetricsVis); + public async setup(core: CoreSetup, { data, visualizations }: MetricsPluginSetupDependencies) { + data.expressions.registerFunction(createMetricsFn); + visualizations.types.VisTypesRegistryProvider.register(createMetricsTypeDefinition); } - public start(core: CoreStart, plugins: TsvbStartPlugins): TsvbStart {} - - public stop() {} + public start(core: CoreStart) { + // nothing to do here yet + } } diff --git a/src/legacy/core_plugins/metrics/server/index.ts b/src/legacy/core_plugins/metrics/server/index.ts index 1448a82a7f39c..14047c31f2dcd 100644 --- a/src/legacy/core_plugins/metrics/server/index.ts +++ b/src/legacy/core_plugins/metrics/server/index.ts @@ -17,9 +17,9 @@ * under the License. */ -import { PluginInitializerContext } from 'src/core/server'; -import { Plugin } from './plugin'; +import { PluginInitializerContext } from 'kibana/server'; +import { MetricsServerPlugin as Plugin } from './plugin'; export function plugin(initializerContext: PluginInitializerContext) { - return new Plugin(); + return new Plugin(initializerContext); } diff --git a/src/legacy/core_plugins/metrics/server/plugin.ts b/src/legacy/core_plugins/metrics/server/plugin.ts index f94d619fd5212..027354d6181a2 100644 --- a/src/legacy/core_plugins/metrics/server/plugin.ts +++ b/src/legacy/core_plugins/metrics/server/plugin.ts @@ -18,7 +18,8 @@ */ import { Legacy } from 'kibana'; -import { CoreSetup } from 'src/core/server'; +import { PluginInitializerContext, CoreSetup } from 'kibana/server'; + // @ts-ignore import { fieldsRoutes } from './routes/fields'; // @ts-ignore @@ -33,9 +34,16 @@ export interface CustomCoreSetup { }; } -export class Plugin { +export class MetricsServerPlugin { + public initializerContext: PluginInitializerContext; + + constructor(initializerContext: PluginInitializerContext) { + this.initializerContext = initializerContext; + } + public setup(core: CoreSetup & CustomCoreSetup) { const { http } = core; + fieldsRoutes(http.server); visDataRoutes(http.server); From ae365790142c5b5e78a1d6ccd1ff92774373c8cf Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Fri, 2 Aug 2019 15:37:17 +0300 Subject: [PATCH 25/25] fix PR commnets --- .../core_plugins/metrics/public/metrics_fn.ts | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/legacy/core_plugins/metrics/public/metrics_fn.ts b/src/legacy/core_plugins/metrics/public/metrics_fn.ts index 9d49d4e5784b8..5baab42f2e1ba 100644 --- a/src/legacy/core_plugins/metrics/public/metrics_fn.ts +++ b/src/legacy/core_plugins/metrics/public/metrics_fn.ts @@ -22,11 +22,32 @@ import { i18n } from '@kbn/i18n'; import { PersistedState } from 'ui/persisted_state'; import chrome from 'ui/chrome'; +import { ExpressionFunction, KibanaContext, Render } from '../../interpreter/types'; + // @ts-ignore import { createMetricsRequestHandler } from './request_handler'; -export const createMetricsFn = () => ({ - name: 'tsvb', +const name = 'tsvb'; +type Context = KibanaContext | null; + +interface Arguments { + params: string; + uiState: string; +} + +type VisParams = Required; + +interface RenderValue { + visType: 'metrics'; + visData: Context; + visConfig: VisParams; + uiState: any; +} + +type Return = Promise>; + +export const createMetricsFn = (): ExpressionFunction => ({ + name, type: 'render', context: { types: ['kibana_context', 'null'], @@ -38,13 +59,15 @@ export const createMetricsFn = () => ({ params: { types: ['string'], default: '"{}"', + help: '', }, uiState: { types: ['string'], default: '"{}"', + help: '', }, }, - async fn(context: any, args: any) { + async fn(context: Context, args: Arguments) { const uiSettings = chrome.getUiSettingsClient(); const metricsRequestHandler = createMetricsRequestHandler(uiSettings); const params = JSON.parse(args.params); @@ -65,9 +88,9 @@ export const createMetricsFn = () => ({ type: 'render', as: 'visualization', value: { + uiState, visType: 'metrics', visConfig: params, - uiState, visData: response, }, };