Skip to content

Commit

Permalink
Add testing config and lint errors (#10)
Browse files Browse the repository at this point in the history
* 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 <francesco.gualazzi@elastic.co>
  • Loading branch information
inge4pres authored and rockdaboot committed Jul 4, 2022
1 parent 32f6687 commit 489db27
Show file tree
Hide file tree
Showing 20 changed files with 284 additions and 361 deletions.
21 changes: 21 additions & 0 deletions src/plugins/profiling/common/index.test.ts
Original file line number Diff line number Diff line change
@@ -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]);
});
});
5 changes: 2 additions & 3 deletions src/plugins/profiling/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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`,
};
}

Expand All @@ -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`,
};
}

Expand Down
16 changes: 16 additions & 0 deletions src/plugins/profiling/jest.config.js
Original file line number Diff line number Diff line change
@@ -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: ['<rootDir>/src/plugins/profiling'],
coverageDirectory: '<rootDir>/target/kibana-coverage/jest/src/plugins/profiling',
coverageReporters: ['text', 'html'],
collectCoverageFrom: ['<rootDir>/src/plugins/profiling/{common,public,server}/**/*.{ts,tsx}'],
};
37 changes: 36 additions & 1 deletion src/plugins/profiling/server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataRequestHandlerContext>) {
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);
}
34 changes: 0 additions & 34 deletions src/plugins/profiling/server/routes/load_flameChartPixi.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -33,3 +33,26 @@ export function registerFlameChartElasticRoute(router: IRouter<DataRequestHandle
}
);
}

export function registerFlameChartPixiRoute(router: IRouter<DataRequestHandlerContext>) {
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 });
}
);
}
34 changes: 0 additions & 34 deletions src/plugins/profiling/server/routes/load_topNContainers.ts

This file was deleted.

36 changes: 0 additions & 36 deletions src/plugins/profiling/server/routes/load_topNDeployments.ts

This file was deleted.

34 changes: 0 additions & 34 deletions src/plugins/profiling/server/routes/load_topNHosts.ts

This file was deleted.

51 changes: 0 additions & 51 deletions src/plugins/profiling/server/routes/load_topNStackTraces.ts

This file was deleted.

34 changes: 0 additions & 34 deletions src/plugins/profiling/server/routes/load_topNThreads.ts

This file was deleted.

Loading

0 comments on commit 489db27

Please sign in to comment.