Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nesting query in promQL

I am looking for the output of metric 'prom_metric2' where input label is 'label2' the value of which has to be taken from metric 'prom_metric1'.

i.e. for followng input query:

prom_metric1{label1="A"}

Output time series is :

prom_metric1{label1="A",label2="B",label3="C"}
prom_metric1{label1="A",label2="D",label3="E"}

Now, the following metric should take all the values of label2 from above time series and then show the output.

prom_metric2{label2="LABEL_FROM_PROM_METRIC1 i.e. B and D"}

It is equivalent to following SQL query :

Select * from prom_metric2 where label2 IN (Select label2 from prom_metric1 where label1='A')

Is this possible in promQL?

Thanks in advance.

like image 283
Harshit Goel Avatar asked Sep 06 '25 23:09

Harshit Goel


1 Answers

The below solution is working fine :

prom_metric2 {some_label="value"} and on (label2 ) prom_metric1 {label1='A'}

References: https://www.robustperception.io/exposing-the-software-version-to-prometheus

https://prometheus.io/docs/prometheus/latest/querying/operators/#many-to-one-and-one-to-many-vector-matches

like image 180
Harshit Goel Avatar answered Sep 11 '25 03:09

Harshit Goel