-
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.
[Actionable Observability] Move the AlertSummary into the AlertDetail…
…sAppSection in the solutions (#147025) ## Summary Closes #145409 by formatting the `Actual value` and the `Expected value.`
- Loading branch information
Showing
4 changed files
with
87 additions
and
4 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
23 changes: 23 additions & 0 deletions
23
x-pack/plugins/observability/public/utils/format_alert_evaluation_value.test.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,23 @@ | ||
/* | ||
* 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 { formatAlertEvaluationValue } from './format_alert_evaluation_value'; | ||
|
||
describe('formatAlertEvaluationValue', () => { | ||
it('returns - when there is no evaluationValue passed', () => { | ||
expect(formatAlertEvaluationValue('apm.transaction_error_rate', undefined)).toBe('-'); | ||
}); | ||
it('returns the evaluation value when ruleTypeId in unknown aka unformatted', () => { | ||
expect(formatAlertEvaluationValue('unknown.rule.type', 2000)).toBe(2000); | ||
}); | ||
it('returns the evaluation value formatted as percent when the alert rule type is "apm.transaction_error_rate" ', () => { | ||
expect(formatAlertEvaluationValue('apm.transaction_error_rate', 20)).toBe('20%'); | ||
}); | ||
it('returns the evaluation value formatted as duration in ms when the alert rule type is "apm.transaction_duration" ', () => { | ||
expect(formatAlertEvaluationValue('apm.transaction_duration', 140000)).toBe('140 ms'); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
x-pack/plugins/observability/public/utils/format_alert_evaluation_value.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,25 @@ | ||
/* | ||
* 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 { asMillisecondDuration, asPercent } from '../../common/utils/formatters'; | ||
import { | ||
ALERT_EVALUATION_UNIT_TYPE, | ||
getAlertEvaluationUnitTypeByRuleTypeId, | ||
} from './get_alert_evaluation_unit_type_by_rule_type_id'; | ||
|
||
export const formatAlertEvaluationValue = (ruleTypeId?: string, evaluationValue?: number) => { | ||
if (!evaluationValue || !ruleTypeId) return '-'; | ||
const unitType = getAlertEvaluationUnitTypeByRuleTypeId(ruleTypeId); | ||
switch (unitType) { | ||
case ALERT_EVALUATION_UNIT_TYPE.DURATION: | ||
return asMillisecondDuration(evaluationValue); | ||
case ALERT_EVALUATION_UNIT_TYPE.PERCENT: | ||
return asPercent(evaluationValue, 100); | ||
default: | ||
return evaluationValue; | ||
} | ||
}; |
28 changes: 28 additions & 0 deletions
28
x-pack/plugins/observability/public/utils/get_alert_evaluation_unit_type_by_rule_type_id.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,28 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export const ALERT_EVALUATION_UNIT_TYPE = { | ||
DURATION: 'DURATION', | ||
PERCENT: 'PERCENT', | ||
NUMBER: 'NUMBER', | ||
} as const; | ||
|
||
type ObjectValues<T> = T[keyof T]; | ||
type AlertEvaluationUnitType = ObjectValues<typeof ALERT_EVALUATION_UNIT_TYPE>; | ||
|
||
export const getAlertEvaluationUnitTypeByRuleTypeId = ( | ||
ruleTypeId: string | ||
): AlertEvaluationUnitType => { | ||
switch (ruleTypeId) { | ||
case 'apm.transaction_duration': | ||
return ALERT_EVALUATION_UNIT_TYPE.DURATION; | ||
case 'apm.transaction_error_rate': | ||
return ALERT_EVALUATION_UNIT_TYPE.PERCENT; | ||
default: | ||
return ALERT_EVALUATION_UNIT_TYPE.NUMBER; | ||
} | ||
}; |