Merge pull request #12264 from rabenhorst/sample-ring-iterator-mixed-histograms-fix

Fix for `sampleRingIterator` with mixed histograms
This commit is contained in:
Björn Rabenstein 2023-04-20 16:58:18 +02:00 committed by GitHub
commit 78cd9ae2c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View file

@ -332,9 +332,11 @@ func (it *sampleRingIterator) Next() chunkenc.ValueType {
switch s.Type() {
case chunkenc.ValHistogram:
it.h = s.H()
it.fh = nil
return chunkenc.ValHistogram
case chunkenc.ValFloatHistogram:
it.fh = s.FH()
it.h = nil
return chunkenc.ValFloatHistogram
default:
it.f = s.F()

View file

@ -21,6 +21,7 @@ import (
"github.com/prometheus/prometheus/model/histogram"
"github.com/prometheus/prometheus/tsdb/chunkenc"
"github.com/prometheus/prometheus/tsdb/tsdbutil"
)
func TestSampleRing(t *testing.T) {
@ -180,6 +181,28 @@ func TestBufferedSeriesIteratorNoBadAt(t *testing.T) {
it.Next()
}
func TestBufferedSeriesIteratorMixedHistograms(t *testing.T) {
histograms := tsdbutil.GenerateTestHistograms(2)
it := NewBufferIterator(NewListSeriesIterator(samples{
fhSample{t: 1, fh: histograms[0].ToFloat()},
hSample{t: 2, h: histograms[1]},
}), 2)
require.Equal(t, chunkenc.ValNone, it.Seek(3))
require.NoError(t, it.Err())
buf := it.Buffer()
require.Equal(t, chunkenc.ValFloatHistogram, buf.Next())
_, fh := buf.AtFloatHistogram()
require.Equal(t, histograms[0].ToFloat(), fh)
require.Equal(t, chunkenc.ValHistogram, buf.Next())
_, fh = buf.AtFloatHistogram()
require.Equal(t, histograms[1].ToFloat(), fh)
}
func BenchmarkBufferedSeriesIterator(b *testing.B) {
// Simulate a 5 minute rate.
it := NewBufferIterator(newFakeSeriesIterator(int64(b.N), 30), 5*60)