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] Align APM severity levels with ML #77818

Merged
merged 3 commits into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
37 changes: 37 additions & 0 deletions x-pack/plugins/apm/common/alert_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/

import { i18n } from '@kbn/i18n';
import { ValuesType } from 'utility-types';
import { ANOMALY_SEVERITY, ANOMALY_THRESHOLD } from '../../ml/common';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are already exporting these from the root of our plugin.

Suggested change
import { ANOMALY_SEVERITY, ANOMALY_THRESHOLD } from '../../ml/common';
import { ANOMALY_SEVERITY, ANOMALY_THRESHOLD } from '../../ml/public';


export enum AlertType {
ErrorCount = 'apm.error_rate', // ErrorRate was renamed to ErrorCount but the key is kept as `error_rate` for backwards-compat.
Expand Down Expand Up @@ -55,6 +57,41 @@ export const ALERT_TYPES_CONFIG = {
},
};

export const ANOMALY_ALERT_SEVERITY_TYPES = [
{
type: ANOMALY_SEVERITY.CRITICAL,
label: i18n.translate('xpack.apm.alerts.anomalySeverity.criticalLabel', {
defaultMessage: 'critical',
}),
threshold: ANOMALY_THRESHOLD.CRITICAL,
},
{
type: ANOMALY_SEVERITY.MAJOR,
label: i18n.translate('xpack.apm.alerts.anomalySeverity.majorLabel', {
defaultMessage: 'major',
}),
threshold: ANOMALY_THRESHOLD.MAJOR,
},
{
type: ANOMALY_SEVERITY.MINOR,
label: i18n.translate('xpack.apm.alerts.anomalySeverity.minor', {
defaultMessage: 'minor',
}),
threshold: ANOMALY_THRESHOLD.MINOR,
},
{
type: ANOMALY_SEVERITY.WARNING,
label: i18n.translate('xpack.apm.alerts.anomalySeverity.warningLabel', {
defaultMessage: 'warning',
}),
threshold: ANOMALY_THRESHOLD.WARNING,
},
] as const;

export type AnomalyAlertSeverityType = ValuesType<
typeof ANOMALY_ALERT_SEVERITY_TYPES
>['type'];

// Server side registrations
// x-pack/plugins/apm/server/lib/alerts/<alert>.ts
// x-pack/plugins/apm/server/lib/alerts/register_apm_alerts.ts
Expand Down
39 changes: 0 additions & 39 deletions x-pack/plugins/apm/common/anomaly_detection.test.ts

This file was deleted.

84 changes: 13 additions & 71 deletions x-pack/plugins/apm/common/anomaly_detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,89 +5,31 @@
*/

import { i18n } from '@kbn/i18n';
import { EuiTheme } from '../../../legacy/common/eui_styled_components';
import { ANOMALY_SEVERITY } from '../../ml/common';
import {
getSeverityType,
getSeverityColor as mlGetSeverityColor,
} from '../../ml/common';
import { ServiceHealthStatus } from './service_health_status';

export interface ServiceAnomalyStats {
transactionType?: string;
anomalyScore?: number;
actualValue?: number;
jobId?: string;
healthStatus: ServiceHealthStatus;
}

export enum Severity {
critical = 'critical',
major = 'major',
minor = 'minor',
warning = 'warning',
}

// TODO: Replace with `getSeverity` from:
// https://github.com/elastic/kibana/blob/0f964f66916480f2de1f4b633e5afafc08cf62a0/x-pack/plugins/ml/common/util/anomaly_utils.ts#L129
export function getSeverity(score?: number) {
if (typeof score !== 'number') {
return undefined;
} else if (score < 25) {
return Severity.warning;
} else if (score >= 25 && score < 50) {
return Severity.minor;
} else if (score >= 50 && score < 75) {
return Severity.major;
} else if (score >= 75) {
return Severity.critical;
} else {
return undefined;
export function getSeverity(score: number | undefined) {
if (score === undefined) {
return ANOMALY_SEVERITY.UNKNOWN;
}
}

export function getSeverityColor(theme: EuiTheme, severity?: Severity) {
switch (severity) {
case Severity.warning:
return theme.eui.euiColorVis0;
case Severity.minor:
case Severity.major:
return theme.eui.euiColorVis5;
case Severity.critical:
return theme.eui.euiColorVis9;
default:
return;
}
return getSeverityType(score);
}

export function getSeverityLabel(severity?: Severity) {
switch (severity) {
case Severity.critical:
return i18n.translate(
'xpack.apm.servicesTable.serviceHealthStatus.critical',
{
defaultMessage: 'Critical',
}
);

case Severity.major:
case Severity.minor:
return i18n.translate(
'xpack.apm.servicesTable.serviceHealthStatus.warning',
{
defaultMessage: 'Warning',
}
);

case Severity.warning:
return i18n.translate(
'xpack.apm.servicesTable.serviceHealthStatus.healthy',
{
defaultMessage: 'Healthy',
}
);

default:
return i18n.translate(
'xpack.apm.servicesTable.serviceHealthStatus.unknown',
{
defaultMessage: 'Unknown',
}
);
}
export function getSeverityColor(score: number) {
return mlGetSeverityColor(score);
}

export const ML_ERRORS = {
Expand Down
79 changes: 79 additions & 0 deletions x-pack/plugins/apm/common/service_health_status.ts
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 { i18n } from '@kbn/i18n';
import { ANOMALY_SEVERITY } from '../../ml/common';

import { EuiTheme } from '../../../legacy/common/eui_styled_components';

export enum ServiceHealthStatus {
healthy = 'healthy',
critical = 'critical',
warning = 'warning',
unknown = 'unknown',
}

export function getServiceHealthStatus({
severity,
}: {
severity: ANOMALY_SEVERITY;
}) {
switch (severity) {
case ANOMALY_SEVERITY.CRITICAL:
case ANOMALY_SEVERITY.MAJOR:
return ServiceHealthStatus.critical;

case ANOMALY_SEVERITY.MINOR:
case ANOMALY_SEVERITY.WARNING:
return ServiceHealthStatus.warning;

case ANOMALY_SEVERITY.LOW:
return ServiceHealthStatus.healthy;

case ANOMALY_SEVERITY.UNKNOWN:
return ServiceHealthStatus.unknown;
}
}

export function getServiceHealthStatusColor(
theme: EuiTheme,
status: ServiceHealthStatus
) {
switch (status) {
case ServiceHealthStatus.healthy:
return theme.eui.euiColorVis0;
case ServiceHealthStatus.warning:
return theme.eui.euiColorVis5;
case ServiceHealthStatus.critical:
return theme.eui.euiColorVis9;
case ServiceHealthStatus.unknown:
return theme.eui.euiColorMediumShade;
}
}

export function getServiceHealthStatusLabel(status: ServiceHealthStatus) {
switch (status) {
case ServiceHealthStatus.critical:
return i18n.translate('xpack.apm.serviceHealthStatus.critical', {
defaultMessage: 'Critical',
});

case ServiceHealthStatus.warning:
return i18n.translate('xpack.apm.serviceHealthStatus.warning', {
defaultMessage: 'Warning',
});

case ServiceHealthStatus.healthy:
return i18n.translate('xpack.apm.serviceHealthStatus.healthy', {
defaultMessage: 'Healthy',
});

case ServiceHealthStatus.unknown:
return i18n.translate('xpack.apm.serviceHealthStatus.unknown', {
defaultMessage: 'Unknown',
});
}
}
12 changes: 9 additions & 3 deletions x-pack/plugins/apm/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@
],
"server": true,
"ui": true,
"configPath": ["xpack", "apm"],
"extraPublicDirs": ["public/style/variables"],
"configPath": [
"xpack",
"apm"
],
"extraPublicDirs": [
"public/style/variables"
],
"requiredBundles": [
"kibanaReact",
"kibanaUtils",
"observability",
"home",
"maps"
"maps",
"ml"
]
}
Loading