From 867b75fecb01f4244011c45695c683a1c5eb97a1 Mon Sep 17 00:00:00 2001 From: Francesco Gualazzi Date: Wed, 9 Feb 2022 15:11:18 +0100 Subject: [PATCH] Add testing config and lint errors (#10) * add tests: jest config and common testing * remove unnecessary file * lint: renamed files, apply ESLint * group similar features in same file Signed-off-by: inge4pres --- src/plugins/profiling/common/index.test.ts | 21 +++ src/plugins/profiling/common/index.ts | 5 +- src/plugins/profiling/jest.config.js | 16 ++ src/plugins/profiling/server/routes/index.ts | 37 ++++- .../server/routes/load_flameChartPixi.ts | 34 ---- ...lameChartElastic.ts => load_flamechart.ts} | 25 ++- .../server/routes/load_topNContainers.ts | 34 ---- .../server/routes/load_topNDeployments.ts | 36 ----- .../profiling/server/routes/load_topNHosts.ts | 34 ---- .../server/routes/load_topNStackTraces.ts | 51 ------ .../server/routes/load_topNThreads.ts | 34 ---- .../profiling/server/routes/load_topn.ts | 145 ++++++++++++++++++ .../server/routes/register_routes.ts | 41 ----- ...rch_flameChart.ts => search_flamechart.ts} | 4 +- .../server/routes/search_topNContainers.ts | 18 --- .../server/routes/search_topNDeployments.ts | 18 --- .../server/routes/search_topNHosts.ts | 18 --- .../server/routes/search_topNStackTraces.ts | 18 --- .../server/routes/search_topNThreads.ts | 18 --- .../routes/{search_topN.ts => search_topn.ts} | 38 ++++- 20 files changed, 284 insertions(+), 361 deletions(-) create mode 100644 src/plugins/profiling/common/index.test.ts create mode 100644 src/plugins/profiling/jest.config.js delete mode 100644 src/plugins/profiling/server/routes/load_flameChartPixi.ts rename src/plugins/profiling/server/routes/{load_flameChartElastic.ts => load_flamechart.ts} (63%) delete mode 100644 src/plugins/profiling/server/routes/load_topNContainers.ts delete mode 100644 src/plugins/profiling/server/routes/load_topNDeployments.ts delete mode 100644 src/plugins/profiling/server/routes/load_topNHosts.ts delete mode 100644 src/plugins/profiling/server/routes/load_topNStackTraces.ts delete mode 100644 src/plugins/profiling/server/routes/load_topNThreads.ts create mode 100644 src/plugins/profiling/server/routes/load_topn.ts delete mode 100644 src/plugins/profiling/server/routes/register_routes.ts rename src/plugins/profiling/server/routes/{search_flameChart.ts => search_flamechart.ts} (98%) delete mode 100644 src/plugins/profiling/server/routes/search_topNContainers.ts delete mode 100644 src/plugins/profiling/server/routes/search_topNDeployments.ts delete mode 100644 src/plugins/profiling/server/routes/search_topNHosts.ts delete mode 100644 src/plugins/profiling/server/routes/search_topNStackTraces.ts delete mode 100644 src/plugins/profiling/server/routes/search_topNThreads.ts rename src/plugins/profiling/server/routes/{search_topN.ts => search_topn.ts} (78%) diff --git a/src/plugins/profiling/common/index.test.ts b/src/plugins/profiling/common/index.test.ts new file mode 100644 index 00000000000000..fd60230b807aa6 --- /dev/null +++ b/src/plugins/profiling/common/index.test.ts @@ -0,0 +1,21 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { timeRangeFromRequest } from './index'; + +describe('Common profiling helpers', () => { + test('convert query parameters time ranges into tuple', () => { + const request = { + query: { + timeFrom: 123, + timeTo: 456, + }, + }; + expect(timeRangeFromRequest(request)).toEqual([123, 456]); + }); +}); diff --git a/src/plugins/profiling/common/index.ts b/src/plugins/profiling/common/index.ts index fcd26897a81baf..5a02c7b83bd15b 100644 --- a/src/plugins/profiling/common/index.ts +++ b/src/plugins/profiling/common/index.ts @@ -5,7 +5,6 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ -import {KibanaRequest} from 'kibana/server'; export const PLUGIN_ID = 'profiling'; export const PLUGIN_NAME = 'profiling'; @@ -24,7 +23,7 @@ export function getLocalRoutePaths() { TopNThreads: `${BASE_LOCAL_ROUTE_PATH}/topn/threads`, TopNTraces: `${BASE_LOCAL_ROUTE_PATH}/topn/traces`, FlamechartElastic: `${BASE_LOCAL_ROUTE_PATH}/flamechart/elastic`, - FlamechartPixi: `${BASE_LOCAL_ROUTE_PATH}/flamechart/pixi` + FlamechartPixi: `${BASE_LOCAL_ROUTE_PATH}/flamechart/pixi`, }; } @@ -37,7 +36,7 @@ export function getRemoteRoutePaths() { TopNThreads: `${BASE_REMOTE_ROUTE_PATH}/topn/threads`, TopNTraces: `${BASE_REMOTE_ROUTE_PATH}/topn/traces`, FlamechartElastic: `${BASE_REMOTE_ROUTE_PATH}/flamechart/elastic`, - FlamechartPixi: `${BASE_REMOTE_ROUTE_PATH}/flamechart/pixi` + FlamechartPixi: `${BASE_REMOTE_ROUTE_PATH}/flamechart/pixi`, }; } diff --git a/src/plugins/profiling/jest.config.js b/src/plugins/profiling/jest.config.js new file mode 100644 index 00000000000000..92981131d373ad --- /dev/null +++ b/src/plugins/profiling/jest.config.js @@ -0,0 +1,16 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +module.exports = { + preset: '@kbn/test', + rootDir: '../../..', + roots: ['/src/plugins/profiling'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/profiling', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/profiling/{common,public,server}/**/*.{ts,tsx}'], +}; diff --git a/src/plugins/profiling/server/routes/index.ts b/src/plugins/profiling/server/routes/index.ts index bd582ecd899146..5b49f91393eb36 100644 --- a/src/plugins/profiling/server/routes/index.ts +++ b/src/plugins/profiling/server/routes/index.ts @@ -5,4 +5,39 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ -export { registerRoutes } from './register_routes'; +import type { IRouter } from 'kibana/server'; +import { DataRequestHandlerContext } from '../../../data/server'; +import { registerFlameChartElasticRoute, registerFlameChartPixiRoute } from './load_flamechart'; +import { + registerTraceEventsTopNContainersRoute, + registerTraceEventsTopNDeploymentsRoute, + registerTraceEventsTopNHostsRoute, + registerTraceEventsTopNStackTracesRoute, + registerTraceEventsTopNThreadsRoute, +} from './load_topn'; + +import { registerFlameChartSearchRoute } from './search_flamechart'; +import { + registerTraceEventsTopNContainersSearchRoute, + registerTraceEventsTopNDeploymentsSearchRoute, + registerTraceEventsTopNHostsSearchRoute, + registerTraceEventsTopNStackTracesSearchRoute, + registerTraceEventsTopNThreadsSearchRoute, +} from './search_topn'; + +export function registerRoutes(router: IRouter) { + registerFlameChartElasticRoute(router); + registerFlameChartPixiRoute(router); + registerTraceEventsTopNContainersRoute(router); + registerTraceEventsTopNDeploymentsRoute(router); + registerTraceEventsTopNHostsRoute(router); + registerTraceEventsTopNStackTracesRoute(router); + registerTraceEventsTopNThreadsRoute(router); + + registerFlameChartSearchRoute(router); + registerTraceEventsTopNContainersSearchRoute(router); + registerTraceEventsTopNDeploymentsSearchRoute(router); + registerTraceEventsTopNHostsSearchRoute(router); + registerTraceEventsTopNStackTracesSearchRoute(router); + registerTraceEventsTopNThreadsSearchRoute(router); +} diff --git a/src/plugins/profiling/server/routes/load_flameChartPixi.ts b/src/plugins/profiling/server/routes/load_flameChartPixi.ts deleted file mode 100644 index a0bdf27f82a378..00000000000000 --- a/src/plugins/profiling/server/routes/load_flameChartPixi.ts +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -import { schema } from '@kbn/config-schema'; -import type { DataRequestHandlerContext } from '../../../data/server'; -import type { IRouter } from '../../../../core/server'; -import { getLocalRoutePaths, timeRangeFromRequest } from '../../common'; - -export function registerFlameChartPixiRoute(router: IRouter) { - const paths = getLocalRoutePaths(); - router.get( - { - path: paths.FlamechartPixi, - validate: { - query: schema.object({ - index: schema.maybe(schema.string()), - projectID: schema.maybe(schema.string()), - timeFrom: schema.maybe(schema.string()), - timeTo: schema.maybe(schema.string()), - }), - }, - }, - async (ctx, request, response) => { - const [timeFrom, timeTo] = timeRangeFromRequest(request); - const src = await import(`../fixtures/flamechart_${timeTo - timeFrom}`); - delete src.default; - return response.ok({ body: src }); - } - ); -} diff --git a/src/plugins/profiling/server/routes/load_flameChartElastic.ts b/src/plugins/profiling/server/routes/load_flamechart.ts similarity index 63% rename from src/plugins/profiling/server/routes/load_flameChartElastic.ts rename to src/plugins/profiling/server/routes/load_flamechart.ts index ddf7827e5dc390..6942c61b1a7b3b 100644 --- a/src/plugins/profiling/server/routes/load_flameChartElastic.ts +++ b/src/plugins/profiling/server/routes/load_flamechart.ts @@ -6,8 +6,8 @@ * Side Public License, v 1. */ import { schema } from '@kbn/config-schema'; +import type { IRouter } from 'kibana/server'; import type { DataRequestHandlerContext } from '../../../data/server'; -import type { IRouter } from '../../../../core/server'; import { getLocalRoutePaths, timeRangeFromRequest } from '../../common'; import { mapFlamechart } from './mappings'; @@ -33,3 +33,26 @@ export function registerFlameChartElasticRoute(router: IRouter) { + const paths = getLocalRoutePaths(); + router.get( + { + path: paths.FlamechartPixi, + validate: { + query: schema.object({ + index: schema.maybe(schema.string()), + projectID: schema.maybe(schema.string()), + timeFrom: schema.maybe(schema.string()), + timeTo: schema.maybe(schema.string()), + }), + }, + }, + async (ctx, request, response) => { + const [timeFrom, timeTo] = timeRangeFromRequest(request); + const src = await import(`../fixtures/flamechart_${timeTo - timeFrom}`); + delete src.default; + return response.ok({ body: src }); + } + ); +} diff --git a/src/plugins/profiling/server/routes/load_topNContainers.ts b/src/plugins/profiling/server/routes/load_topNContainers.ts deleted file mode 100644 index dbc253235cf14c..00000000000000 --- a/src/plugins/profiling/server/routes/load_topNContainers.ts +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -import { schema } from '@kbn/config-schema'; -import type { DataRequestHandlerContext } from '../../../data/server'; -import type { IRouter } from '../../../../core/server'; -import { getLocalRoutePaths, timeRangeFromRequest } from '../../common'; - -export function registerTraceEventsTopNContainersRoute(router: IRouter) { - const paths = getLocalRoutePaths(); - router.get( - { - path: paths.TopNContainers, - validate: { - query: schema.object({ - index: schema.maybe(schema.string()), - projectID: schema.maybe(schema.string()), - timeFrom: schema.maybe(schema.string()), - timeTo: schema.maybe(schema.string()), - }), - }, - }, - async (ctx, request, response) => { - const [timeFrom, timeTo] = timeRangeFromRequest(request); - const src = await import(`../fixtures/containers_${timeTo - timeFrom}`); - delete src.default; - return response.ok({ body: src }); - } - ); -} diff --git a/src/plugins/profiling/server/routes/load_topNDeployments.ts b/src/plugins/profiling/server/routes/load_topNDeployments.ts deleted file mode 100644 index bbbc69a2304a17..00000000000000 --- a/src/plugins/profiling/server/routes/load_topNDeployments.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -import { schema } from '@kbn/config-schema'; -import type { DataRequestHandlerContext } from '../../../data/server'; -import type { IRouter } from '../../../../core/server'; -import { getLocalRoutePaths, timeRangeFromRequest } from '../../common'; - -export function registerTraceEventsTopNDeploymentsRoute( - router: IRouter -) { - const paths = getLocalRoutePaths(); - router.get( - { - path: paths.TopNDeployments, - validate: { - query: schema.object({ - index: schema.maybe(schema.string()), - projectID: schema.maybe(schema.string()), - timeFrom: schema.maybe(schema.string()), - timeTo: schema.maybe(schema.string()), - }), - }, - }, - async (ctx, request, response) => { - const [timeFrom, timeTo] = timeRangeFromRequest(request); - const src = await import(`../fixtures/pods_${timeTo - timeFrom}`); - delete src.default; - return response.ok({ body: src }); - } - ); -} diff --git a/src/plugins/profiling/server/routes/load_topNHosts.ts b/src/plugins/profiling/server/routes/load_topNHosts.ts deleted file mode 100644 index f3e2e5c2963f34..00000000000000 --- a/src/plugins/profiling/server/routes/load_topNHosts.ts +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -import { schema } from '@kbn/config-schema'; -import type { DataRequestHandlerContext } from '../../../data/server'; -import type { IRouter } from '../../../../core/server'; -import { getLocalRoutePaths, timeRangeFromRequest } from '../../common'; - -export function registerTraceEventsTopNHostsRoute(router: IRouter) { - const paths = getLocalRoutePaths(); - router.get( - { - path: paths.TopNHosts, - validate: { - query: schema.object({ - index: schema.maybe(schema.string()), - projectID: schema.maybe(schema.string()), - timeFrom: schema.maybe(schema.string()), - timeTo: schema.maybe(schema.string()), - }), - }, - }, - async (ctx, request, response) => { - const [timeFrom, timeTo] = timeRangeFromRequest(request); - const src = await import(`../fixtures/hosts_${timeTo - timeFrom}`); - delete src.default; - return response.ok({ body: src }); - } - ); -} diff --git a/src/plugins/profiling/server/routes/load_topNStackTraces.ts b/src/plugins/profiling/server/routes/load_topNStackTraces.ts deleted file mode 100644 index bb30be0b365cce..00000000000000 --- a/src/plugins/profiling/server/routes/load_topNStackTraces.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -import { schema } from '@kbn/config-schema'; -import type { DataRequestHandlerContext } from '../../../data/server'; -import type { IRouter } from '../../../../core/server'; -import { getLocalRoutePaths, timeRangeFromRequest } from '../../common'; - -function transformFlamechart(src) { - const obj = { - Total: src.TotalTraces, - TopN: {}, - Metadata: src.TraceDetails, - SampleRate: src.SampleRate, - }; - Object.keys(src.TopNTraces).map((key) => { - obj.TopN[key] = src.TopNTraces[key].map((item) => { - return { Value: item.TraceHash, Count: item.Count }; - }); - }); - return obj; -} - -export function registerTraceEventsTopNStackTracesRoute( - router: IRouter -) { - const paths = getLocalRoutePaths(); - router.get( - { - path: paths.TopNTraces, - validate: { - query: schema.object({ - index: schema.maybe(schema.string()), - projectID: schema.maybe(schema.string()), - timeFrom: schema.maybe(schema.string()), - timeTo: schema.maybe(schema.string()), - }), - }, - }, - async (ctx, request, response) => { - const [timeFrom, timeTo] = timeRangeFromRequest(request); - const src = await import(`../fixtures/traces_${timeTo - timeFrom}`); - delete src.default; - return response.ok({ body: transformFlamechart(src) }); - } - ); -} diff --git a/src/plugins/profiling/server/routes/load_topNThreads.ts b/src/plugins/profiling/server/routes/load_topNThreads.ts deleted file mode 100644 index 7a34dc9b1afc77..00000000000000 --- a/src/plugins/profiling/server/routes/load_topNThreads.ts +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -import { schema } from '@kbn/config-schema'; -import type { DataRequestHandlerContext } from '../../../data/server'; -import type { IRouter } from '../../../../core/server'; -import { getLocalRoutePaths, timeRangeFromRequest } from '../../common'; - -export function registerTraceEventsTopNThreadsRoute(router: IRouter) { - const paths = getLocalRoutePaths(); - router.get( - { - path: paths.TopNThreads, - validate: { - query: schema.object({ - index: schema.maybe(schema.string()), - projectID: schema.maybe(schema.string()), - timeFrom: schema.maybe(schema.string()), - timeTo: schema.maybe(schema.string()), - }), - }, - }, - async (ctx, request, response) => { - const [timeFrom, timeTo] = timeRangeFromRequest(request); - const src = await import(`../fixtures/threads_${timeTo - timeFrom}`); - delete src.default; - return response.ok({ body: src }); - } - ); -} diff --git a/src/plugins/profiling/server/routes/load_topn.ts b/src/plugins/profiling/server/routes/load_topn.ts new file mode 100644 index 00000000000000..aa5d137351aa7d --- /dev/null +++ b/src/plugins/profiling/server/routes/load_topn.ts @@ -0,0 +1,145 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ +import { schema } from '@kbn/config-schema'; +import type { IRouter } from 'kibana/server'; +import type { DataRequestHandlerContext } from '../../../data/server'; +import { getLocalRoutePaths, timeRangeFromRequest } from '../../common'; + +export function registerTraceEventsTopNContainersRoute(router: IRouter) { + const paths = getLocalRoutePaths(); + router.get( + { + path: paths.TopNContainers, + validate: { + query: schema.object({ + index: schema.maybe(schema.string()), + projectID: schema.maybe(schema.string()), + timeFrom: schema.maybe(schema.string()), + timeTo: schema.maybe(schema.string()), + }), + }, + }, + async (ctx, request, response) => { + const [timeFrom, timeTo] = timeRangeFromRequest(request); + const src = await import(`../fixtures/containers_${timeTo - timeFrom}`); + delete src.default; + return response.ok({ body: src }); + } + ); +} + +export function registerTraceEventsTopNDeploymentsRoute( + router: IRouter +) { + const paths = getLocalRoutePaths(); + router.get( + { + path: paths.TopNDeployments, + validate: { + query: schema.object({ + index: schema.maybe(schema.string()), + projectID: schema.maybe(schema.string()), + timeFrom: schema.maybe(schema.string()), + timeTo: schema.maybe(schema.string()), + }), + }, + }, + async (ctx, request, response) => { + const [timeFrom, timeTo] = timeRangeFromRequest(request); + const src = await import(`../fixtures/pods_${timeTo - timeFrom}`); + delete src.default; + return response.ok({ body: src }); + } + ); +} + +export function registerTraceEventsTopNHostsRoute(router: IRouter) { + const paths = getLocalRoutePaths(); + router.get( + { + path: paths.TopNHosts, + validate: { + query: schema.object({ + index: schema.maybe(schema.string()), + projectID: schema.maybe(schema.string()), + timeFrom: schema.maybe(schema.string()), + timeTo: schema.maybe(schema.string()), + }), + }, + }, + async (ctx, request, response) => { + const [timeFrom, timeTo] = timeRangeFromRequest(request); + const src = await import(`../fixtures/hosts_${timeTo - timeFrom}`); + delete src.default; + return response.ok({ body: src }); + } + ); +} + +export function registerTraceEventsTopNStackTracesRoute( + router: IRouter +) { + const paths = getLocalRoutePaths(); + router.get( + { + path: paths.TopNTraces, + validate: { + query: schema.object({ + index: schema.maybe(schema.string()), + projectID: schema.maybe(schema.string()), + timeFrom: schema.maybe(schema.string()), + timeTo: schema.maybe(schema.string()), + }), + }, + }, + async (ctx, request, response) => { + const [timeFrom, timeTo] = timeRangeFromRequest(request); + const src = await import(`../fixtures/traces_${timeTo - timeFrom}`); + delete src.default; + return response.ok({ body: transformFlamechart(src) }); + } + ); +} + +export function registerTraceEventsTopNThreadsRoute(router: IRouter) { + const paths = getLocalRoutePaths(); + router.get( + { + path: paths.TopNThreads, + validate: { + query: schema.object({ + index: schema.maybe(schema.string()), + projectID: schema.maybe(schema.string()), + timeFrom: schema.maybe(schema.string()), + timeTo: schema.maybe(schema.string()), + }), + }, + }, + async (ctx, request, response) => { + const [timeFrom, timeTo] = timeRangeFromRequest(request); + const src = await import(`../fixtures/threads_${timeTo - timeFrom}`); + delete src.default; + return response.ok({ body: src }); + } + ); +} + +function transformFlamechart(src) { + const obj = { + Total: src.TotalTraces, + TopN: {}, + Metadata: src.TraceDetails, + SampleRate: src.SampleRate, + }; + Object.keys(src.TopNTraces).map((key) => { + obj.TopN[key] = src.TopNTraces[key].map((item) => { + return { Value: item.TraceHash, Count: item.Count }; + }); + }); + return obj; +} diff --git a/src/plugins/profiling/server/routes/register_routes.ts b/src/plugins/profiling/server/routes/register_routes.ts deleted file mode 100644 index 5b41d49ba1db18..00000000000000 --- a/src/plugins/profiling/server/routes/register_routes.ts +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -import type { IRouter } from '../../../../core/server'; -import { DataRequestHandlerContext } from '../../../data/server'; - -import { registerFlameChartElasticRoute } from './load_flameChartElastic'; -import { registerFlameChartPixiRoute } from './load_flameChartPixi'; -import { registerTraceEventsTopNContainersRoute } from './load_topNContainers'; -import { registerTraceEventsTopNDeploymentsRoute } from './load_topNDeployments'; -import { registerTraceEventsTopNHostsRoute } from './load_topNHosts'; -import { registerTraceEventsTopNStackTracesRoute } from './load_topNStackTraces'; -import { registerTraceEventsTopNThreadsRoute } from './load_topNThreads'; - -import { registerFlameChartSearchRoute } from './search_flameChart'; -import { registerTraceEventsTopNContainersSearchRoute } from './search_topNContainers'; -import { registerTraceEventsTopNDeploymentsSearchRoute } from './search_topNDeployments'; -import { registerTraceEventsTopNHostsSearchRoute } from './search_topNHosts'; -import { registerTraceEventsTopNStackTracesSearchRoute } from './search_topNStackTraces'; -import { registerTraceEventsTopNThreadsSearchRoute } from './search_topNThreads'; - -export function registerRoutes(router: IRouter) { - registerFlameChartElasticRoute(router); - registerFlameChartPixiRoute(router); - registerTraceEventsTopNContainersRoute(router); - registerTraceEventsTopNDeploymentsRoute(router); - registerTraceEventsTopNHostsRoute(router); - registerTraceEventsTopNStackTracesRoute(router); - registerTraceEventsTopNThreadsRoute(router); - - registerFlameChartSearchRoute(router); - registerTraceEventsTopNContainersSearchRoute(router); - registerTraceEventsTopNDeploymentsSearchRoute(router); - registerTraceEventsTopNHostsSearchRoute(router); - registerTraceEventsTopNStackTracesSearchRoute(router); - registerTraceEventsTopNThreadsSearchRoute(router); -} diff --git a/src/plugins/profiling/server/routes/search_flameChart.ts b/src/plugins/profiling/server/routes/search_flamechart.ts similarity index 98% rename from src/plugins/profiling/server/routes/search_flameChart.ts rename to src/plugins/profiling/server/routes/search_flamechart.ts index 31fc23173fcaf2..181bb047d4c98f 100644 --- a/src/plugins/profiling/server/routes/search_flameChart.ts +++ b/src/plugins/profiling/server/routes/search_flamechart.ts @@ -6,8 +6,8 @@ * Side Public License, v 1. */ import { schema } from '@kbn/config-schema'; +import type { IRouter } from 'kibana/server'; import type { DataRequestHandlerContext } from '../../../data/server'; -import type { IRouter } from '../../../../core/server'; import { getRemoteRoutePaths } from '../../common'; import { FlameGraph } from './flamegraph'; @@ -145,6 +145,7 @@ export function registerFlameChartSearchRoute(router: IRouter -) { - const paths = getRemoteRoutePaths(); - return queryTopNCommon(router, paths.TopNContainers, 'ContainerName'); -} diff --git a/src/plugins/profiling/server/routes/search_topNDeployments.ts b/src/plugins/profiling/server/routes/search_topNDeployments.ts deleted file mode 100644 index 7319daa680b607..00000000000000 --- a/src/plugins/profiling/server/routes/search_topNDeployments.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -import type { DataRequestHandlerContext } from '../../../data/server'; -import type { IRouter } from '../../../../core/server'; -import { getRemoteRoutePaths } from '../../common'; -import { queryTopNCommon } from './search_topN'; - -export function registerTraceEventsTopNDeploymentsSearchRoute( - router: IRouter -) { - const paths = getRemoteRoutePaths(); - return queryTopNCommon(router, paths.TopNDeployments, 'PodName'); -} diff --git a/src/plugins/profiling/server/routes/search_topNHosts.ts b/src/plugins/profiling/server/routes/search_topNHosts.ts deleted file mode 100644 index 00264ec8ddbabe..00000000000000 --- a/src/plugins/profiling/server/routes/search_topNHosts.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -import type { DataRequestHandlerContext } from '../../../data/server'; -import type { IRouter } from '../../../../core/server'; -import { getRemoteRoutePaths } from '../../common'; -import { queryTopNCommon } from './search_topN'; - -export function registerTraceEventsTopNHostsSearchRoute( - router: IRouter -) { - const paths = getRemoteRoutePaths(); - return queryTopNCommon(router, paths.TopNHosts, 'HostID'); -} diff --git a/src/plugins/profiling/server/routes/search_topNStackTraces.ts b/src/plugins/profiling/server/routes/search_topNStackTraces.ts deleted file mode 100644 index 30ca2e97279711..00000000000000 --- a/src/plugins/profiling/server/routes/search_topNStackTraces.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -import type { DataRequestHandlerContext } from '../../../data/server'; -import type { IRouter } from '../../../../core/server'; -import { getRemoteRoutePaths } from '../../common'; -import { queryTopNCommon } from './search_topN'; - -export function registerTraceEventsTopNStackTracesSearchRoute( - router: IRouter -) { - const paths = getRemoteRoutePaths(); - return queryTopNCommon(router, paths.TopNTraces, 'StackTraceID'); -} diff --git a/src/plugins/profiling/server/routes/search_topNThreads.ts b/src/plugins/profiling/server/routes/search_topNThreads.ts deleted file mode 100644 index 4318da47af2201..00000000000000 --- a/src/plugins/profiling/server/routes/search_topNThreads.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -import type { DataRequestHandlerContext } from '../../../data/server'; -import type { IRouter } from '../../../../core/server'; -import { getRemoteRoutePaths } from '../../common'; -import { queryTopNCommon } from './search_topN'; - -export function registerTraceEventsTopNThreadsSearchRoute( - router: IRouter -) { - const paths = getRemoteRoutePaths(); - return queryTopNCommon(router, paths.TopNThreads, 'ThreadName'); -} diff --git a/src/plugins/profiling/server/routes/search_topN.ts b/src/plugins/profiling/server/routes/search_topn.ts similarity index 78% rename from src/plugins/profiling/server/routes/search_topN.ts rename to src/plugins/profiling/server/routes/search_topn.ts index 7ce4271c71f05b..9d4108a5a788ab 100644 --- a/src/plugins/profiling/server/routes/search_topN.ts +++ b/src/plugins/profiling/server/routes/search_topn.ts @@ -6,10 +6,11 @@ * Side Public License, v 1. */ import { schema } from '@kbn/config-schema'; +import type { IRouter } from 'kibana/server'; import { IEsSearchRequest } from '../../../data/server'; import { IEsSearchResponse } from '../../../data/common'; import type { DataRequestHandlerContext } from '../../../data/server'; -import type { IRouter } from '../../../../core/server'; +import { getRemoteRoutePaths } from '../../common'; export function queryTopNCommon( router: IRouter, @@ -134,3 +135,38 @@ export function queryTopNCommon( } ); } + +export function registerTraceEventsTopNContainersSearchRoute( + router: IRouter +) { + const paths = getRemoteRoutePaths(); + return queryTopNCommon(router, paths.TopNContainers, 'ContainerName'); +} + +export function registerTraceEventsTopNDeploymentsSearchRoute( + router: IRouter +) { + const paths = getRemoteRoutePaths(); + return queryTopNCommon(router, paths.TopNDeployments, 'PodName'); +} + +export function registerTraceEventsTopNHostsSearchRoute( + router: IRouter +) { + const paths = getRemoteRoutePaths(); + return queryTopNCommon(router, paths.TopNHosts, 'HostID'); +} + +export function registerTraceEventsTopNStackTracesSearchRoute( + router: IRouter +) { + const paths = getRemoteRoutePaths(); + return queryTopNCommon(router, paths.TopNTraces, 'StackTraceID'); +} + +export function registerTraceEventsTopNThreadsSearchRoute( + router: IRouter +) { + const paths = getRemoteRoutePaths(); + return queryTopNCommon(router, paths.TopNThreads, 'ThreadName'); +}