Repository navigation
model/histogram: preserve integer cumulative counts in classic conversion - #20330
Conversation
| } | ||
| } | ||
|
|
||
| func TestEngine_NativeHistogramsAsClassicIntegerPrecision(t *testing.T) { |
There was a problem hiding this comment.
Since the fix is entirely in histogram.ClassicBucketCounts in model/histogram/convert.go, could we move these precision and uint64 boundary test cases into model/histogram/convert_test.go (where ClassicBucketCounts and dirty buf reuse are already unit-tested) instead of spinning up a TSDB and PromQL engine per subtest here?
There was a problem hiding this comment.
Moved the precision and uint64 boundary cases to model/histogram/convert_test.go. They now call ClassicBucketCounts directly with prefilled buffers and floating-histogram controls, without constructing a TSDB or PromQL engine per subtest.
| {"empty", []int64{0, 0, 0}}, | ||
| {"small", []int64{0, 10, 0, 1, 0}}, | ||
| {"below_float_precision", []int64{1<<53 - 1, 1, 1, 1, 0}}, | ||
| {"at_float_precision", []int64{1 << 53, 1, 1, 0}}, |
There was a problem hiding this comment.
In the 1<<53 cases all non-zero counts are contiguous, so sparse=true only trims the trailing +Inf bucket and never exercises an inter-span s.Offset > 0 gap while holding an odd prefix like 1<<53 + 1. Worth putting an empty bucket between the +1 increments here too:
| {"at_float_precision", []int64{1 << 53, 1, 1, 0}}, | |
| {"at_float_precision", []int64{1 << 53, 1, 0, 1, 0}}, |
There was a problem hiding this comment.
Added the suggested empty bucket between the +1 increments. The sparse case now crosses an inter-span gap with an exact prefix of 1<<53 + 1 before the next increment.
Signed-off-by: Perfloop Agent <[email protected]>
…unding Signed-off-by: Perfloop Agent <[email protected]>
964ce65 to
b9facde
Compare
The NHCB-as-classic queries added in #18048 can lose small bucket increments at large integer counts, leaving
+Infbelow_count. Accumulate integer prefixes before rounding each classic bucket value to avoid this intermediate precision loss.Which issue(s) does the PR fix:
Related to #16948.
ClassicBucketCountsnow accumulates integer bucket prefixes inuint64. Empty buckets retain the preceding cumulative count, including across sparse spans and after the last populated bucket. The shared helper serves both PromQL compatibility queries and remote-write conversion; floating-histogram summation, validation, labels, count and sum are unchanged.The precision and integer-boundary cases are in
model/histogram/convert_test.go, alongside the existing conversion tests. They check dense and sparse layouts throughMaxUint64, floating-histogram controls, and prefilled output buffers. An empty bucket between the small increments exercises an inter-span gap while the exact prefix is odd.Go tests passed for histogram conversion and precision, classic storage selectors, remote-write conversion, and PromQL compatibility. Scoped Go lint passed.
Prefixes not representable as
float64still round. PromQL conversion still requirespromql-native-histograms-as-classicto be enabled.Related work: #19881 and #19886 also change the compatibility conversion path.
Release notes for end users (ALL commits must be considered).
Reviewers should verify clarity and quality.
Case and evidence
Made by Perfloop.