Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[TSVB] Shim new platform #39169

Merged
merged 46 commits into from
Aug 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
001dc1a
Shim server side to new platform
Jun 18, 2019
d4c049c
Merge branch 'master' into metrics-shim-new-platform
Jun 20, 2019
ae523fb
Shim public to new platfrom
Jun 21, 2019
1aeb0be
Break by services
Jun 21, 2019
c72cebd
Merge branch 'master' into metrics-shim-new-platform
Jun 24, 2019
60db353
Add dependencies to the TSVB plugin
Jun 24, 2019
9444061
Change folder structure for the shim
Jun 24, 2019
2a7174b
Pass services as a second argument of setup() and small fixes
Jun 24, 2019
379b3d5
Merge branch 'master' into metrics-shim-new-platform
Jun 24, 2019
a90d699
Add start() to the Plugin
Jun 24, 2019
3b91dcc
Get rid of the Private
Jun 24, 2019
9f4c116
Merge branch 'master' into metrics-shim-new-platform
Jun 25, 2019
69d0aff
Pass the core to setup()
Jun 25, 2019
f821fe5
Merge branch 'master' into metrics-shim-new-platform
Jun 26, 2019
bbb4c49
Get rid of NP folder
Jun 26, 2019
263378b
Set config to timezoneProvider()
Jun 26, 2019
847f90b
Take an external dependency from EditorController
Jun 26, 2019
335b5af
Take an extra dependency out from Request Handler
Jun 26, 2019
4d87639
Merge remote-tracking branch 'upstream/master' into metrics-shim-new-…
Jun 26, 2019
6422fe3
Merge branch 'master' into metrics-shim-new-platform
Jun 27, 2019
5310184
Rename metricsPlugin to Plugin
Jun 27, 2019
05a0973
Fix reviews
Jun 27, 2019
61e9140
Merge branch 'master' into metrics-shim-new-platform
Jun 28, 2019
2c035e1
Merge branch 'master' into metrics-shim-new-platform
Jul 1, 2019
214e6f6
Add types to .setup()
Jul 1, 2019
486917c
Change types of TSVB
Jul 2, 2019
3b94740
Merge remote-tracking branch 'upstream/master' into metrics-shim-new-…
Jul 4, 2019
b5891c4
Divide the plugin, its setup config and and entry point
Jul 4, 2019
c36da2c
Get rid of @ts-ignore
Jul 4, 2019
87ca0e8
Merge remote-tracking branch 'upstream/master' into metrics-shim-new-…
Jul 5, 2019
8c929fa
Merge branch 'metrics-shim-new-platform' of github.com:Avinar-24/kiba…
Jul 5, 2019
ad4f29a
Merge remote-tracking branch 'upstream/master' into metrics-shim-new-…
Jul 5, 2019
69f74c5
Merge branch 'metrics-shim-new-platform' of github.com:Avinar-24/kiba…
Jul 5, 2019
9801e7c
Add a server type to the CustomCoreSetup interface
Jul 5, 2019
b5cf84e
Merge remote-tracking branch 'upstream/master' into metrics-shim-new-…
Jul 9, 2019
669c098
Revert kbn_vis_type settings
Jul 9, 2019
410371c
Merge remote-tracking branch 'upstream/master' into metrics-shim-new-…
Jul 11, 2019
e1055fd
Restructure public assets
Jul 11, 2019
17f4344
Merge remote-tracking branch 'upstream/master' into metrics-shim-new-…
Jul 12, 2019
f1ed49a
Merge remote-tracking branch 'upstream/master' into metrics-shim-new-…
Jul 15, 2019
5eee987
Move setup.js inner to the legacy.ts
Jul 15, 2019
468ada5
Merge remote-tracking branch 'upstream/master' into metrics-shim-new-…
Jul 16, 2019
6b95d14
Merge branch 'master' into metrics-shim-new-platform
alexwizp Aug 1, 2019
f5143e2
clean up
alexwizp Aug 1, 2019
ae36579
fix PR commnets
alexwizp Aug 2, 2019
5d07730
Merge branch 'master' of github.com:elastic/kibana into metrics-shim-…
alexwizp Aug 3, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,39 @@
*/

import { resolve } from 'path';
import { Legacy } from 'kibana';
import { PluginInitializerContext } from 'src/core/server';
import { CoreSetup } from 'src/core/server';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could combine the above two imports


import { fieldsRoutes } from './server/routes/fields';
import { visDataRoutes } from './server/routes/vis';
import { SearchStrategiesRegister } from './server/lib/search_strategies/search_strategies_register';
import { plugin } from './server/';
import { CustomCoreSetup } from './server/plugin';

export default function(kibana) {
return new kibana.Plugin({
require: ['kibana', 'elasticsearch'],
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: {
visTypes: ['plugins/metrics/kbn_vis_types'],
interpreter: ['plugins/metrics/tsvb_fn'],
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
hacks: [resolve(__dirname, 'public/legacy')],
injectDefaultVars: server => ({}),
},
init: (server: Legacy.Server) => {
const initializerContext = {} as PluginInitializerContext;
const core = { http: { server } } as CoreSetup & CustomCoreSetup;

config(Joi) {
plugin(initializerContext).setup(core);
},
config(Joi: any) {
return Joi.object({
enabled: Joi.boolean().default(true),
chartResolution: Joi.number().default(150),
minimumBucketSize: Joi.number().default(10),
}).default();
},
} as Legacy.PluginSpecOptions);

init(server) {
fieldsRoutes(server);
visDataRoutes(server);

SearchStrategiesRegister.init(server);
},
});
}
// eslint-disable-next-line import/no-default-export
export default metricsPluginInitializer;
Original file line number Diff line number Diff line change
Expand Up @@ -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';
import { fetchIndexPatternFields } from './lib/fetch_fields';

function ReactEditorControllerProvider(config) {
class ReactEditorController {
export function createEditorController(config, savedObjectsClient) {
return class {
constructor(el, savedObj) {
this.el = el;

Expand All @@ -36,7 +35,6 @@ function ReactEditorControllerProvider(config) {
}

fetchDefaultIndexPattern = async () => {
const savedObjectsClient = chrome.getSavedObjectsClient();
const indexPattern = await savedObjectsClient.get(
'index-pattern',
config.get('defaultIndex')
Expand Down Expand Up @@ -85,12 +83,5 @@ function ReactEditorControllerProvider(config) {
destroy() {
unmountComponentAtNode(this.el);
}
}

return {
name: 'react_editor',
handler: ReactEditorController,
};
}

export { ReactEditorControllerProvider };
25 changes: 25 additions & 0 deletions src/legacy/core_plugins/metrics/public/index.ts
Original file line number Diff line number Diff line change
@@ -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 '../../../../core/public';
import { MetricsPlugin as Plugin } from './plugin';

export function plugin(initializerContext: PluginInitializerContext) {
return new Plugin(initializerContext);
}

This file was deleted.

35 changes: 35 additions & 0 deletions src/legacy/core_plugins/metrics/public/legacy.ts
Original file line number Diff line number Diff line change
@@ -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 { PluginInitializerContext } from 'kibana/public';
import { npSetup, npStart } from 'ui/new_platform';

import { visualizations } from '../../visualizations/public';
import { MetricsPluginSetupDependencies } from './plugin';
import { plugin } from '.';

const plugins: Readonly<MetricsPluginSetupDependencies> = {
visualizations,
data: npSetup.plugins.data,
};

const pluginInstance = plugin({} as PluginInitializerContext);

export const setup = pluginInstance.setup(npSetup.core, plugins);
export const start = pluginInstance.start(npStart.core);
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,37 @@
* 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';
import { PersistedState } from 'ui/persisted_state';

import chrome from 'ui/chrome';

export const tsvb = () => ({
name: 'tsvb',
import { ExpressionFunction, KibanaContext, Render } from '../../interpreter/types';

// @ts-ignore
import { createMetricsRequestHandler } from './request_handler';

const name = 'tsvb';
type Context = KibanaContext | null;

interface Arguments {
params: string;
uiState: string;
}

type VisParams = Required<Arguments>;

interface RenderValue {
visType: 'metrics';
visData: Context;
visConfig: VisParams;
uiState: any;
}

type Return = Promise<Render<RenderValue>>;

export const createMetricsFn = (): ExpressionFunction<typeof name, Context, Arguments, Return> => ({
name,
type: 'render',
context: {
types: ['kibana_context', 'null'],
Expand All @@ -38,17 +59,17 @@ export const tsvb = () => ({
params: {
types: ['string'],
default: '"{}"',
help: '',
},
uiState: {
types: ['string'],
default: '"{}"',
help: '',
},
},
async fn(context, args) {
const $injector = await chrome.dangerouslyGetActiveInjector();
const Private = $injector.get('Private');
const metricsRequestHandler = Private(MetricsRequestHandlerProvider).handler;

async fn(context: Context, args: Arguments) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: context, arguments types don't need to be here

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);
Expand All @@ -58,7 +79,7 @@ export const tsvb = () => ({
query: get(context, 'query', null),
filters: get(context, 'filters', null),
visParams: params,
uiState: uiState,
uiState,
});

response.visType = 'metrics';
Expand All @@ -67,13 +88,11 @@ export const tsvb = () => ({
type: 'render',
as: 'visualization',
value: {
uiState,
visType: 'metrics',
visConfig: params,
uiState: uiState,
visData: response,
},
};
},
});

functionsRegistry.register(tsvb);
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,27 @@
* under the License.
*/

import { MetricsRequestHandlerProvider } from './request_handler';
import chrome from 'ui/chrome';
import { i18n } from '@kbn/i18n';
import { ReactEditorControllerProvider } from './editor_controller';
import { VisFactoryProvider } from 'ui/vis/vis_factory';
// @ts-ignore
import { defaultFeedbackMessage } from 'ui/vis/default_feedback_message';

import { PANEL_TYPES } from '../../common/panel_types';
import { visFactory } from '../../visualizations/public';

// register the provider with the visTypes registry so that other know it exists
import { VisTypesRegistryProvider } from 'ui/registry/vis_types';
VisTypesRegistryProvider.register(MetricsVisProvider);
// @ts-ignore
import { createMetricsRequestHandler } from './request_handler';
// @ts-ignore
import { createEditorController } from './editor_controller';
// @ts-ignore
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;
export const createMetricsTypeDefinition = () => {
const uiSettings = chrome.getUiSettingsClient();
const savedObjectsClient = chrome.getSavedObjectsClient();
const EditorController = createEditorController(uiSettings, savedObjectsClient);
const metricsRequestHandler = createMetricsRequestHandler(uiSettings);

return VisFactory.createReactVisualization({
return visFactory.createReactVisualization({
name: 'metrics',
title: i18n.translate('tsvb.kbnVisTypes.metricsTitle', { defaultMessage: 'TSVB' }),
description: i18n.translate('tsvb.kbnVisTypes.metricsDescription', {
Expand Down Expand Up @@ -76,11 +79,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,
editor: EditorController,
editorConfig: {
component: require('../components/vis_editor').VisEditor,
component: require('./components/vis_editor').VisEditor,
},
options: {
showQueryBar: false,
Expand All @@ -90,4 +93,4 @@ export function MetricsVisProvider(Private) {
requestHandler: metricsRequestHandler,
responseHandler: 'none',
});
}
};
Loading