4

I'm trying to define an alert rule with "expr" containing regular-expression

Metric: XYZ-POST-failure-400-1min-rate

- alert: alert_name_here
  expr: __name__=~"(.*)-POST-failure-\d{3}-1min-rate" > 0

Unit testing this using "promtool"

Error
group "group_name", rule 1, "alert_name_here": could not parse expression: parse error at char 10: unexpected character after '=': '~'

Is this even supported by Prometheus alert manager? Can someone guide me on what is the correct way to achieve this?

Thank you

user2922123
  • 51
  • 1
  • 2

2 Answers2

4

The expression should be a valid PromQL query, you are missing the curly braces to make it a valid vector selector:

{__name__=~"(.*)-POST-failure-\d{3}-1min-rate"} > 0

You can test it in your Prometheus interface.

Regarding the YAML issue of having a leading curly brace, you can use single quotes for which the special character sequences are allowed:

- alert: alert_name_here
  expr: '{__name__=~"(.*)-POST-failure-\d{3}-1min-rate"} > 0'
Michael Doubez
  • 5,937
  • 25
  • 39
0

I had a very similar error when I twisted the =~ with ~=.

parse error: unexpected character inside braces: '~'

This kind of errors are hard to spot and the error message is not that helpful.

konkit
  • 349
  • 5
  • 11