-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[APM] Anomaly detection setup link with alert if job doesn't exist #71229
Merged
ogupte
merged 6 commits into
elastic:master
from
ogupte:apm-70440-anomaly-detection-setup-link
Jul 13, 2020
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
093801c
Closes #70440 by adding a setup link to anomaly detection setting in …
ogupte b2bc73b
PR feedback and type error fix
ogupte e7857ea
Merge branch 'master' into apm-70440-anomaly-detection-setup-link
elasticmachine f150299
Code cleanup and PR feedback
ogupte 4bf17ee
Modified getEnvironmentUiFilterES return type from `ESFilter | undefi…
ogupte 68e666d
Merge branch 'master' into apm-70440-anomaly-detection-setup-link
elasticmachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
63 changes: 63 additions & 0 deletions
63
x-pack/plugins/apm/public/components/shared/Links/apm/AnomalyDetectionSetupLink.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 from 'react'; | ||
import { EuiButtonEmpty, EuiToolTip, EuiIcon } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { APMLink } from './APMLink'; | ||
import { getEnvironmentLabel } from '../../../../../common/environment_filter_values'; | ||
import { useUrlParams } from '../../../../hooks/useUrlParams'; | ||
import { useFetcher, FETCH_STATUS } from '../../../../hooks/useFetcher'; | ||
|
||
export function AnomalyDetectionSetupLink() { | ||
const { uiFilters } = useUrlParams(); | ||
const environment = uiFilters.environment; | ||
|
||
const { data = { jobs: [], hasLegacyJobs: false }, status } = useFetcher( | ||
(callApmApi) => | ||
callApmApi({ pathname: `/api/apm/settings/anomaly-detection` }), | ||
[], | ||
{ preservePreviousData: false } | ||
); | ||
const isFetchSuccess = status === FETCH_STATUS.SUCCESS; | ||
|
||
// Show alert if there are no jobs OR if no job matches the current environment | ||
const showAlert = | ||
isFetchSuccess && !data.jobs.some((job) => environment === job.environment); | ||
|
||
return ( | ||
<APMLink path="/settings/anomaly-detection"> | ||
<EuiButtonEmpty size="s" color="primary" iconType="inspect"> | ||
{ANOMALY_DETECTION_LINK_LABEL} | ||
</EuiButtonEmpty> | ||
{showAlert && ( | ||
<EuiToolTip position="bottom" content={getTooltipText(environment)}> | ||
<EuiIcon type="alert" color="danger" /> | ||
</EuiToolTip> | ||
)} | ||
</APMLink> | ||
); | ||
} | ||
|
||
function getTooltipText(environment?: string) { | ||
if (!environment) { | ||
return i18n.translate('xpack.apm.anomalyDetectionSetup.notEnabledText', { | ||
defaultMessage: `Anomaly detection is not yet enabled. Click to continue setup.`, | ||
}); | ||
} | ||
|
||
return i18n.translate( | ||
'xpack.apm.anomalyDetectionSetup.notEnabledForEnvironmentText', | ||
{ | ||
defaultMessage: `Anomaly detection is not yet enabled for the "{currentEnvironment}" environment. Click to continue setup.`, | ||
values: { currentEnvironment: getEnvironmentLabel(environment) }, | ||
} | ||
); | ||
} | ||
|
||
const ANOMALY_DETECTION_LINK_LABEL = i18n.translate( | ||
'xpack.apm.anomalyDetectionSetup.linkLabel', | ||
{ defaultMessage: `Anomaly detection` } | ||
); |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice change, thanks! Can we use spread for
mappedFilters
instead of concat (for consistency)?