I have this metric: task_code{pod="foobar"} 9
I am trying to write an expression to check the value of the mentioned metric to raise an alert as the value of the above metric can be any number.
I can do the following but the values to be matched are plenty.
(task_code{pod="foobar"} == 9 or task_code{pod="foobar"} == 15 or task_code{pod="foobar"} == 29)
But looks like regex can only be applied on a label value and Not on a metric value.
I tried exploring the label_replace function to create a new label out of the metric value but no go.
Looking to have something like
task_code{pod="foobar"} in [9,15,29]
or
task_code{pod="foobar"} =~ "(9|15|29)"
Any pointer is really appreciated.
I suspect that your metric is an anti-pattern and, rather than try to force Prometheus into this somewhat unnatural behavior, you should reconsider the metric (if possible).
Measurements (counters, gauges) etc. should be continuous.
Corollary: measurements that are discrete values (and I think
codeis a smell here) should be label values.Unless you can correct the metric, you're limited to PromQL Operators and I suspect you'll be limited to enumerating the many conditions:
task_code{foo="..."}=={value} or ...