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
This was super helpful for me, thanks! However, I did notice that
my_metric{Lable_1=~"A"|"B"|"C"}
should be:
my_metric{Lable_1=~"A|B|C"}
so the whole regex is quoted and not just the values. It explains it in the link you shared, but saves one more click for others 