PromQL - Possible to query label by list of values?

Is is possible in PromQL to query a label with a list of values? For example this is a how you’d do it in SQL:

SELECT *
FROM my_table
WHERE column_1 IN ('A', 'B', 'C')

Is there a similar syntax in PromQL? I would have imagined something like this:

my_metric{Lable_1=["A", "B", "C"]}

You would use the regex match operator =~ like this:

my_metric{Lable_1=~"A"|"B"|"C"}

If you use a Grafana list of values variable then it’s:

my_metric{Lable_1=~"$MyVariable"}

If you set a Custom all value of .* in your variable it may help performance if you have a long list of values.

More info:
https://prometheus.io/docs/prometheus/latest/querying/basics/

1 Like