-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] Package
@kbn/ml-anomaly-utils
(#155697)
Creates Package `@kbn/ml-anomaly-utils`. - This moves some of the utility functions, constants and types related to Anomaly Detection we previously exposed from the `ml` plugin itself to a package `@kbn/ml-anomaly-utils`, resulting in ~5.9KB reduction of the plugin's page load bundle size. - To reduce increases in async bundle size for consuming plugins the utils have been refactored into individual files to allow deep imports and get some optimization through that. Some previously duplicated code in consuming plugins has been deleted and replaced with deep imports of the corresponding original code in the package. - Types have been prefixed with `Ml`. - Constants have been prefixed with `ML_`. Created package via `node scripts/generate package @kbn/ml-anomaly-utils --web --dir ./x-pack/packages/ml/anomaly_utils`.
- Loading branch information
Showing
163 changed files
with
1,653 additions
and
1,170 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# @kbn/ml-anomaly-utils | ||
|
||
Utility functions, constants and types for Machine Learning's 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
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 | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
/** | ||
* Labels displayed in the ML UI to indicate the severity of the anomaly according | ||
* to the normalized anomaly score. | ||
*/ | ||
export enum ML_ANOMALY_SEVERITY { | ||
/** | ||
* Anomalies are displayed as critical severity when the score is greater than or equal to 75. | ||
*/ | ||
CRITICAL = 'critical', | ||
|
||
/** | ||
* Anomalies are displayed as major severity when the score is greater than or equal to 50 and less than 75. | ||
*/ | ||
MAJOR = 'major', | ||
|
||
/** | ||
* Anomalies are displayed as minor severity when the score is greater than or equal to 25 and less than 50. | ||
*/ | ||
MINOR = 'minor', | ||
|
||
/** | ||
* Anomalies are displayed as warning severity when the score is greater than or equal to 3 and less than 25. | ||
* Note in some parts of the UI, warning severity is used when the score is greater than or equal to 0. | ||
*/ | ||
WARNING = 'warning', | ||
|
||
/** | ||
* Anomalies are displayed as low severity in some parts of the ML UI when the score is greater than or equal to 0 and less than 3. | ||
*/ | ||
LOW = 'low', | ||
|
||
/** | ||
* Anomalies are displayed as unknown severity if the anomaly score is not known. | ||
*/ | ||
UNKNOWN = 'unknown', | ||
} | ||
|
||
/** | ||
* Interface for severity types to be used in ML_ANOMALY_SEVERITY_TYPES. | ||
* | ||
* @export | ||
* @interface MlSeverityType | ||
* @typedef {MlSeverityType} | ||
*/ | ||
export interface MlSeverityType { | ||
/** | ||
* One of ML_ANOMALY_SEVERITY | ||
* @type {ML_ANOMALY_SEVERITY} | ||
*/ | ||
id: ML_ANOMALY_SEVERITY; | ||
/** | ||
* Translated ML_ANOMALY_SEVERITY | ||
* @type {string} | ||
*/ | ||
label: string; | ||
} |
48 changes: 48 additions & 0 deletions
48
x-pack/packages/ml/anomaly_utils/anomaly_severity_types.ts
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,48 @@ | ||
/* | ||
* 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 { type MlSeverityType, ML_ANOMALY_SEVERITY } from './anomaly_severity'; | ||
|
||
export const ML_ANOMALY_SEVERITY_TYPES: Record<ML_ANOMALY_SEVERITY, MlSeverityType> = { | ||
critical: { | ||
id: ML_ANOMALY_SEVERITY.CRITICAL, | ||
label: i18n.translate('xpack.ml.anomalyUtils.severity.criticalLabel', { | ||
defaultMessage: 'critical', | ||
}), | ||
}, | ||
major: { | ||
id: ML_ANOMALY_SEVERITY.MAJOR, | ||
label: i18n.translate('xpack.ml.anomalyUtils.severity.majorLabel', { | ||
defaultMessage: 'major', | ||
}), | ||
}, | ||
minor: { | ||
id: ML_ANOMALY_SEVERITY.MINOR, | ||
label: i18n.translate('xpack.ml.anomalyUtils.severity.minorLabel', { | ||
defaultMessage: 'minor', | ||
}), | ||
}, | ||
warning: { | ||
id: ML_ANOMALY_SEVERITY.WARNING, | ||
label: i18n.translate('xpack.ml.anomalyUtils.severity.warningLabel', { | ||
defaultMessage: 'warning', | ||
}), | ||
}, | ||
unknown: { | ||
id: ML_ANOMALY_SEVERITY.UNKNOWN, | ||
label: i18n.translate('xpack.ml.anomalyUtils.severity.unknownLabel', { | ||
defaultMessage: 'unknown', | ||
}), | ||
}, | ||
low: { | ||
id: ML_ANOMALY_SEVERITY.LOW, | ||
label: i18n.translate('xpack.ml.anomalyUtils.severityWithLow.lowLabel', { | ||
defaultMessage: 'low', | ||
}), | ||
}, | ||
}; |
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,36 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* Anomaly score numeric thresholds to indicate the severity of the anomaly. | ||
*/ | ||
export enum ML_ANOMALY_THRESHOLD { | ||
/** | ||
* Threshold at which anomalies are labelled in the UI as critical. | ||
*/ | ||
CRITICAL = 75, | ||
|
||
/** | ||
* Threshold at which anomalies are labelled in the UI as major. | ||
*/ | ||
MAJOR = 50, | ||
|
||
/** | ||
* Threshold at which anomalies are labelled in the UI as minor. | ||
*/ | ||
MINOR = 25, | ||
|
||
/** | ||
* Threshold at which anomalies are labelled in the UI as warning. | ||
*/ | ||
WARNING = 3, | ||
|
||
/** | ||
* Threshold at which anomalies are labelled in the UI as low. | ||
*/ | ||
LOW = 0, | ||
} |
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.