-
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
Custom equation editor for Metric Threshold Rule #148732
Custom equation editor for Metric Threshold Rule #148732
Conversation
Would you intend that this shall have the full power of Lens Formular's or do yo have a different scope in mind? (https://www.elastic.co/guide/en/kibana/current/lens.html#lens-formulas ) |
…stom-metric-editor-for-mtr
@StephanErb We are exploring ideas for an expressive rule type in the future which will be based on something like the Len's expressions or ESQL. If and when we deliver that, it will be a separate rule type. |
…stom-metric-editor-for-mtr
…stom-metric-editor-for-mtr
@maryam-saeidi @crespocarlos Yes, it's expected that |
…stom-metric-editor-for-mtr
I had a Zoom with @maryam-saeidi and we figured out how to reproduce the validation error she was seeing:
|
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.
LGTM! thanks for applying the suggestions and fixing the bugs.
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.
x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/aggregation.tsx
Outdated
Show resolved
Hide resolved
import { validateMetricThreshold } from '../validation'; | ||
|
||
export default { | ||
title: 'infra/alerting/CustomEquationEditor', |
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.
😍
...blic/alerting/metric_threshold/components/custom_equation/custom_equation_editor.stories.tsx
Outdated
Show resolved
Hide resolved
...infra/public/alerting/metric_threshold/components/custom_equation/custom_equation_editor.tsx
Show resolved
Hide resolved
...infra/public/alerting/metric_threshold/components/custom_equation/custom_equation_editor.tsx
Outdated
Show resolved
Hide resolved
…stom-metric-editor-for-mtr
… changing to other aggreation types
Co-authored-by: Maryam Saeidi <maryam.saeidi@elastic.co>
@maryam-saeidi Thanks for the review! I've addressed all the issue you found. Please give it another review, thanks in advance. |
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: |
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.
Tested locally, and it worked as expected; fantastic job! 🎉
Just to double-check something here, when I test on a fresh instance everything is working fine, but when I use my oblt instance, I get the following error:
Is it because of some recent changes in this PR, so the rule that I created with the earlier version of this PR is not valid anymore? What can cause this issue? (Maybe it is not related to this PR at all ¯_(ツ)_/¯)
@maryam-saeidi That's an error in a different rule:
|
## Summary This PR closes elastic#145444 by adding a custom equation editor to the Metric Threshold rule. I also added support for custom metrics to the Metric Explorer API which powers the preview chart on the rule editor. Eventually we could do a follow up PR to the Metrics Explorer UI to expose this new functionality; which is outside the scope of this PR. ### Notable changes with this PR I changed the reason message for Metric Threshold rules which do not have a group by. The original message would say something like `system.cpu.user.pct is 82% in the last 1 min for all hosts. Alert when > 81%.` I removed the `for all hosts` portion because the Metric Threshold rule is not limited to just the concept of hosts, our users rely on this rule as their "Swiss Army Knife" rule for all types of data. I also had to change the format of the `currentPeriod` bucket for the Metric Threshold aggregation to support the "document count with KQL filter" use case. One of the requirements of a `filter` aggregation is that it must be a child of a multi-bucket aggregation. This is why I converted it from a 'filter' aggregation to a `filters` aggregation with an `all` key for the time range query. I added basic validation for the equations with a regular expression that just limits the characters to the allowable: `A-Z, +, -, /, *, (, ), ?, !, &, :, |, >, <, =`. I feel like for now this is good enough. If we want to expose some of the Painless `Math.*` libraries then we can follow up in a later release with a PegJS parser which would do some syntax validation as well. ### Rule with custom equation <img width="538" alt="image" src="https://user-images.githubusercontent.com/41702/213583128-1adbc405-828e-4571-aeb4-9900baeaabee.png"> ### Rule with custom ratio equation <img width="538" alt="image" src="https://user-images.githubusercontent.com/41702/213583239-a39d15d2-7023-4daf-af97-cb25a9965433.png"> ### Reason message with custom label ![image](https://user-images.githubusercontent.com/41702/211936062-4b696f0c-dfec-4e48-b89c-b0462fb5f7f0.png) --------- Co-authored-by: Carlos Crespo <crespocarlos@users.noreply.github.com> Co-authored-by: Maryam Saeidi <maryam.saeidi@elastic.co>
Summary
This PR closes #145444 by adding a custom equation editor to the Metric Threshold rule. I also added support for custom metrics to the Metric Explorer API which powers the preview chart on the rule editor. Eventually we could do a follow up PR to the Metrics Explorer UI to expose this new functionality; which is outside the scope of this PR.
Notable changes with this PR
I changed the reason message for Metric Threshold rules which do not have a group by. The original message would say something like
system.cpu.user.pct is 82% in the last 1 min for all hosts. Alert when > 81%.
I removed thefor all hosts
portion because the Metric Threshold rule is not limited to just the concept of hosts, our users rely on this rule as their "Swiss Army Knife" rule for all types of data.I also had to change the format of the
currentPeriod
bucket for the Metric Threshold aggregation to support the "document count with KQL filter" use case. One of the requirements of afilter
aggregation is that it must be a child of a multi-bucket aggregation. This is why I converted it from a 'filter' aggregation to afilters
aggregation with anall
key for the time range query.I added basic validation for the equations with a regular expression that just limits the characters to the allowable:
A-Z, +, -, /, *, (, ), ?, !, &, :, |, >, <, =
. I feel like for now this is good enough. If we want to expose some of the PainlessMath.*
libraries then we can follow up in a later release with a PegJS parser which would do some syntax validation as well.Rule with custom equation
Rule with custom ratio equation
Reason message with custom label