I want to check if value for the metric is above threshold for a metric with a specific values in a label. I have a long list of those values (~30), and only those.
a_metric_total {alabel="foo"} >= 1
alabel can be foo, foobar, bar, (but not barfoo
, so I don’t want to use regexp).
I wanted something like this:
a_metric_total {alabel in ["foo", "bar", "foobar"]} >= 1
Is there a way to do in
operation for a label and a set/list of constants?
>Solution :
Correct way to select metrics based on multiple values of label are regex.
So for your example this query will return what you describe:
a_metric_total{alabel=~"foo|bar|foobar"} >= 1
Please note, that regex selectors for labels are fully anchored (so selector in example is equivalent to ^(foo|bar|foobar)$
) and thus no partial matching is occurring. For regex selector in promql to partially match you need to manually specify that: .*foo.*|.*bar.*
will match any label containing "foo" or "bar", but foo|bar
matches only "foo" or "bar", but not "foobar".