Skip to content

Commit 3374b2d

Browse files
[Observability] Change appLink passing the date range (#71259)
* changing apm appLink * changing apm appLink * removing title from api * adding absolute and relative times * addressing pr comments * addressing pr comments * addressing pr comments * fixing TS issues * addressing pr comments Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent 831e427 commit 3374b2d

File tree

30 files changed

+255
-221
lines changed

30 files changed

+255
-221
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ import { toggleAppLinkInNav } from './toggleAppLinkInNav';
3939
import { setReadonlyBadge } from './updateBadge';
4040
import { createStaticIndexPattern } from './services/rest/index_pattern';
4141
import {
42-
fetchLandingPageData,
42+
fetchOverviewPageData,
4343
hasData,
44-
} from './services/rest/observability_dashboard';
44+
} from './services/rest/apm_overview_fetchers';
4545

4646
export type ApmPluginSetup = void;
4747
export type ApmPluginStart = void;
@@ -81,9 +81,7 @@ export class ApmPlugin implements Plugin<ApmPluginSetup, ApmPluginStart> {
8181
if (plugins.observability) {
8282
plugins.observability.dashboard.register({
8383
appName: 'apm',
84-
fetchData: async (params) => {
85-
return fetchLandingPageData(params);
86-
},
84+
fetchData: fetchOverviewPageData,
8785
hasData,
8886
});
8987
}

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

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

7-
import { fetchLandingPageData, hasData } from './observability_dashboard';
7+
import moment from 'moment';
8+
import { fetchOverviewPageData, hasData } from './apm_overview_fetchers';
89
import * as createCallApmApi from './createCallApmApi';
910

1011
describe('Observability dashboard data', () => {
1112
const callApmApiMock = jest.spyOn(createCallApmApi, 'callApmApi');
13+
const params = {
14+
absoluteTime: {
15+
start: moment('2020-07-02T13:25:11.629Z').valueOf(),
16+
end: moment('2020-07-09T14:25:11.629Z').valueOf(),
17+
},
18+
relativeTime: {
19+
start: 'now-15m',
20+
end: 'now',
21+
},
22+
bucketSize: '600s',
23+
};
1224
afterEach(() => {
1325
callApmApiMock.mockClear();
1426
});
@@ -25,7 +37,7 @@ describe('Observability dashboard data', () => {
2537
});
2638
});
2739

28-
describe('fetchLandingPageData', () => {
40+
describe('fetchOverviewPageData', () => {
2941
it('returns APM data with series and stats', async () => {
3042
callApmApiMock.mockImplementation(() =>
3143
Promise.resolve({
@@ -37,14 +49,9 @@ describe('Observability dashboard data', () => {
3749
],
3850
})
3951
);
40-
const response = await fetchLandingPageData({
41-
startTime: '1',
42-
endTime: '2',
43-
bucketSize: '3',
44-
});
52+
const response = await fetchOverviewPageData(params);
4553
expect(response).toEqual({
46-
title: 'APM',
47-
appLink: '/app/apm',
54+
appLink: '/app/apm#/services?rangeFrom=now-15m&rangeTo=now',
4855
stats: {
4956
services: {
5057
type: 'number',
@@ -73,14 +80,9 @@ describe('Observability dashboard data', () => {
7380
transactionCoordinates: [],
7481
})
7582
);
76-
const response = await fetchLandingPageData({
77-
startTime: '1',
78-
endTime: '2',
79-
bucketSize: '3',
80-
});
83+
const response = await fetchOverviewPageData(params);
8184
expect(response).toEqual({
82-
title: 'APM',
83-
appLink: '/app/apm',
85+
appLink: '/app/apm#/services?rangeFrom=now-15m&rangeTo=now',
8486
stats: {
8587
services: {
8688
type: 'number',
@@ -105,14 +107,9 @@ describe('Observability dashboard data', () => {
105107
transactionCoordinates: [{ x: 1 }, { x: 2 }, { x: 3 }],
106108
})
107109
);
108-
const response = await fetchLandingPageData({
109-
startTime: '1',
110-
endTime: '2',
111-
bucketSize: '3',
112-
});
110+
const response = await fetchOverviewPageData(params);
113111
expect(response).toEqual({
114-
title: 'APM',
115-
appLink: '/app/apm',
112+
appLink: '/app/apm#/services?rangeFrom=now-15m&rangeTo=now',
116113
stats: {
117114
services: {
118115
type: 'number',

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

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

7-
import { i18n } from '@kbn/i18n';
87
import { mean } from 'lodash';
98
import {
109
ApmFetchDataResponse,
1110
FetchDataParams,
1211
} from '../../../../observability/public';
1312
import { callApmApi } from './createCallApmApi';
1413

15-
export const fetchLandingPageData = async ({
16-
startTime,
17-
endTime,
14+
export const fetchOverviewPageData = async ({
15+
absoluteTime,
16+
relativeTime,
1817
bucketSize,
1918
}: FetchDataParams): Promise<ApmFetchDataResponse> => {
2019
const data = await callApmApi({
21-
pathname: '/api/apm/observability_dashboard',
22-
params: { query: { start: startTime, end: endTime, bucketSize } },
20+
pathname: '/api/apm/observability_overview',
21+
params: {
22+
query: {
23+
start: new Date(absoluteTime.start).toISOString(),
24+
end: new Date(absoluteTime.end).toISOString(),
25+
bucketSize,
26+
},
27+
},
2328
});
2429

2530
const { serviceCount, transactionCoordinates } = data;
2631

2732
return {
28-
title: i18n.translate('xpack.apm.observabilityDashboard.title', {
29-
defaultMessage: 'APM',
30-
}),
31-
appLink: '/app/apm',
33+
appLink: `/app/apm#/services?rangeFrom=${relativeTime.start}&rangeTo=${relativeTime.end}`,
3234
stats: {
3335
services: {
3436
type: 'number',
@@ -54,6 +56,6 @@ export const fetchLandingPageData = async ({
5456

5557
export async function hasData() {
5658
return await callApmApi({
57-
pathname: '/api/apm/observability_dashboard/has_data',
59+
pathname: '/api/apm/observability_overview/has_data',
5860
});
5961
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ import {
7979
rumServicesRoute,
8080
} from './rum_client';
8181
import {
82-
observabilityDashboardHasDataRoute,
83-
observabilityDashboardDataRoute,
84-
} from './observability_dashboard';
82+
observabilityOverviewHasDataRoute,
83+
observabilityOverviewRoute,
84+
} from './observability_overview';
8585
import {
8686
anomalyDetectionJobsRoute,
8787
createAnomalyDetectionJobsRoute,
@@ -176,8 +176,8 @@ const createApmApi = () => {
176176
.add(rumServicesRoute)
177177

178178
// Observability dashboard
179-
.add(observabilityDashboardHasDataRoute)
180-
.add(observabilityDashboardDataRoute)
179+
.add(observabilityOverviewHasDataRoute)
180+
.add(observabilityOverviewRoute)
181181

182182
// Anomaly detection
183183
.add(anomalyDetectionJobsRoute)

x-pack/plugins/apm/server/routes/observability_dashboard.ts renamed to x-pack/plugins/apm/server/routes/observability_overview.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55
*/
66
import * as t from 'io-ts';
77
import { setupRequest } from '../lib/helpers/setup_request';
8-
import { hasData } from '../lib/observability_dashboard/has_data';
8+
import { getServiceCount } from '../lib/observability_overview/get_service_count';
9+
import { getTransactionCoordinates } from '../lib/observability_overview/get_transaction_coordinates';
10+
import { hasData } from '../lib/observability_overview/has_data';
911
import { createRoute } from './create_route';
1012
import { rangeRt } from './default_api_types';
11-
import { getServiceCount } from '../lib/observability_dashboard/get_service_count';
12-
import { getTransactionCoordinates } from '../lib/observability_dashboard/get_transaction_coordinates';
1313

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

22-
export const observabilityDashboardDataRoute = createRoute(() => ({
23-
path: '/api/apm/observability_dashboard',
22+
export const observabilityOverviewRoute = createRoute(() => ({
23+
path: '/api/apm/observability_overview',
2424
params: {
2525
query: t.intersection([rangeRt, t.type({ bucketSize: t.string })]),
2626
},

x-pack/plugins/infra/public/__snapshots__/metrics_overview_fetchers.test.ts.snap

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugins/infra/public/metrics_overview_fetchers.test.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,18 @@ describe('Metrics UI Observability Homepage Functions', () => {
5353
const { core, mockedGetStartServices } = setup();
5454
core.http.post.mockResolvedValue(FAKE_SNAPSHOT_RESPONSE);
5555
const fetchData = createMetricsFetchData(mockedGetStartServices);
56-
const endTime = moment();
56+
const endTime = moment('2020-07-02T13:25:11.629Z');
5757
const startTime = endTime.clone().subtract(1, 'h');
5858
const bucketSize = '300s';
5959
const response = await fetchData({
60-
startTime: startTime.toISOString(),
61-
endTime: endTime.toISOString(),
60+
absoluteTime: {
61+
start: startTime.valueOf(),
62+
end: endTime.valueOf(),
63+
},
64+
relativeTime: {
65+
start: 'now-15m',
66+
end: 'now',
67+
},
6268
bucketSize,
6369
});
6470
expect(core.http.post).toHaveBeenCalledTimes(1);

0 commit comments

Comments
 (0)