Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prometheus Union of Ranged Vectors

I have two range vectors (# of hits and misses) that I want to aggregate by their types. Some of the types have hits, other misses, some with both. These are two independant metrics that I'm trying to get a union of but the resulting vector doesn't make sense. It's missing some of the values and I think it's because they have either all hits or misses. Am I doing this completely the wrong way?

sum by (type) (increase(metric_hit{}[24h]) + sum by (type) (increase(metric_miss{}[24h])
like image 275
szxnyc Avatar asked Jan 04 '23 20:01

szxnyc


1 Answers

First off, it's recommended to always initialise all your potential label values to avoid this sort of issue.

This can be handled with the or operator:

sum by (type) (
     (increase(metric_hit[1d]) or metric_miss * 0)
  + 
     (increase(metric_miss[1d]) or metric_hit * 0)
)
like image 165
brian-brazil Avatar answered Jan 14 '23 01:01

brian-brazil