-
Notifications
You must be signed in to change notification settings - Fork 8k
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
[OBS-UX-MNGMT] Move the Alerting comparators from TriggersActionsUI plugin to the alerting-types package #181584
[OBS-UX-MNGMT] Move the Alerting comparators from TriggersActionsUI plugin to the alerting-types package #181584
Conversation
🤖 GitHub commentsExpand to view the GitHub comments
Just comment with:
|
Pinging @elastic/obs-ux-management-team (Team:obs-ux-management) |
…-ui-and-remove-duplicates
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.
Infra LGTM
…-ui-and-remove-duplicates
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.
ResponesOps changes LGTM
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.
Thanks for the update, looks much better now! 🎉 (Waiting for the discussion on slack before approval)
Tested the following scenarios locally, creating the rule in the main and checking it on the current PR.
Rule | Comparator | Result | Preview chart | Flyout | Execution |
---|---|---|---|---|---|
Custom threshold | Not between | Saved successfully | ✅ | ✅ | ✅ |
Metric threshold | Not between | Cannot create a rule, shows params invalid: [criteria.0]: types that failed validation: - [criteria.0.0.comparator] error |
|||
Metric threshold | Is not between | Saved successfully | ✅ | ✅ | ✅ |
Metric threshold | Not between (warning) | Cannot create a rule, shows params invalid: [criteria.0]: types that failed validation: - [criteria.0.0.warningComparator] error |
|||
Metric threshold | Is not between | Saved successfully | ✅ | ✅ | ✅ |
Inventory | Not between | Cannot create a rule, shows params invalid: [criteria.0.comparator]: must be one of ... between | outside error |
|||
Inventory | Not between (warning) | Cannot create a rule, shows params invalid: [criteria.0.warningComparator]: must be one of ... between | outside error |
Btw, when I edited the rule and saved it again, the comparator was still outside
, is that expected?
…-ui-and-remove-duplicates
@@ -19,11 +20,6 @@ export enum InfraRuleType { | |||
InventoryThreshold = 'metrics.alert.inventory.threshold', | |||
} | |||
|
|||
export interface InfraRuleTypeParams { |
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.
Not used ❌
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.
Thanks for updating the rule param types to COMPARATORS | LEGACY_COMPARATORS. :)
There are some type check failures that I assume we can fix without casting by using the helper function, so I will approve the PR as it works as expected.
I just added one comment about checking outside for Inventory rule, as I assume it should have been working at some point from UI, and from API, it should be possible to create rules even when UI is failing. But up to you to decide as you have more context about the impact of this.
export const createConditionScript = (threshold: number[], comparator: COMPARATORS) => { | ||
export const createConditionScript = ( | ||
threshold: number[], | ||
comparator: COMPARATORS | LEGACY_COMPARATORS |
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.
Can you please use convertToBuiltInComparators
at the upper level to avoid this type change?
i.e.
createConditionScript(condition.threshold, convertToBuiltInComparators(condition.comparator))
@@ -45,7 +46,9 @@ const recoveredComparatorToI18n = ( | |||
} | |||
}; | |||
|
|||
const alertComparatorToI18n = (comparator: COMPARATORS) => { | |||
const alertComparatorToI18n = (comparator: COMPARATORS | LEGACY_COMPARATORS) => { |
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.
You can avoid this type change by adjusting formatAlertResult
and returning build in comparator:
export type FormattedEvaluation = Omit<Evaluation, 'currentValue' | 'threshold' | 'comparator'> & {
currentValue: string;
threshold: string[];
comparator: COMPARATOR;
};
export const formatAlertResult = (evaluationResult: Evaluation): FormattedEvaluation => {
return {
...
comparator: convertToBuiltInComparators(comparator),
};
};
@@ -56,13 +54,13 @@ import { O11Y_AAD_FIELDS } from '../../../../common/constants'; | |||
|
|||
const condition = schema.object({ | |||
threshold: schema.arrayOf(schema.number()), | |||
comparator: oneOfLiterals(Object.values(Comparator)) as Type<Comparator>, | |||
comparator: oneOfLiterals(Object.values(COMPARATORS)) as Type<COMPARATORS>, |
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.
We don't check the outside
here for the inventory rule, IIRC, since it was not working in the UI. From what I see, it should work fine if someone provides outside
in the API. So, I think it would be better to handle this case like other rules.
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.
When the inventory rule was introduced, it didn't have "not in between". It was introduced in v8.10
-I believe by accident due to a types refactoring, and since the 8.10 version, we can't create the rule with "not in between"
From what I see, it should work fine if someone provides outside in the API
The error we see in the UI is coming from the API. The API will use the validator function provided in the rule registry, so we can't create the rule from the API for the same reason.
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.
The error we see in the UI is coming from the API. The API will use the validator function provided in the rule registry, so we can't create the rule from the API for the same reason.
UI is providing notBetween,
but in the API validation, it accepts outside.
When I tried creating a rule directly via API, providing outside
, the rule was created successfully and alerts were generated as you see below:
But now the execution is failing:
…-ui-and-remove-duplicates
…-ui-and-remove-duplicates
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.
Update:
- No more
COMPARATORS | LEGACY_COMPARATORS
all over the place. Only used in the main types definitions. - Wherever the comparator is used and before sending it to a function that uses it, I convert it with
convertToBuiltInComparators
, so the function keepsCOMPARATORS
as the only type. - I was converting the comparator at the entry point of the rule executor, this is gone 🧹 , which is cleaner and better. Thanks to the previous step, I don't need it anymore.
- Also covered creating the inventory rule from the API using
outside
use case
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Module Count
Public APIs missing comments
Async chunks
Canvas Sharable Runtime
Page load bundle
Unknown metric groupsAPI count
History
To update your PR or re-run it, just comment with: cc @fkanout |
…lugin to the alerting-types package (elastic#181584) ## Summary It fixes elastic#179633 Observability created a Comparator type/enum, when ResponseOps is already exporting one and other rules using it. The only difference is the wording of not in between [I put the two types side by side to compare] Currently, we import the one in triggers-actions-ui-plugin , and then update the not in between to match our Comparator. ### Comparing the two enums: ![Screenshot 2024-04-23 at 18 17 23](https://github.com/elastic/kibana/assets/6838659/16429ff9-e672-4c16-92ed-488a2f66007d) ## For reviewers 🧪 - Everything should work as expected: Alert flyout, Alert reason message, Rule creation flyout, etc. - I kept the `outside` comparator (replaced by `NOT BETWEEN`) for backward compatibility
…lugin to the alerting-types package (elastic#181584) ## Summary It fixes elastic#179633 Observability created a Comparator type/enum, when ResponseOps is already exporting one and other rules using it. The only difference is the wording of not in between [I put the two types side by side to compare] Currently, we import the one in triggers-actions-ui-plugin , and then update the not in between to match our Comparator. ### Comparing the two enums: ![Screenshot 2024-04-23 at 18 17 23](https://github.com/elastic/kibana/assets/6838659/16429ff9-e672-4c16-92ed-488a2f66007d) ## For reviewers 🧪 - Everything should work as expected: Alert flyout, Alert reason message, Rule creation flyout, etc. - I kept the `outside` comparator (replaced by `NOT BETWEEN`) for backward compatibility
Summary
It fixes #179633
Observability created a Comparator type/enum, when ResponseOps is already exporting one and other rules using it.
The only difference is the wording of not in between [I put the two types side by side to compare]
Currently, we import the one in triggers-actions-ui-plugin , and then update the not in between to match our Comparator.
Comparing the two enums:
For reviewers 🧪
outside
comparator (replaced byNOT BETWEEN
) for backward compatibility