I have following PromQL metric structures
metric1{label_1="a",label_2="b",...,status="running"} value = 0
metric1{label_1="a",label_2="b",...,status="running"} value = 1
metric2{label_1="a",label_2="b",...,status="healthy"} value = 0
metric2{label_1="a",label_2="b",...,status="healthy"} value = 1
I want to select only metrics with specific value and merge these metrics into this structure
resultmetric{label_1="a",label_2="b",...,metric1_status="running", metric2_status="healthy"}
What is the correct PromQL query? I tried queries with group_left() and on() but no luck.
The main roadblock you are probably hitting is the fact that the in both metrics you have the
statuslabel which is different AND the one you want to replicate. Prometheus won't be able resolve it while the label names collide.The first thing you want to do is generate a new timeseries with a different label name for the second
status. You can do this by usinglabel_replace. For example:This will keep the
statuslabel but will also add ametric2_statuswith the value of thestatuslabel.Now you can proceed to use
on()andgroup_left(). These need to be used with an arithmetic or group function. If you are using this to add more labels to metric1, remember to use an arithmetic that will not alter the metric value.For example - assuming metric2 has always a value of 1 - this is what you could use:
the resulting metric should have
metric1's labels plus themetric2_statuslabel.