Skip to content
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
merged 6 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions x-pack/plugins/apm/public/components/app/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { EuiTabLink } from '../../shared/EuiTabLink';
import { ServiceMapLink } from '../../shared/Links/apm/ServiceMapLink';
import { ServiceOverviewLink } from '../../shared/Links/apm/ServiceOverviewLink';
import { SettingsLink } from '../../shared/Links/apm/SettingsLink';
import { AnomalyDetectionSetupLink } from '../../shared/Links/apm/AnomalyDetectionSetupLink';
import { TraceOverviewLink } from '../../shared/Links/apm/TraceOverviewLink';
import { SetupInstructionsLink } from '../../shared/Links/SetupInstructionsLink';
import { ServiceMap } from '../ServiceMap';
Expand Down Expand Up @@ -118,6 +119,9 @@ export function Home({ tab }: Props) {
</EuiButtonEmpty>
</SettingsLink>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<AnomalyDetectionSetupLink />
</EuiFlexItem>
<EuiFlexItem grow={false}>
<SetupInstructionsLink />
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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 { ENVIRONMENT_NOT_DEFINED } from '../../../../../common/environment_filter_values';
import { useUrlParams } from '../../../../hooks/useUrlParams';
import { useFetcher, FETCH_STATUS } from '../../../../hooks/useFetcher';

export function AnomalyDetectionSetupLink() {
const { uiFilters, urlParams } = useUrlParams();
// check both uiFilters and urlParams for selected environment
ogupte marked this conversation as resolved.
Show resolved Hide resolved
const environment = uiFilters.environment || urlParams.environment;

const { data = [], status } = useFetcher(
(callApmApi) =>
callApmApi({ pathname: `/api/apm/settings/anomaly-detection` }),
[],
{ preservePreviousData: false }
);
const isFetchSuccess = status === FETCH_STATUS.SUCCESS;

const hasJobs = data.length > 0;
const hasJobForEnv = environment
? data.some(({ environment: env }) => environment === env)
: true;

const showAlert = isFetchSuccess && (!hasJobs || !hasJobForEnv);
const toolTipText = environment
? getNotEnabledForEnvironmentText(environment)
: NOT_ENABLED_TEXT;

return (
<APMLink path="/settings/anomaly-detection">
<EuiButtonEmpty size="s" color="primary" iconType="inspect">
{ANOMALY_DETECTION_LINK_LABEL}
</EuiButtonEmpty>
{showAlert && (
<EuiToolTip position="bottom" content={toolTipText}>
ogupte marked this conversation as resolved.
Show resolved Hide resolved
<EuiIcon type="alert" color="danger" />
</EuiToolTip>
)}
</APMLink>
);
}

function getEnvironmentLabel(environment: string) {
if (environment === ENVIRONMENT_NOT_DEFINED) {
return i18n.translate('xpack.apm.filter.environment.notDefinedLabel', {
defaultMessage: 'Not defined',
});
}
return environment;
}
ogupte marked this conversation as resolved.
Show resolved Hide resolved

function getNotEnabledForEnvironmentText(environment: string) {
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` }
);
const NOT_ENABLED_TEXT = i18n.translate(
'xpack.apm.anomalyDetectionSetup.notEnabledText',
{
defaultMessage: `Anomaly detection is not yet enabled. Click to continue setup.`,
}
);
ogupte marked this conversation as resolved.
Show resolved Hide resolved