mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 05:34:05 -08:00
Merge pull request #12264 from rabenhorst/sample-ring-iterator-mixed-histograms-fix
Fix for `sampleRingIterator` with mixed histograms
This commit is contained in:
commit
78cd9ae2c3
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue