Skip to content
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

feature request - templated route matcher expressions #4032

Open
grozan opened this issue Sep 19, 2024 · 4 comments
Open

feature request - templated route matcher expressions #4032

grozan opened this issue Sep 19, 2024 · 4 comments

Comments

@grozan
Copy link

grozan commented Sep 19, 2024

Hi,

I see I can define matcher rules like this

route:
  routes:
    - matchers:
        - alertname =~ ".*foo.*"
      receiver: my_receiver

what I'd want would be the possibility to leverage the alerts' labels, and the available functions, to dynamically construct that regex with something like

route:
  routes:
    - matchers:
        - alertname =~ ".*{{ .CommonLabels.some_label  }}.*"
      receiver: my_receiver

and even

route:
  routes:
    - matchers:
        - alertname =~ ".*{{ .CommonLabels.some_label | reReplaceAll 'foo' 'bar'  }}.*"
      receiver: my_receiver

That would let admins define small but dynamic set of rules, that would let users tweak the behavior of the alerting system simply by defining the labels/values of their alerts

@dwilliams782
Copy link

Being able to set things like group_by, group_interval, repeat_interval dynamically in the routes based on labels would be extremely useful.

@grobinson-grafana
Copy link
Contributor

I don't understand how this would work? For example, CommonLabels does not exist until after an alert has matched a route, so it would be impossible for it to be used in the route definition.

@grozan
Copy link
Author

grozan commented Sep 20, 2024

@grobinson-grafana ah ok, sorry about that, was not aware of the CommonLabels thing. So it would be a different syntax, but hopefully the point is still clear enough

matcher rules compare a "property" of an alert, like its alertname, severity, other_label_the_alert_has, etc, with an expression.
The ask here is to be able to have dynamically computed expression strings (the right part), instead of hard-coded ones like the static .*foo.*, to make it possible to derive the expression string from the value of other_label_the_alert_has for example.

Terminology is certainly wrong, but hopefully it still makes sense

@grobinson-grafana
Copy link
Contributor

If I understand correct, you want to be able to do something like this:

route:
  routes:
    - matchers:
        - alertname =~ "foo{{ .Labels.bar  }}.*"

But I still don't quite understand what advantages this has for Alertmanager users?

However, the big problem is I think this will be almost impossible to implement for one simple reason. These regexes need to be compiled and cached in memory. Right now, the number of regexes is equal to the number of matchers in all routes. But if we need to recompile the regex for every alert, you could end up having to compile millions of regexes (suppose 10,000 alerts, 10 routes, 10 matchers each = 1,000,000 regular expressions). This would cause enormous CPU spikes and I just don't see how we could optimize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants