-
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.
[ML] Add anomaly description as an alert message for anomaly detectio…
…n rule type (#172473) ## Summary Closes #136391 Uses a description of the anomaly for the alert message for anomaly detection alerting rules with the `record` result type. This messages is used for example in the `Reason` field in the alert table and details flyout. <img width="753" alt="image" src="https://github.com/elastic/kibana/assets/7405507/072fe833-204b-4d38-bd3d-50d00015a43f"> ### Checklist - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
- Loading branch information
Showing
10 changed files
with
161 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { capitalize } from 'lodash'; | ||
import { getSeverity, type MlAnomaliesTableRecordExtended } from '@kbn/ml-anomaly-utils'; | ||
|
||
export function getAnomalyDescription(anomaly: MlAnomaliesTableRecordExtended): { | ||
anomalyDescription: string; | ||
mvDescription: string | undefined; | ||
} { | ||
const source = anomaly.source; | ||
|
||
let anomalyDescription = i18n.translate('xpack.ml.anomalyDescription.anomalyInLabel', { | ||
defaultMessage: '{anomalySeverity} anomaly in {anomalyDetector}', | ||
values: { | ||
anomalySeverity: capitalize(getSeverity(anomaly.severity).label), | ||
anomalyDetector: anomaly.detector, | ||
}, | ||
}); | ||
|
||
if (anomaly.entityName !== undefined) { | ||
anomalyDescription += i18n.translate('xpack.ml.anomalyDescription.foundForLabel', { | ||
defaultMessage: ' found for {anomalyEntityName} {anomalyEntityValue}', | ||
values: { | ||
anomalyEntityName: anomaly.entityName, | ||
anomalyEntityValue: anomaly.entityValue, | ||
}, | ||
}); | ||
} | ||
|
||
if ( | ||
source.partition_field_name !== undefined && | ||
source.partition_field_name !== anomaly.entityName | ||
) { | ||
anomalyDescription += i18n.translate('xpack.ml.anomalyDescription.detectedInLabel', { | ||
defaultMessage: ' detected in {sourcePartitionFieldName} {sourcePartitionFieldValue}', | ||
values: { | ||
sourcePartitionFieldName: source.partition_field_name, | ||
sourcePartitionFieldValue: source.partition_field_value, | ||
}, | ||
}); | ||
} | ||
|
||
// Check for a correlatedByFieldValue in the source which will be present for multivariate analyses | ||
// where the record is anomalous due to relationship with another 'by' field value. | ||
let mvDescription: string = ''; | ||
if (source.correlated_by_field_value !== undefined) { | ||
mvDescription = i18n.translate('xpack.ml.anomalyDescription.multivariateDescription', { | ||
defaultMessage: | ||
'multivariate correlations found in {sourceByFieldName}; ' + | ||
'{sourceByFieldValue} is considered anomalous given {sourceCorrelatedByFieldValue}', | ||
values: { | ||
sourceByFieldName: source.by_field_name, | ||
sourceByFieldValue: source.by_field_value, | ||
sourceCorrelatedByFieldValue: source.correlated_by_field_value, | ||
}, | ||
}); | ||
} | ||
|
||
return { | ||
anomalyDescription, | ||
mvDescription, | ||
}; | ||
} |
File renamed without changes.
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
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