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

Move infra plugin server to NP folder #53945

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6ae305d
Sets up the basic client-side shim for infra UI
jasonrhodes Dec 11, 2019
68d7996
Moves main init legacy stuff to top level shim index file
jasonrhodes Dec 12, 2019
d21691a
Merge remote-tracking branch 'upstream/master' into logs-ui-client-np…
Kerry350 Dec 12, 2019
7fc147e
WIP getting react rendering in place, not working yet
jasonrhodes Dec 12, 2019
3b8f4af
Merge branch 'logs-ui-client-np-shim' of github.com:jasonrhodes/kiban…
Kerry350 Dec 12, 2019
1af00d1
Get the app rendering
Kerry350 Dec 12, 2019
f8c25c9
Add a top level KibanaFramework context provider to pass down core se…
Kerry350 Dec 12, 2019
74e7681
Replace legacy uses of uiCapabilities with context from kibana_react
Kerry350 Dec 13, 2019
593274d
Merge remote-tracking branch 'upstream/master' into logs-ui-client-np…
Kerry350 Dec 16, 2019
904d936
Remove unused lines
Kerry350 Dec 16, 2019
70609c1
Migrate (almost all) instances of ui/chrome
Kerry350 Dec 16, 2019
85e62ec
Merge remote-tracking branch 'upstream/master' into logs-ui-client-np…
Kerry350 Dec 16, 2019
9736891
Migrate ui/kfetch
Kerry350 Dec 17, 2019
4536465
Merge remote-tracking branch 'upstream/master' into logs-ui-client-np…
Kerry350 Dec 17, 2019
c91f19a
Migrate ui/notify references
Kerry350 Dec 17, 2019
1715c5d
Migrate ui/index_patterns types
Kerry350 Dec 17, 2019
0bbb5b8
Tweak dependencies array
Kerry350 Dec 17, 2019
2a08ace
Migrate ui/i18n reference
Kerry350 Dec 17, 2019
1137b59
Amend types
Kerry350 Dec 17, 2019
57e8b7e
Amend return value to make tests pass
Kerry350 Dec 17, 2019
c78e6bf
Remove files
Kerry350 Dec 17, 2019
843e709
Merge branch 'master' into logs-ui-client-np-shim
elasticmachine Dec 17, 2019
9cb020d
Merge remote-tracking branch 'upstream/master' into logs-ui-client-np…
Kerry350 Dec 18, 2019
2d4fcc4
Merge remote-tracking branch 'upstream/master' into logs-ui-client-np…
Kerry350 Dec 18, 2019
5dde1e0
Fix typecheck / test
Kerry350 Dec 18, 2019
c31e6cf
Merge branch 'logs-ui-client-np-shim' of github.com:Kerry350/kibana i…
Kerry350 Dec 18, 2019
aded8e9
Merge remote-tracking branch 'upstream/master' into logs-ui-client-np…
Kerry350 Dec 18, 2019
5abd68b
Differentiate between index and app whilst we aren't 100% in the NP
Kerry350 Dec 18, 2019
d9c874d
Amend import
Kerry350 Dec 18, 2019
56fbd18
Increase notification timeouts and make sure a message is displayed w…
Kerry350 Dec 19, 2019
06ad151
Moves server and common files into new platform plugin directory
jasonrhodes Dec 23, 2019
41fdabb
Unshims NP server plugin
jasonrhodes Dec 23, 2019
44dfcbd
Fixes index patterns dependency for NP (based on APM)
jasonrhodes Dec 23, 2019
38e8916
Removes lodash/fp dependency to avoid need for our own lodash
jasonrhodes Dec 23, 2019
67f2416
WIP server np move
jasonrhodes Jan 3, 2020
e7781ce
vis_type_timeseries server side new platform migration (#52501)
Kerry350 Dec 19, 2019
900ac43
Adds metrics plugin dep back after cherry picking needed changes
jasonrhodes Jan 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 4 additions & 9 deletions src/legacy/core_plugins/vis_type_timeseries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@

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';

import { LegacyPluginApi, LegacyPluginInitializer } from '../../../../src/legacy/types';
import { VisTypeTimeseriesSetup } from '../../../plugins/vis_type_timeseries/server';

const metricsPluginInitializer: LegacyPluginInitializer = ({ Plugin }: LegacyPluginApi) =>
new Plugin({
Expand All @@ -38,10 +34,9 @@ const metricsPluginInitializer: LegacyPluginInitializer = ({ Plugin }: LegacyPlu
injectDefaultVars: server => ({}),
},
init: (server: Legacy.Server) => {
const initializerContext = {} as PluginInitializerContext;
const core = { http: { server } } as CoreSetup & CustomCoreSetup;

plugin(initializerContext).setup(core);
const visTypeTimeSeriesPlugin = server.newPlatform.setup.plugins
.metrics as VisTypeTimeseriesSetup;
visTypeTimeSeriesPlugin.__legacy.registerLegacyAPI({ server });
},
config(Joi: any) {
return Joi.object({
Expand Down
8 changes: 2 additions & 6 deletions src/legacy/core_plugins/vis_type_timeseries/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,5 @@
* under the License.
*/

import { PluginInitializerContext } from 'kibana/server';
import { MetricsServerPlugin as Plugin } from './plugin';

export function plugin(initializerContext: PluginInitializerContext) {
return new Plugin(initializerContext);
}
export { init } from './init';
export { getVisData, GetVisData, GetVisDataOptions } from './lib/get_vis_data';
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
* under the License.
*/

import { Legacy } from 'kibana';
import { PluginInitializerContext, CoreSetup } from 'kibana/server';

// @ts-ignore
import { fieldsRoutes } from './routes/fields';
// @ts-ignore
Expand All @@ -28,30 +25,15 @@ import { visDataRoutes } from './routes/vis';
import { SearchStrategiesRegister } from './lib/search_strategies/search_strategies_register';
// @ts-ignore
import { getVisData } from './lib/get_vis_data';
import { Framework } from '../../../../plugins/vis_type_timeseries/server';

// TODO: Remove as CoreSetup is completed.
export interface CustomCoreSetup {
http: {
server: Legacy.Server;
};
}

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);
export const init = async (framework: Framework, __LEGACY: any) => {
const { core } = framework;
const router = core.http.createRouter();

// Expose getVisData to allow plugins to use TSVB's backend for metrics
http.server.expose('getVisData', getVisData);
visDataRoutes(router, framework);

SearchStrategiesRegister.init(http.server);
}
}
// [LEGACY_TODO]
fieldsRoutes(__LEGACY.server);
SearchStrategiesRegister.init(__LEGACY.server);
};
101 changes: 101 additions & 0 deletions src/legacy/core_plugins/vis_type_timeseries/server/lib/get_vis_data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* 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 { RequestHandlerContext } from 'src/core/server';
import _ from 'lodash';
import { first, map } from 'rxjs/operators';
import { getPanelData } from './vis_data/get_panel_data';
import { Framework } from '../../../../../plugins/vis_type_timeseries/server';

interface GetVisDataResponse {
[key: string]: GetVisDataPanel;
}

interface GetVisDataPanel {
id: string;
series: GetVisDataSeries[];
}

interface GetVisDataSeries {
id: string;
label: string;
data: GetVisDataDataPoint[];
}

type GetVisDataDataPoint = [number, number];

export interface GetVisDataOptions {
timerange?: any;
panels?: any;
filters?: any;
state?: any;
query?: any;
}

export type GetVisData = (
requestContext: RequestHandlerContext,
options: GetVisDataOptions,
framework: Framework
) => Promise<GetVisDataResponse>;

export function getVisData(
requestContext: RequestHandlerContext,
options: GetVisDataOptions,
framework: Framework
): Promise<GetVisDataResponse> {
// NOTE / TODO: This facade has been put in place to make migrating to the New Platform easier. It
// removes the need to refactor many layers of dependencies on "req", and instead just augments the top
// level object passed from here. The layers should be refactored fully at some point, but for now
// this works and we are still using the New Platform services for these vis data portions.
const reqFacade: any = {
payload: options,
getUiSettingsService: () => requestContext.core.uiSettings.client,
getSavedObjectsClient: () => requestContext.core.savedObjects.client,
server: {
plugins: {
elasticsearch: {
getCluster: () => {
return {
callWithRequest: async (req: any, endpoint: string, params: any) => {
return await requestContext.core.elasticsearch.dataClient.callAsCurrentUser(
endpoint,
params
);
},
};
},
},
},
},
getEsShardTimeout: async () => {
return await framework.globalConfig$
.pipe(
first(),
map(config => config.elasticsearch.shardTimeout.asMilliseconds())
)
.toPromise();
},
};
const promises = reqFacade.payload.panels.map(getPanelData(reqFacade));
return Promise.all(promises).then(res => {
return res.reduce((acc, data) => {
return _.assign(acc as any, data);
}, {});
}) as Promise<GetVisDataResponse>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,14 @@
* under the License.
*/

import moment from 'moment';
import { of } from 'rxjs';
import { expect } from 'chai';
import { getEsShardTimeout } from '../../helpers/get_es_shard_timeout';

describe('getEsShardTimeout', () => {
it('should return the elasticsearch.shardTimeout', async () => {
const req = {
server: {
newPlatform: {
__internals: {
elasticsearch: { legacy: { config$: of({ shardTimeout: moment.duration(12345) }) } },
},
},
getEsShardTimeout: async () => {
return 12345;
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,4 @@
* under the License.
*/

import _ from 'lodash';
import { getPanelData } from './vis_data/get_panel_data';

export function getVisData(req) {
const promises = req.payload.panels.map(getPanelData(req));
return Promise.all(promises).then(res => {
return res.reduce((acc, data) => {
return _.assign(acc, data);
}, {});
});
}
export function getPanelData(req: any): any;
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export async function getSeriesData(req, panel) {

const data = await searchRequest.search(searches);
const series = data.map(handleResponseBody(panel));

let annotations = null;

if (panel.annotations && panel.annotations.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { first, map } from 'rxjs/operators';

export async function getEsShardTimeout(req) {
return await req.server.newPlatform.__internals.elasticsearch.legacy.config$
.pipe(
first(),
map(config => config.shardTimeout.asMilliseconds())
)
.toPromise();
return await req.getEsShardTimeout();
}
35 changes: 20 additions & 15 deletions src/legacy/core_plugins/vis_type_timeseries/server/routes/vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,28 @@
* under the License.
*/

import { schema } from '@kbn/config-schema';
import { getVisData } from '../lib/get_vis_data';
import Boom from 'boom';

export const visDataRoutes = server => {
server.route({
path: '/api/metrics/vis/data',
method: 'POST',
handler: async req => {
try {
return await getVisData(req);
} catch (err) {
if (err.isBoom && err.status === 401) {
return err;
}
const escapeHatch = schema.object({}, { allowUnknowns: true });

throw Boom.boomify(err, { statusCode: 500 });
}
export const visDataRoutes = (router, framework) => {
router.post(
{
path: '/api/metrics/vis/data',
validate: {
body: escapeHatch,
},
},
});
async (requestContext, request, response) => {
try {
const results = await getVisData(requestContext, request.body, framework);
return response.ok({ body: results });
} catch (error) {
return response.internalError({
body: error.message,
});
}
}
);
};
6 changes: 6 additions & 0 deletions src/plugins/vis_type_timeseries/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"id": "metrics",
"version": "8.0.0",
"kibanaVersion": "kibana",
"server": true
}
35 changes: 35 additions & 0 deletions src/plugins/vis_type_timeseries/server/index.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 { schema, TypeOf } from '@kbn/config-schema';
import { PluginInitializerContext } from 'src/core/server';
import { VisTypeTimeseriesPlugin } from './plugin';
export { VisTypeTimeseriesSetup, Framework } from './plugin';

export const config = {
schema: schema.object({
enabled: schema.boolean({ defaultValue: true }),
}),
};

export type VisTypeTimeseriesConfig = TypeOf<typeof config.schema>;

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