Skip to content

Commit cf09181

Browse files
ogupteAPM User
authored andcommitted
[APM] fixes linking errors to ML and Discover (#73758)
* Closes #73755 by removing the extra uri encoding from time ranges and using correct refreshValue rison types rather than just strings * removes commented out test assertion
1 parent c55e81f commit cf09181

File tree

8 files changed

+85
-23
lines changed

8 files changed

+85
-23
lines changed

x-pack/plugins/apm/public/components/shared/Links/DiscoverLinks/__test__/DiscoverLinks.integration.test.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ describe('DiscoverLinks', () => {
3333
} as Location
3434
);
3535

36-
expect(href).toEqual(
37-
`/basepath/app/discover#/?_g=(refreshInterval:(pause:true,value:'0'),time:(from:now%2Fw,to:now))&_a=(index:apm_static_index_pattern_id,interval:auto,query:(language:kuery,query:'processor.event:"transaction" AND transaction.id:"8b60bd32ecc6e150" AND trace.id:"8b60bd32ecc6e1506735a8b6cfcf175c"'))`
36+
expect(href).toMatchInlineSnapshot(
37+
`"/basepath/app/discover#/?_g=(refreshInterval:(pause:!t,value:0),time:(from:now/w,to:now))&_a=(index:apm_static_index_pattern_id,interval:auto,query:(language:kuery,query:'processor.event:\\"transaction\\" AND transaction.id:\\"8b60bd32ecc6e150\\" AND trace.id:\\"8b60bd32ecc6e1506735a8b6cfcf175c\\"'))"`
3838
);
3939
});
4040

@@ -50,8 +50,8 @@ describe('DiscoverLinks', () => {
5050
'?rangeFrom=now/w&rangeTo=now&refreshPaused=true&refreshInterval=0',
5151
} as Location);
5252

53-
expect(href).toEqual(
54-
`/basepath/app/discover#/?_g=(refreshInterval:(pause:true,value:'0'),time:(from:now%2Fw,to:now))&_a=(index:apm_static_index_pattern_id,interval:auto,query:(language:kuery,query:'span.id:"test-span-id"'))`
53+
expect(href).toMatchInlineSnapshot(
54+
`"/basepath/app/discover#/?_g=(refreshInterval:(pause:!t,value:0),time:(from:now/w,to:now))&_a=(index:apm_static_index_pattern_id,interval:auto,query:(language:kuery,query:'span.id:\\"test-span-id\\"'))"`
5555
);
5656
});
5757

@@ -72,8 +72,8 @@ describe('DiscoverLinks', () => {
7272
} as Location
7373
);
7474

75-
expect(href).toEqual(
76-
`/basepath/app/discover#/?_g=(refreshInterval:(pause:true,value:'0'),time:(from:now%2Fw,to:now))&_a=(index:apm_static_index_pattern_id,interval:auto,query:(language:kuery,query:'service.name:"service-name" AND error.grouping_key:"grouping-key"'),sort:('@timestamp':desc))`
75+
expect(href).toMatchInlineSnapshot(
76+
`"/basepath/app/discover#/?_g=(refreshInterval:(pause:!t,value:0),time:(from:now/w,to:now))&_a=(index:apm_static_index_pattern_id,interval:auto,query:(language:kuery,query:'service.name:\\"service-name\\" AND error.grouping_key:\\"grouping-key\\"'),sort:('@timestamp':desc))"`
7777
);
7878
});
7979

@@ -95,8 +95,8 @@ describe('DiscoverLinks', () => {
9595
} as Location
9696
);
9797

98-
expect(href).toEqual(
99-
`/basepath/app/discover#/?_g=(refreshInterval:(pause:true,value:'0'),time:(from:now%2Fw,to:now))&_a=(index:apm_static_index_pattern_id,interval:auto,query:(language:kuery,query:'service.name:"service-name" AND error.grouping_key:"grouping-key" AND some:kuery-string'),sort:('@timestamp':desc))`
98+
expect(href).toMatchInlineSnapshot(
99+
`"/basepath/app/discover#/?_g=(refreshInterval:(pause:!t,value:0),time:(from:now/w,to:now))&_a=(index:apm_static_index_pattern_id,interval:auto,query:(language:kuery,query:'service.name:\\"service-name\\" AND error.grouping_key:\\"grouping-key\\" AND some:kuery-string'),sort:('@timestamp':desc))"`
100100
);
101101
});
102102
});

x-pack/plugins/apm/public/components/shared/Links/MachineLearningLinks/MLJobLink.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('MLJobLink', () => {
2222
);
2323

2424
expect(href).toMatchInlineSnapshot(
25-
`"/basepath/app/ml#/timeseriesexplorer?_g=(ml:(jobIds:!(myservicename-mytransactiontype-high_mean_response_time)),refreshInterval:(pause:true,value:'0'),time:(from:now%2Fw,to:now-4h))"`
25+
`"/basepath/app/ml#/timeseriesexplorer?_g=(ml:(jobIds:!(myservicename-mytransactiontype-high_mean_response_time)),refreshInterval:(pause:!t,value:0),time:(from:now/w,to:now-4h))"`
2626
);
2727
});
2828
it('should produce the correct URL with jobId, serviceName, and transactionType', async () => {
@@ -41,7 +41,7 @@ describe('MLJobLink', () => {
4141
);
4242

4343
expect(href).toMatchInlineSnapshot(
44-
`"/basepath/app/ml#/timeseriesexplorer?_g=(ml:(jobIds:!(myservicename-mytransactiontype-high_mean_response_time)),refreshInterval:(pause:true,value:'0'),time:(from:now%2Fw,to:now-4h))&_a=(mlTimeSeriesExplorer:(entities:(service.name:opbeans-test,transaction.type:request)))"`
44+
`"/basepath/app/ml#/timeseriesexplorer?_g=(ml:(jobIds:!(myservicename-mytransactiontype-high_mean_response_time)),refreshInterval:(pause:!t,value:0),time:(from:now/w,to:now-4h))&_a=(mlTimeSeriesExplorer:(entities:(service.name:opbeans-test,transaction.type:request),zoom:(from:now/w,to:now-4h)))"`
4545
);
4646
});
4747
});

x-pack/plugins/apm/public/components/shared/Links/MachineLearningLinks/MLLink.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ test('MLLink produces the correct URL', async () => {
2121
);
2222

2323
expect(href).toMatchInlineSnapshot(
24-
`"/basepath/app/ml#/some/path?_g=(ml:(jobIds:!(something)),refreshInterval:(pause:true,value:'0'),time:(from:now-5h,to:now-2h))"`
24+
`"/basepath/app/ml#/some/path?_g=(ml:(jobIds:!(something)),refreshInterval:(pause:!t,value:0),time:(from:now-5h,to:now-2h))"`
2525
);
2626
});
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { useTimeSeriesExplorerHref } from './useTimeSeriesExplorerHref';
8+
9+
jest.mock('../../../../hooks/useApmPluginContext', () => ({
10+
useApmPluginContext: () => ({
11+
core: { http: { basePath: { prepend: (url: string) => url } } },
12+
}),
13+
}));
14+
15+
jest.mock('../../../../hooks/useLocation', () => ({
16+
useLocation: () => ({
17+
search:
18+
'?rangeFrom=2020-07-29T17:27:29.000Z&rangeTo=2020-07-29T18:45:00.000Z&refreshInterval=10000&refreshPaused=true',
19+
}),
20+
}));
21+
22+
describe('useTimeSeriesExplorerHref', () => {
23+
it('correctly encodes time range values', async () => {
24+
const href = useTimeSeriesExplorerHref({
25+
jobId: 'apm-production-485b-high_mean_transaction_duration',
26+
serviceName: 'opbeans-java',
27+
transactionType: 'request',
28+
});
29+
30+
expect(href).toMatchInlineSnapshot(
31+
`"/app/ml#/timeseriesexplorer?_g=(ml:(jobIds:!(apm-production-485b-high_mean_transaction_duration)),refreshInterval:(pause:!t,value:10000),time:(from:'2020-07-29T17:27:29.000Z',to:'2020-07-29T18:45:00.000Z'))&_a=(mlTimeSeriesExplorer:(entities:(service.name:opbeans-java,transaction.type:request),zoom:(from:'2020-07-29T17:27:29.000Z',to:'2020-07-29T18:45:00.000Z')))"`
32+
);
33+
});
34+
});

x-pack/plugins/apm/public/components/shared/Links/MachineLearningLinks/useTimeSeriesExplorerHref.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ export function useTimeSeriesExplorerHref({
2222
}) {
2323
const { core } = useApmPluginContext();
2424
const location = useLocation();
25+
const { time, refreshInterval } = getTimepickerRisonData(location.search);
2526

2627
const search = querystring.stringify(
2728
{
2829
_g: rison.encode({
2930
ml: { jobIds: [jobId] },
30-
...getTimepickerRisonData(location.search),
31+
time,
32+
refreshInterval,
3133
}),
3234
...(serviceName && transactionType
3335
? {
@@ -37,6 +39,7 @@ export function useTimeSeriesExplorerHref({
3739
'service.name': serviceName,
3840
'transaction.type': transactionType,
3941
},
42+
zoom: time,
4043
},
4144
}),
4245
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { getTimepickerRisonData } from './rison_helpers';
8+
9+
describe('getTimepickerRisonData', () => {
10+
it('returns object of timepicker range and refresh interval values', async () => {
11+
const locationSearch = `?rangeFrom=2020-07-29T17:27:29.000Z&rangeTo=2020-07-29T18:45:00.000Z&refreshInterval=10000&refreshPaused=true`;
12+
const timepickerValues = getTimepickerRisonData(locationSearch);
13+
14+
expect(timepickerValues).toMatchInlineSnapshot(`
15+
Object {
16+
"refreshInterval": Object {
17+
"pause": true,
18+
"value": 10000,
19+
},
20+
"time": Object {
21+
"from": "2020-07-29T17:27:29.000Z",
22+
"to": "2020-07-29T18:45:00.000Z",
23+
},
24+
}
25+
`);
26+
});
27+
});

x-pack/plugins/apm/public/components/shared/Links/rison_helpers.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,16 @@ export function getTimepickerRisonData(currentSearch: Location['search']) {
2222
const currentQuery = toQuery(currentSearch);
2323
return {
2424
time: {
25-
from: currentQuery.rangeFrom
26-
? encodeURIComponent(currentQuery.rangeFrom)
27-
: '',
28-
to: currentQuery.rangeTo ? encodeURIComponent(currentQuery.rangeTo) : '',
25+
from: currentQuery.rangeFrom || '',
26+
to: currentQuery.rangeTo || '',
2927
},
3028
refreshInterval: {
3129
pause: currentQuery.refreshPaused
32-
? String(currentQuery.refreshPaused)
33-
: '',
30+
? Boolean(currentQuery.refreshPaused)
31+
: true,
3432
value: currentQuery.refreshInterval
35-
? String(currentQuery.refreshInterval)
36-
: '',
33+
? parseInt(currentQuery.refreshInterval, 10)
34+
: 0,
3735
},
3836
};
3937
}

x-pack/plugins/apm/public/components/shared/TransactionActionMenu/__test__/sections.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe('Transaction action menu', () => {
6868
key: 'sampleDocument',
6969
label: 'View sample document',
7070
href:
71-
'some-basepath/app/discover#/?_g=(refreshInterval:(pause:true,value:\'0\'),time:(from:now-24h,to:now))&_a=(index:apm_static_index_pattern_id,interval:auto,query:(language:kuery,query:\'processor.event:"transaction" AND transaction.id:"123" AND trace.id:"123"\'))',
71+
'some-basepath/app/discover#/?_g=(refreshInterval:(pause:!t,value:0),time:(from:now-24h,to:now))&_a=(index:apm_static_index_pattern_id,interval:auto,query:(language:kuery,query:\'processor.event:"transaction" AND transaction.id:"123" AND trace.id:"123"\'))',
7272
condition: true,
7373
},
7474
],
@@ -139,7 +139,7 @@ describe('Transaction action menu', () => {
139139
key: 'sampleDocument',
140140
label: 'View sample document',
141141
href:
142-
'some-basepath/app/discover#/?_g=(refreshInterval:(pause:true,value:\'0\'),time:(from:now-24h,to:now))&_a=(index:apm_static_index_pattern_id,interval:auto,query:(language:kuery,query:\'processor.event:"transaction" AND transaction.id:"123" AND trace.id:"123"\'))',
142+
'some-basepath/app/discover#/?_g=(refreshInterval:(pause:!t,value:0),time:(from:now-24h,to:now))&_a=(index:apm_static_index_pattern_id,interval:auto,query:(language:kuery,query:\'processor.event:"transaction" AND transaction.id:"123" AND trace.id:"123"\'))',
143143
condition: true,
144144
},
145145
],
@@ -209,7 +209,7 @@ describe('Transaction action menu', () => {
209209
key: 'sampleDocument',
210210
label: 'View sample document',
211211
href:
212-
'some-basepath/app/discover#/?_g=(refreshInterval:(pause:true,value:\'0\'),time:(from:now-24h,to:now))&_a=(index:apm_static_index_pattern_id,interval:auto,query:(language:kuery,query:\'processor.event:"transaction" AND transaction.id:"123" AND trace.id:"123"\'))',
212+
'some-basepath/app/discover#/?_g=(refreshInterval:(pause:!t,value:0),time:(from:now-24h,to:now))&_a=(index:apm_static_index_pattern_id,interval:auto,query:(language:kuery,query:\'processor.event:"transaction" AND transaction.id:"123" AND trace.id:"123"\'))',
213213
condition: true,
214214
},
215215
],

0 commit comments

Comments
 (0)