Merge the labels on the quary

144 views
Skip to first unread message

MohammdReza MollaSalehi

unread,
Jun 9, 2023, 8:50:09 AM6/9/23
to Prometheus Users
Hi everyone
I want to merge the labels of two query in each other, so I am using this query:

quary1{label_for_both,label_just_in_quary1} * ignore(label_just_in_quary1) group_left() quary2{label_for_both}

After using this query, I found out the entries not in the second query were removed, so I added `or` like this quarry:

(quary1{label_for_both,label_just_in_quary1} * ignore(label_just_in_quary1) group_left() quary2{label_for_both}) or quary1{label_for_both,label_just_in_quary1}

As a result, I have duplicate entries anyone has any suggestions to remove duplicates?

Brian Candler

unread,
Jun 9, 2023, 10:02:10 AM6/9/23
to Prometheus Users
It would be much easier to help you if you gave real examples, with real metrics.

The expression you have given can't possibly give "duplicate" entries.  However, you could end up with entries with different sets of labels, e.g.

mymetric{label1="foo",label2="bar"}
mymetric{label1="foo",label2="bar",label3="baz"}

You can most likely use "or on(...)" or "or ignoring(...)" to avoid this problem - again, it depends on the exact details of your metrics and their labels.

There are some concrete examples which may help you here:

MohammdReza MollaSalehi

unread,
Jun 10, 2023, 5:27:52 AM6/10/23
to Brian Candler, Prometheus Users
Thanks Brian
Issue solved by
on(...) 
Reply all
Reply to author
Forward
0 new messages