'Using vector(0) to avoid empty query result creates incorrect graph

I have a query that sums up all the results for different labels in such a way:

sum (label=~{"regex"}) + sum (label=~{"regex"}) + ...

However, some labels have no result and if added as above they return an empty query result instead of 0, invalidating the whole query.

As a workaround I added the following:

sum (label=~{"regex"} or vector(0)) + sum (label=~{"regex"} or vector(0)) + ...

However, now this gives me a different graph on Grafana and Prometheus than I was expecting. It registers the 0s instead of the actual value.

Incorrect Grafana Graph

Incorrect Prometheus Graph

I have a similar Prometheus and Grafana with the same query, however, that returns the right graph for Grafan, even if in the Prometheus it also records the 0s.

Correct Prometheus Graph

Correct Grafana Graph

My question is how can I make the first graph become like the 2nd one just registering the actual values instead of these 0 that I'm assuming they come from the use of "or vector(0)" in the query.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source