left join queries with different labels

29 views
Skip to first unread message

nesa...@gmail.com

unread,
Sep 28, 2020, 1:54:19 PM9/28/20
to Prometheus Users
Hi
I would like to join two queries, one of them has labeled "exported_namespace" and "route", while the other one has "namespace" and "route" and "host"
Now I want to join these two queries so that "exported_namespace" from the first query should match "namespace" from the second query, and "route" from the first query should match "route" from the second query and the final metric should have labeled "exported_namespace" (or "namespace"), "route" and "host". 
I've already tried this query but it didn't give me any answer:
haproxy_server_http_responses_total * on(exported_namespace, route) openshift_route_info

BTW, the first metric also has a label named "namespace" but the value is irrelevant to the actual namespace I'm looking for

Sohaib Omar

unread,
Sep 28, 2020, 3:18:40 PM9/28/20
to nesa...@gmail.com, Prometheus Users
Hi,
I guess you would need to rename the namespace label of the second query to exported_namespace. or vice versa.
try this example
thanks

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/810c860d-8bcc-4538-b38e-d8e3fe1b767fn%40googlegroups.com.

nesa...@gmail.com

unread,
Sep 28, 2020, 3:24:56 PM9/28/20
to Prometheus Users
Thanks for your reply, this query works for me:
sum((sum without(exported_namespace) (label_replace(irate(haproxy_server_http_responses_total[5m]), "namespace", "$1", "exported_namespace","(.*)")))* on(namespace, route) group_left(host) openshift_route_info) by (code, namespace, route, host)

Brian Candler

unread,
Sep 28, 2020, 3:29:46 PM9/28/20
to Prometheus Users
A join needs matching label names.  Try using label_replace on one side, e.g.

haproxy_server_http_responses_total * on(exported_namespace, route) label_replace(openshift_route_info, "exported_namespace", "$1", "namespace", "(.+)")

Once that's working, then you can add group_left(...) or group_right(...) as required. See:


Reply all
Reply to author
Forward
0 new messages