-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Actionable Observability] - Formate Actual value and the Expected value in Alert Details #147025
Merged
fkanout
merged 15 commits into
elastic:main
from
fkanout:145409-alert-summary-to-alert-details-app-section-apm
Dec 16, 2022
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
653202a
Move the AlertSummary to the shared folder in o11y
fkanout 43af0e1
Del console log
fkanout 35e3a56
Revert "Move the AlertSummary to the shared folder in o11y"
fkanout 7d1ca77
Add formatting to the alert summary
fkanout f4f3cc9
Added the formatter with the getAlertEvaluationUnitTypeByRuleTypeId
fkanout 04e7e72
Move formatAlertEvaluationValue to util folder
fkanout 5872820
Add tests
fkanout 0e90cda
fix typo
fkanout 88d570b
Merge branch 'main' into 145409-alert-summary-to-alert-details-app-se…
fkanout 0f56a8d
Merge branch 'main' into 145409-alert-summary-to-alert-details-app-se…
fkanout 7eca8dc
Merge branch 'main' into 145409-alert-summary-to-alert-details-app-se…
fkanout 23cb662
Fix filename
fkanout cf47806
Fix tests
fkanout e50602f
Merge branch 'main' into 145409-alert-summary-to-alert-details-app-se…
fkanout ca4db3a
Code review
fkanout File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; | ||
} | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just thinking out loud:
Does it make sense that the Observability plugin knows about specific details of the APM rule types? I am wondering if this logic is something that should be provided by each app or if we should handle it like this in the Observability plugin. (Especially if we will have similar scenarios for each rule type)
@fkanout @simianhacker What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maryam-saeidi, it's a good question. The goal was to make the AlertSummary sharable, and then each App will import it and then use their logic/formatter.
However, when I started implementation, I realized that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting.
It makes sense that Observability shares formatter since the formatting logic can be re-used in different rule types.
The concern here is to spread the logic related to rules in multiple plugins and make the Observability plugin unnecessarily aware of details of each rule type and as a result, in case of any change or addition, to always update this plugin as well. So basically, we are affecting the separation of concern here.
Also, can you please elaborate on why it is not ideal? What issues it might cause?