forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve reason message of custom threshold rule by adding data view i…
…nformation (elastic#169414) Resolves elastic#162710 ## Summary This PR improves the custom threshold rule reason message by adding the data view indices and adjusting the reason for multiple aggregations. Previously, for multiple aggregations, we repeat some information that is shared between aggregations, such as interval and group information. Also, this PR improves the reason messages for single aggregation based on the selected aggregation and field, similar to what we currently have in the metric threshold rule. |Previous reason message | New reason message| |---|---| |![image](https://github.com/elastic/kibana/assets/12370520/bb7e0048-3590-48f0-adfe-218618c48782)|![image](https://github.com/elastic/kibana/assets/12370520/7a3d9778-f84b-4bbb-a8e0-a99debfe78d1)| ## 🧪 How to test - Create some custom threshold rules and check the reason message - Single condition (different aggregators and comparators) - With a label for the equation - Without a label - Multiple conditions (different aggregators and comparators) - With a label for the equation - Without a label ### Known issue I created an issue for `is not between` comparator and I wasn't able to genarate an alert for it: elastic#169524
- Loading branch information
1 parent
d942833
commit c15da16
Showing
14 changed files
with
362 additions
and
238 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
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
47 changes: 47 additions & 0 deletions
47
x-pack/plugins/observability/server/lib/rules/custom_threshold/lib/format_alert_result.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,47 @@ | ||
/* | ||
* 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 { createFormatter } from '../../../../../common/custom_threshold_rule/formatters'; | ||
import { Evaluation } from './evaluate_rule'; | ||
|
||
export type FormattedEvaluation = Omit<Evaluation, 'currentValue' | 'threshold'> & { | ||
currentValue: string; | ||
threshold: string[]; | ||
}; | ||
|
||
export const formatAlertResult = (evaluationResult: Evaluation): FormattedEvaluation => { | ||
const { metric, currentValue, threshold, comparator } = evaluationResult; | ||
const noDataValue = i18n.translate( | ||
'xpack.observability.customThreshold.rule.alerting.threshold.noDataFormattedValue', | ||
{ defaultMessage: '[NO DATA]' } | ||
); | ||
|
||
if (metric.endsWith('.pct')) { | ||
const formatter = createFormatter('percent'); | ||
return { | ||
...evaluationResult, | ||
currentValue: | ||
currentValue !== null && currentValue !== undefined ? formatter(currentValue) : noDataValue, | ||
threshold: Array.isArray(threshold) | ||
? threshold.map((v: number) => formatter(v)) | ||
: [formatter(threshold)], | ||
comparator, | ||
}; | ||
} | ||
|
||
const formatter = createFormatter('highPrecision'); | ||
return { | ||
...evaluationResult, | ||
currentValue: | ||
currentValue !== null && currentValue !== undefined ? formatter(currentValue) : noDataValue, | ||
threshold: Array.isArray(threshold) | ||
? threshold.map((v: number) => formatter(v)) | ||
: [formatter(threshold)], | ||
comparator, | ||
}; | ||
}; |
Oops, something went wrong.