-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
6087f1e
commit 2d361f0
Showing
10 changed files
with
145 additions
and
158 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
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
40 changes: 0 additions & 40 deletions
40
x-pack/plugins/apm/public/components/shared/Links/MachineLearningLinks/MLJobLink.tsx
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
x-pack/plugins/apm/public/components/shared/Links/MachineLearningLinks/MLLink.test.tsx
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
...plugins/apm/public/components/shared/Links/MachineLearningLinks/MLManageJobsLink.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,21 @@ | ||
/* | ||
* 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 { MLManageJobsLink } from './MLManageJobsLink'; | ||
|
||
test('MLManageJobsLink', async () => { | ||
const href = await getRenderedHref(() => <MLManageJobsLink />, { | ||
search: | ||
'?rangeFrom=now-5h&rangeTo=now-2h&refreshPaused=true&refreshInterval=0', | ||
} as Location); | ||
|
||
expect(href).toMatchInlineSnapshot( | ||
`"/app/ml/jobs?_a=(jobs:(queryText:'groups:(apm)'))&_g=(refreshInterval:(pause:!t,value:0),time:(from:now-5h,to:now-2h))"` | ||
); | ||
}); |
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
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
90 changes: 90 additions & 0 deletions
90
...ck/plugins/apm/public/components/shared/Links/MachineLearningLinks/MLSingleMetricLink.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,90 @@ | ||
/* | ||
* 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; | ||
serviceName?: string; | ||
transactionType?: string; | ||
} | ||
|
||
export function MLSingleMetricLink({ | ||
jobId, | ||
serviceName, | ||
transactionType, | ||
external, | ||
children, | ||
}: Props) { | ||
const href = useSingleMetricHref({ jobId, serviceName, transactionType }); | ||
|
||
return ( | ||
<EuiLink | ||
children={children} | ||
href={href} | ||
external={external} | ||
target={external ? '_blank' : undefined} | ||
/> | ||
); | ||
} | ||
|
||
export function useSingleMetricHref({ | ||
jobId, | ||
serviceName, | ||
transactionType, | ||
}: { | ||
jobId: string; | ||
serviceName?: string; | ||
transactionType?: 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 entities = | ||
serviceName && transactionType | ||
? { | ||
entities: { | ||
'service.name': serviceName, | ||
'transaction.type': transactionType, | ||
}, | ||
} | ||
: {}; | ||
|
||
const href = useMlHref(ml, core.http.basePath.get(), { | ||
page: ML_PAGES.SINGLE_METRIC_VIEWER, | ||
pageState: { | ||
jobIds: [jobId], | ||
timeRange: { from: rangeFrom, to: rangeTo }, | ||
refreshInterval: { pause: refreshPaused, value: refreshInterval }, | ||
...entities, | ||
}, | ||
}); | ||
|
||
return href; | ||
} |
Oops, something went wrong.