How do you filter a Prometheus metric based on the existence of a label in another metric?

31 Views Asked by At

I would like to filter a query to only values in a metric where a label for that metric exists as a label in another metric. In SQL this would look like:

SELECT * FROM metric1 where metric1.label1 IN (SELECT label2 from metric2);

Is this possible in PromQL?

I have tried using the ON operator, but this doesn't seem to do what I intend.

1

There are 1 best solutions below

0
Robert On

I was able do what I wanted using label_replace (thank you markalex).

metric1 and on (label1) label_replace(metric2, label1, "$1", label2, "(.+)")