Commit Graph

6 Commits

Author SHA1 Message Date
Charles Korn
8d9dfa075d
promql: reuse histogramStatsIterator where possible, and expose it for other implementations to use (#16686)
* Expose type
* Add `Reset` method

---------

Signed-off-by: Charles Korn <charles.korn@grafana.com>
2025-06-18 23:53:46 +02:00
György Krajcsovits
bccb1d6459
fix(promql): do not loose information about buckets when doing the detect
Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
2025-06-04 10:24:50 +02:00
György Krajcsovits
df94ecebab
fix(promql): histogram_count inconsistent
The problem is in the counter reset detection. The code that loads the
samples is matrixIterSlice which uses the typed Buffer iterator, which
will preload the integer histogram samples, however the last sample is
always(!) loaded as a float histogram sample in matrixIterSlice and the
optimized iterator fails to detect counter resets in that case.

Also the iterator does not reset lastH, lastFH properly.

Ref: https://github.com/prometheus/prometheus/issues/16681

Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
2025-06-03 12:31:27 +02:00
Filip Petkovski
3e6155e596
Use CopyTo when resetting histogram in stats iterator
The histogram stats iterator does not fully clear the histogram object
and is not resilient to new fields being added to the histogram type.

To resolve the issue, the commit uses the CopyTo methods which should
be future proof to new fields being added.

Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
2024-07-31 11:18:47 +02:00
Filip Petkovski
be7a4c9b83
Ignore stale histograms for counter reset detection
The histogram stats decoder keeps track of the last seen histogram sample
in order to properly detect counter resets. We are seeing an issue where
a histogram with UnknownResetHint gets treated as a counter reset when it follows
a stale histogram sample.

I believe that this is incorrect since stale samples should be completely ignored
in PromQL. As a result, they should not be stored in the histogram stats iterator
and the counter reset detection needs to be done against the last non-stale sample.

Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
2024-07-26 10:08:31 +02:00
Filip Petkovski
6e68046c25
Implement histogram statistics decoder (#14097)
Implement histogram statistics decoder

This commit speeds up histogram_count and histogram_sum
functions on native histograms. The idea is to have separate decoders which can be
used by the engine to only read count/sum values from histogram objects. This should help
with reducing allocations when decoding histograms, as well as with speeding up aggregations
like sum since they will be done on floats and not on histogram objects.

Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>

---------

Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
Co-authored-by: Anthony Mirabella <a9@aneurysm9.com>
2024-06-06 17:17:13 +02:00