outer join

80 views
Skip to first unread message

Daniele

unread,
Sep 23, 2020, 8:29:24 AM9/23/20
to Prometheus Users
Hello!
I've a query that looks like so:

 
max by (  cluster_id, email_domain,  risk ) (
                subscription_labels{email_domain!~"google.com"} + on (cluster_id) group_left(_ignore)  
                (0 * topk by (cluster_id) (1, cluster_version{version=~"4.[2-9].*",type="current"}) )
            )

problem is:
if a cluster is not present in cluster_version{} it will not be returned by the query.
In other words let's assume that there's a cluster with id "123" that is not present in cluster version (that is the query cluster_version{cluster_id="123"} returns 0 results) and a cluster with id="555" that has version="0.1.1" . I want the query to discard the cluster 555 and return 123 (the version is unknown in this case).

How can I achieve this?

I tried the following query:

max by (  cluster_id, email_domain,  risk ) (
                subscription_labels{email_domain!~"google.com"} + on (cluster_id) group_left(_ignore)  
                (0 * topk by (cluster_id) (1, cluster_version{version=~"4.[2-9].*",type="current"}) )
            ) or on (cluster_id) subscription_labels

but it returns much more records (like 40220 vs 16922) than the query:

max by (  cluster_id, email_domain,  risk ) (
                subscription_labels{email_domain!~"google.com"}
            )

So I guess something is wrong.

Thanks for the help,
Daniele

Brian Candler

unread,
Sep 23, 2020, 1:05:13 PM9/23/20
to Prometheus Users
https://www.robustperception.io/left-joins-in-promql

Build the query up in steps.  I am guessing you want the "or on" condition inside the max by, not outside it.

Daniele

unread,
Sep 24, 2020, 7:57:43 AM9/24/20
to Prometheus Users
Thanks for the reply!

I solved now, for the future readers the correct way is this one:

            max by (
                _id, account, ebs_account, email_domain, external_organization,
                managed, support, risk
            ) (
                subscription_labels{email_domain!~"google.com"} } + on (_id) group_left(_ignore)
                (0 * topk by (_id) (1, cluster_version{{version=~"4.[2-9].*",type="current"}}))
                or on (_id) subscription_labels{email_domain!~"google.com"} }
            )
Reply all
Reply to author
Forward
0 new messages