Browse Source

Fixed sampleRingIterator for mixed histograms

Signed-off-by: Sebastian Rabenhorst <sebastian.rabenhorst@shopify.com>

Fixed sampleRingIterator for mixed histograms

Signed-off-by: Sebastian Rabenhorst <sebastian.rabenhorst@shopify.com>

Fixed lint
pull/12264/head
Sebastian Rabenhorst 2 years ago
parent
commit
5d4ec08a1f
No known key found for this signature in database
GPG Key ID: A55E83DA58D397EF
  1. 2
      storage/buffer.go
  2. 23
      storage/buffer_test.go

2
storage/buffer.go

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

23
storage/buffer_test.go

@ -21,6 +21,7 @@ import (
"github.com/prometheus/prometheus/model/histogram" "github.com/prometheus/prometheus/model/histogram"
"github.com/prometheus/prometheus/tsdb/chunkenc" "github.com/prometheus/prometheus/tsdb/chunkenc"
"github.com/prometheus/prometheus/tsdb/tsdbutil"
) )
func TestSampleRing(t *testing.T) { func TestSampleRing(t *testing.T) {
@ -180,6 +181,28 @@ func TestBufferedSeriesIteratorNoBadAt(t *testing.T) {
it.Next() 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) { func BenchmarkBufferedSeriesIterator(b *testing.B) {
// Simulate a 5 minute rate. // Simulate a 5 minute rate.
it := NewBufferIterator(newFakeSeriesIterator(int64(b.N), 30), 5*60) it := NewBufferIterator(newFakeSeriesIterator(int64(b.N), 30), 5*60)

Loading…
Cancel
Save