Prometheus promQL query is not showing 0 when metric data does not exists

Viewed 1044

Considering the simple promQL:

sum(metric_name{label="some label value"}) by (label, another_label)

I get this graph displayed: enter image description here I know that my metric_name has data for two label values for another_label, e.g. another value1 and another value2, but only the line for another value1 is displayed, because for this time interval, there is/might be no data for another value2.

What I want to achieve is to see the second line for another value2 displayed as 0. I tried:

sum(metric_name{label="some label value"} or on() vector(0)) by (label, another_label)

No luck, then I tried with a trick:

sum(
  metric_name{label="some label value"} 
  or (absent(metric_name{label="some label value", another_label="another value2"}) - 1)
) by (label, another_label)

This worked as expected: enter image description here But as you can imagine I don't want to manually chain these absent conditions for every existing label value of another_label, especially that I know that these won't be just two in reality.

  1. Can I somehow generalize the absent condition like or (absent(metric_name{label="some label value", another_label="<foreach>"}) - 1)?
  2. Is there some other way to fill these gaps with 0?
0 Answers
Related