-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[APM] "View job" link from latency charts leads to a malfunctioning p…
- Loading branch information
1 parent
755b042
commit 177f9a1
Showing
4 changed files
with
122 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...k/plugins/apm/public/components/shared/Links/MachineLearningLinks/MLExplorerLink.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { Location } from 'history'; | ||
import React from 'react'; | ||
import { getRenderedHref } from '../../../../utils/testHelpers'; | ||
import { MLExplorerLink } from './MLExplorerLink'; | ||
|
||
describe('MLExplorerLink', () => { | ||
it('should produce the correct URL with jobId', async () => { | ||
const href = await getRenderedHref( | ||
() => ( | ||
<MLExplorerLink jobId="myservicename-mytransactiontype-high_mean_response_time" /> | ||
), | ||
{ | ||
search: | ||
'?rangeFrom=now/w&rangeTo=now-4h&refreshPaused=true&refreshInterval=0', | ||
} as Location | ||
); | ||
|
||
expect(href).toMatchInlineSnapshot( | ||
`"/app/ml/explorer?_g=(ml:(jobIds:!(myservicename-mytransactiontype-high_mean_response_time)),refreshInterval:(pause:!t,value:0),time:(from:now%2Fw,to:now-4h))&_a=(explorer:(mlExplorerFilter:(),mlExplorerSwimlane:()))"` | ||
); | ||
}); | ||
|
||
it('correctly encodes time range values', async () => { | ||
const href = await getRenderedHref( | ||
() => ( | ||
<MLExplorerLink jobId="apm-production-485b-high_mean_transaction_duration" /> | ||
), | ||
{ | ||
search: | ||
'?rangeFrom=2020-07-29T17:27:29.000Z&rangeTo=2020-07-29T18:45:00.000Z&refreshInterval=10000&refreshPaused=true', | ||
} as Location | ||
); | ||
|
||
expect(href).toMatchInlineSnapshot( | ||
`"/app/ml/explorer?_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=(explorer:(mlExplorerFilter:(),mlExplorerSwimlane:()))"` | ||
); | ||
}); | ||
}); |
63 changes: 63 additions & 0 deletions
63
x-pack/plugins/apm/public/components/shared/Links/MachineLearningLinks/MLExplorerLink.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { ReactNode } from 'react'; | ||
import { EuiLink } from '@elastic/eui'; | ||
import { UI_SETTINGS } from '../../../../../../../../src/plugins/data/common'; | ||
import { useApmPluginContext } from '../../../../context/apm_plugin/use_apm_plugin_context'; | ||
import { useMlHref, ML_PAGES } from '../../../../../../ml/public'; | ||
import { useUrlParams } from '../../../../context/url_params_context/use_url_params'; | ||
import { TimePickerRefreshInterval } from '../../DatePicker/typings'; | ||
|
||
interface Props { | ||
children?: ReactNode; | ||
jobId: string; | ||
external?: boolean; | ||
} | ||
|
||
export function MLExplorerLink({ jobId, external, children }: Props) { | ||
const href = useExplorerHref({ jobId }); | ||
|
||
return ( | ||
<EuiLink | ||
children={children} | ||
href={href} | ||
external={external} | ||
target={external ? '_blank' : undefined} | ||
/> | ||
); | ||
} | ||
|
||
export function useExplorerHref({ jobId }: { jobId: string }) { | ||
const { | ||
core, | ||
plugins: { ml }, | ||
} = useApmPluginContext(); | ||
const { urlParams } = useUrlParams(); | ||
|
||
const timePickerRefreshIntervalDefaults = core.uiSettings.get<TimePickerRefreshInterval>( | ||
UI_SETTINGS.TIMEPICKER_REFRESH_INTERVAL_DEFAULTS | ||
); | ||
|
||
const { | ||
// hardcoding a custom default of 1 hour since the default kibana timerange of 15 minutes is shorter than the ML interval | ||
rangeFrom = 'now-1h', | ||
rangeTo = 'now', | ||
refreshInterval = timePickerRefreshIntervalDefaults.value, | ||
refreshPaused = timePickerRefreshIntervalDefaults.pause, | ||
} = urlParams; | ||
|
||
const href = useMlHref(ml, core.http.basePath.get(), { | ||
page: ML_PAGES.ANOMALY_EXPLORER, | ||
pageState: { | ||
jobIds: [jobId], | ||
timeRange: { from: rangeFrom, to: rangeTo }, | ||
refreshInterval: { pause: refreshPaused, value: refreshInterval }, | ||
}, | ||
}); | ||
|
||
return href; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters