Skip to content

Commit 9a92fae

Browse files
committed
addressing PR comments
1 parent cca31e9 commit 9a92fae

File tree

6 files changed

+56
-32
lines changed

6 files changed

+56
-32
lines changed

x-pack/plugins/apm/public/plugin.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ import { setHelpExtension } from './setHelpExtension';
3838
import { toggleAppLinkInNav } from './toggleAppLinkInNav';
3939
import { setReadonlyBadge } from './updateBadge';
4040
import { createStaticIndexPattern } from './services/rest/index_pattern';
41-
import { fetchData, hasData } from './services/rest/observability_dashboard';
41+
import {
42+
fetchLandingPageData,
43+
hasData,
44+
} from './services/rest/observability_dashboard';
4245

4346
export type ApmPluginSetup = void;
4447
export type ApmPluginStart = void;
@@ -75,9 +78,12 @@ export class ApmPlugin implements Plugin<ApmPluginSetup, ApmPluginStart> {
7578
pluginSetupDeps.home.featureCatalogue.register(featureCatalogueEntry);
7679

7780
if (plugins.observability) {
81+
const isDarkMode = core.uiSettings.get('theme:darkMode');
7882
plugins.observability.dashboard.register({
7983
appName: 'apm',
80-
fetchData,
84+
fetchData: async (params) => {
85+
return fetchLandingPageData(params, { isDarkMode });
86+
},
8187
hasData,
8288
});
8389
}

x-pack/plugins/apm/public/services/rest/observability.dashboard.test.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { fetchData, hasData } from './observability_dashboard';
7+
import { fetchLandingPageData, hasData } from './observability_dashboard';
88
import * as createCallApmApi from './createCallApmApi';
99

1010
describe('Observability dashboard data', () => {
@@ -25,7 +25,7 @@ describe('Observability dashboard data', () => {
2525
});
2626
});
2727

28-
describe('fetchData', () => {
28+
describe('fetchLandingPageData', () => {
2929
it('returns APM data with series and stats', async () => {
3030
callApmApiMock.mockImplementation(() =>
3131
Promise.resolve({
@@ -37,11 +37,14 @@ describe('Observability dashboard data', () => {
3737
],
3838
})
3939
);
40-
const response = await fetchData({
41-
startTime: '1',
42-
endTime: '2',
43-
bucketSize: '3',
44-
});
40+
const response = await fetchLandingPageData(
41+
{
42+
startTime: '1',
43+
endTime: '2',
44+
bucketSize: '3',
45+
},
46+
{ isDarkMode: false }
47+
);
4548
expect(response).toEqual({
4649
title: 'APM',
4750
appLink: '/app/apm',
@@ -53,6 +56,7 @@ describe('Observability dashboard data', () => {
5356
transactions: {
5457
label: 'Transactions',
5558
value: 6,
59+
color: '#6092c0',
5660
},
5761
},
5862
series: {
@@ -63,7 +67,7 @@ describe('Observability dashboard data', () => {
6367
{ x: 2, y: 2 },
6468
{ x: 3, y: 3 },
6569
],
66-
color: 'euiColorVis1',
70+
color: '#6092c0',
6771
},
6872
},
6973
});
@@ -75,11 +79,14 @@ describe('Observability dashboard data', () => {
7579
transactionCoordinates: [],
7680
})
7781
);
78-
const response = await fetchData({
79-
startTime: '1',
80-
endTime: '2',
81-
bucketSize: '3',
82-
});
82+
const response = await fetchLandingPageData(
83+
{
84+
startTime: '1',
85+
endTime: '2',
86+
bucketSize: '3',
87+
},
88+
{ isDarkMode: false }
89+
);
8390
expect(response).toEqual({
8491
title: 'APM',
8592
appLink: '/app/apm',
@@ -91,13 +98,14 @@ describe('Observability dashboard data', () => {
9198
transactions: {
9299
label: 'Transactions',
93100
value: 0,
101+
color: '#6092c0',
94102
},
95103
},
96104
series: {
97105
transactions: {
98106
label: 'Transactions',
99107
coordinates: [],
100-
color: 'euiColorVis1',
108+
color: '#6092c0',
101109
},
102110
},
103111
});

x-pack/plugins/apm/public/services/rest/observability_dashboard.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,25 @@
66

77
import { i18n } from '@kbn/i18n';
88
import { sum } from 'lodash';
9+
import lightTheme from '@elastic/eui/dist/eui_theme_light.json';
10+
import darkTheme from '@elastic/eui/dist/eui_theme_dark.json';
911
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
10-
import { FetchData } from '../../../../observability/public/data_handler';
12+
import { FetchDataParams } from '../../../../observability/public/data_handler';
1113
import { ApmFetchDataResponse } from '../../../../observability/public/typings/fetch_data_response';
1214
import { callApmApi } from './createCallApmApi';
1315

14-
export const fetchData: FetchData<ApmFetchDataResponse> = async ({
15-
startTime,
16-
endTime,
17-
bucketSize,
18-
}) => {
16+
interface Options {
17+
isDarkMode: boolean;
18+
}
19+
20+
export const fetchLandingPageData = async (
21+
{ startTime, endTime, bucketSize }: FetchDataParams,
22+
{ isDarkMode }: Options
23+
): Promise<ApmFetchDataResponse> => {
24+
const theme = isDarkMode ? darkTheme : lightTheme;
25+
1926
const data = await callApmApi({
20-
pathname: '/api/apm/observability-dashboard',
27+
pathname: '/api/apm/observability_dashboard',
2128
params: { query: { start: startTime, end: endTime, bucketSize } },
2229
});
2330

@@ -42,6 +49,7 @@ export const fetchData: FetchData<ApmFetchDataResponse> = async ({
4249
{ defaultMessage: 'Transactions' }
4350
),
4451
value: sum(transactionCoordinates.map((coordinates) => coordinates.y)),
52+
color: theme.euiColorVis1,
4553
},
4654
},
4755
series: {
@@ -50,7 +58,7 @@ export const fetchData: FetchData<ApmFetchDataResponse> = async ({
5058
'xpack.apm.observabilityDashboard.chart.transactions',
5159
{ defaultMessage: 'Transactions' }
5260
),
53-
color: 'euiColorVis1',
61+
color: theme.euiColorVis1,
5462
coordinates: transactionCoordinates,
5563
},
5664
},
@@ -59,6 +67,6 @@ export const fetchData: FetchData<ApmFetchDataResponse> = async ({
5967

6068
export async function hasData() {
6169
return await callApmApi({
62-
pathname: '/api/apm/observability-dashboard/hasData',
70+
pathname: '/api/apm/observability_dashboard/has_data',
6371
});
6472
}

x-pack/plugins/apm/server/lib/observability_dashboard/has_data.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export async function hasData({ setup }: { setup: Setup }) {
1313
indices['apm_oss.transactionIndices'],
1414
indices['apm_oss.errorIndices'],
1515
indices['apm_oss.metricsIndices'],
16-
indices['apm_oss.spanIndices'],
1716
],
1817
terminateAfter: 1,
1918
size: 0,

x-pack/plugins/apm/server/routes/observability_dashboard.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,30 @@ import { getServiceCount } from '../lib/observability_dashboard/get_service_coun
1212
import { getTransactionCoordinates } from '../lib/observability_dashboard/get_transaction_coordinates';
1313

1414
export const observabilityDashboardHasDataRoute = createRoute(() => ({
15-
path: '/api/apm/observability-dashboard/hasData',
15+
path: '/api/apm/observability_dashboard/has_data',
1616
handler: async ({ context, request }) => {
1717
const setup = await setupRequest(context, request);
1818
return await hasData({ setup });
1919
},
2020
}));
2121

2222
export const observabilityDashboardDataRoute = createRoute(() => ({
23-
path: '/api/apm/observability-dashboard',
23+
path: '/api/apm/observability_dashboard',
2424
params: {
2525
query: t.intersection([rangeRt, t.type({ bucketSize: t.string })]),
2626
},
2727
handler: async ({ context, request }) => {
2828
const setup = await setupRequest(context, request);
2929
const { bucketSize } = context.params.query;
30-
const serviceCount = await getServiceCount({ setup });
31-
const transactionCoordinates = await getTransactionCoordinates({
30+
const serviceCountPromise = getServiceCount({ setup });
31+
const transactionCoordinatesPromise = getTransactionCoordinates({
3232
setup,
3333
bucketSize,
3434
});
35-
35+
const [serviceCount, transactionCoordinates] = await Promise.all([
36+
serviceCountPromise,
37+
transactionCoordinatesPromise,
38+
]);
3639
return { serviceCount, transactionCoordinates };
3740
},
3841
}));

x-pack/plugins/observability/public/data_handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { ObservabilityFetchDataResponse, FetchDataResponse } from './typings/fetch_data_response';
88
import { ObservabilityApp } from '../typings/common';
99

10-
interface FetchDataParams {
10+
export interface FetchDataParams {
1111
// The start timestamp in milliseconds of the queried time interval
1212
startTime: string;
1313
// The end timestamp in milliseconds of the queried time interval

0 commit comments

Comments
 (0)