PromQL "outer-join"-like behaviour

18 views Asked by At

Consider the metrics:

foo{a="a"} 1
foo{a="b"} 1
bar{a="b"} 1
bar{a="c"} 1

The query

sum by (a) (foo) + sum by (a) (bar)

returns

{a="b"} 2

What I would like is a query that will treat the absence of a given set of labels on the other side of the sum as 0. Essentially I need a query with the following result:

{a="a"} 1
{a="b"} 2
{a="c"} 1
1

There are 1 answers

0
markalex On BEST ANSWER

Prometheus is lacking outer join functionality. You can see very in-depth description of situation and possible workaround for left outer join from Brian Brazil here.

Based on the same logic full outer join for your example will look like this:

sum by (a) (foo) + sum by (a) (bar) #inner join
  or sum by (a) (foo) #with first line ~left outer join
  or sum by (a) (bar) #with first line ~right outer join