prometheus: Some aggregations and functions produce incorrect results for native histograms
Currently there are some operators and aggregations that produce either incorrect or inconsistent results for native histograms in some cases. Which are-
| Args | Current Behaviour | Expected Behaviour | Status | |
|---|---|---|---|---|
+ and - |
float, histogram in any order |
returns float |
no result, add info annotation | |
* and / |
histogram, histogram |
returns float |
no result, add info annotation | |
/ |
float, histogram (in this order! histogram, float is fine) |
returns float ignoring histogram |
no result, add info annotation | |
/ |
histogram, 0 |
returns histogram with every value divided by zero |
return histogram with sum and count as NaN or Inf and all buckets removed |
|
min/max/quantile |
combination of histogram and float |
returns scalar by taking histogram as 0 |
return min/max/quantile of all the floats and add info annotation |
|
min/max/quantile |
only histogram |
returns scalar by taking histogram as 0 |
no result, add info annotation | |
stdvar, stddev |
combination of histogram and float |
ignores histogram and only processes floats | no change in result but add info annotation | |
stdvar, stddev |
only histogram |
no result | no result, add info annotation | |
== and != without bool modifier |
float, histogram in any order |
treat histogram as 0, return either histogram or float depending on order if the comparison is true |
no result, add info annotation | |
== and != without bool modifier |
histogram, histogram |
treat both histograms as 0, return nothing for != and the first(?) histogram for == |
check histograms for (in)equality, return the first histogram if the check is true |
|
>, <, <=, >= without bool modifier |
histogram on either or both sides |
treat histogram as 0, return value depends on order |
no result, add info annotation | |
count_values |
combination of histogram and float |
treat histogram as 0 |
use the string representation of histogram | |
topk, bottomk |
combination of histogram and float |
treat histogram as 0 |
ignore histogram, add info annotation |
|
limitk, limit_ratio |
combination of histogram and float |
treat histogram as 0 |
add histogram to the result if applicable |
|
sum_over_time, avg_over_time |
combination of histogram and float in one range |
no result, add warn annotation | no result, add warn annotation (i.e. already correct, but we should add tests) | |
min_over_time, max_over_time, quantile_over_time, stddev_over_time, stdvar_over_time, mad_over_time,deriv, double_exponential_smoothing, predict_linear |
combination of histogram and float in one range |
ignore histogram | ignore histograms, calculate results just for the floats in the range, add info annotation | |
min_over_time, max_over_time, quantile_over_time, stddev_over_time, stdvar_over_time, mad_over_time,deriv, double_exponential_smoothing, predict_linear |
only histograms in one range | ignore | ignore (i.e. already correct, but we should add tests) | |
idelta, irate |
the last two samples in range are both histograms | no result | calculate result corresponding to delta/rate, including annotation about applying idelta to counter histogram and irate to gauge histogram |
|
idelta, irate |
the last two samples in range are a histogram and a float sample | ignore histogram | no result, add warn annotation | |
sort, sort_by_desc, scalar |
histogram | treat histogram as 0 float |
ignore histogram silently (which might, in the case of scalar, result in fulfilling the condition of exactly one (float) sample in the input vector) |
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 48 (48 by maintainers)
Commits related to this issue
- docs: Update PromQL documentation to match the native histogram spec This is also meant to document the actual implementation, but see #13934 for the current state. Signed-off-by: beorn7 <beorn@graf... — committed to prometheus/prometheus by beorn7 2 years ago
- docs: Update PromQL documentation to match the native histogram spec This is also meant to document the actual implementation, but see #13934 for the current state. Signed-off-by: beorn7 <beorn@graf... — committed to prometheus/prometheus by beorn7 2 years ago
- docs: Update PromQL documentation to match the native histogram spec This is also meant to document the actual implementation, but see #13934 for the current state. Signed-off-by: beorn7 <beorn@graf... — committed to prometheus/prometheus by beorn7 2 years ago
- docs: Update PromQL documentation to match the native histogram spec This is also meant to document the actual implementation, but see #13934 for the current state. Signed-off-by: beorn7 <beorn@graf... — committed to prometheus/prometheus by beorn7 2 years ago
- docs: Update PromQL documentation to match the native histogram spec This is also meant to document the actual implementation, but see #13934 for the current state. This also improves and streamline... — committed to prometheus/prometheus by beorn7 2 years ago
- docs: Update PromQL documentation to match the native histogram spec This is also meant to document the actual implementation, but see #13934 for the current state. This also improves and streamline... — committed to francoposa/prometheus by beorn7 2 years ago
Which is done now.
I think we are done here! 🎉
Special thanks to @NeerajGartia21 who dutifully hunted down all of these.
Quoting from https://github.com/prometheus/docs/pull/2539 : “All remaining functions not mentioned in this section do not work with native histograms. Histogram elements in the input vector are silently ignored.”
So yes, the intended behavior is to not add any annotations in those cases.
I’ve updated the table for the above aggregations. Please have a look!
Yes. Just trying to say that my thoughts are expressed in that document. If my thoughts match your thoughts, you could just update it in the table. If you have any concerns, let’s discuss here in more detail.
I’d like to challenge the last line “>, <, <=, >= without bool modifier” . Especially because we have clamp function and also the proposed trim (>/) functions, I think it would make sense to interpret conditions like this (using “<” for example).
histogram < float would mean all observations are below the float value float < histogram would mean the float is below all observations in the histogram
histogram < histogram would return nothing and warning. There’s probably a way to define this as well to mean more observations are higher in the right side - the trivial case being that all observations are higher in the right side.
Yes, the table is certainly not complete yet. Please amend as you see fit.
I don’t think we are ignoring histograms in
sumand+:For the
sumaggregation, we do not ignore histograms. For any result that would require the aggregation of histograms and floats, we return nothing (remove that group from the result), and attach a warning annotation.For the
+binop (I guess that’s what you mean by “add operator”), we also remove results that try to add a histogram to a float, but since it is a binop, it’s plausible that this could be used as an intended filtering, so we only attach an info annotation.I’m not 100% confident that this is the best approach, but we discussed it before, and this is the outcome as I understood it:
If we have new evidence that this is not a good plan, we can revise it. But for now, I think the aggregation case is indeed much different from the binop case. Aggregation is “worse” indeed as you could really aggregate a lot of histograms, and a single float accidentally sneaking in will kill that whole aggregation group (thereby possible preventing your alert from firing). With a binop, the collisions could still be accidental, of course, but you are only ever matching two elements, so it’s much easier to keep under control. It’s also “normal” in binops that elements disappear that do not label-match, so one might argue the histogram/float property behaves just like a label here. Plus, as said above, even relying on the behavior on purpose (for filtering) is a much more plausible approach than it would be with aggregations.
I’ve added a status column to the table ! And I’ve started working on the remaining tasks.
Your reasoning in https://github.com/prometheus/prometheus/issues/13934#issuecomment-2328272160 makes sense to me - I’ll update #14821 to match this.
https://github.com/prometheus/prometheus/pull/14821 might also be relevant to this issue.
That’s also an option. If I understand you correctly, you would add an info annotation to the
2 / fooexpression iffoocontains both histograms and floats (so something is returned) but iffoois a pure histogram vector, you would add a warning annotation (because nothing is returned). That might be hard to implement (you can only decide about the level of the annotation when looking at the whole vector), but maybe it’s doable. I’m a bit more concerned about the change of behavior that a “float divided by histogram” operation becomes “more bad” if the histogram is not accompanied by a float in the same vector.Another thought in this regard: A mix of floats and histograms in the same vector should be a very rare case. So maybe we don’t need to think too much about treating that case specially or with concerns about spammy annotations. It shouldn’t really happen in practice, and if it does, it’s probably a faulty setup or a transition period and will be fixed soon. So maybe let’s say for now, whenever we ignore a histogram in an operation because it doesn’t make sense, we add an info-level annotation saying that an operation wasn’t performed, even if the expression still yields a result from other vector elements. We can do this first, it’s easy, and then iterate on it once we see how it plays out in practice.