From b8b0d45d6982a1587acb669409982b6917620db0 Mon Sep 17 00:00:00 2001 From: Ganesh Vernekar Date: Wed, 30 Nov 2022 17:49:33 +0530 Subject: [PATCH] Fix reset of a histogram chunk iterator Signed-off-by: Ganesh Vernekar --- tsdb/chunkenc/histogram.go | 4 ++-- tsdb/chunkenc/histogram_test.go | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tsdb/chunkenc/histogram.go b/tsdb/chunkenc/histogram.go index 6e326888a..e57b96db9 100644 --- a/tsdb/chunkenc/histogram.go +++ b/tsdb/chunkenc/histogram.go @@ -624,9 +624,9 @@ func (it *histogramIterator) Err() error { } func (it *histogramIterator) Reset(b []byte) { - // The first 2 bytes contain chunk headers. + // The first 3 bytes contain chunk headers. // We skip that for actual samples. - it.br = newBReader(b[2:]) + it.br = newBReader(b[3:]) it.numTotal = binary.BigEndian.Uint16(b) it.numRead = 0 diff --git a/tsdb/chunkenc/histogram_test.go b/tsdb/chunkenc/histogram_test.go index 1a187667c..09c08ae3c 100644 --- a/tsdb/chunkenc/histogram_test.go +++ b/tsdb/chunkenc/histogram_test.go @@ -84,14 +84,14 @@ func TestHistogramChunkSameBuckets(t *testing.T) { require.Equal(t, exp, act) // 2. Expand second iterator while reusing first one. - // it2 := c.Iterator(it1) - // var res2 []pair - // for it2.Next() { - // ts, v := it2.At() - // res2 = append(res2, pair{t: ts, v: v}) - // } - // require.NoError(t, it2.Err()) - // require.Equal(t, exp, res2) + it2 := c.Iterator(it) + var res2 []res + for it2.Next() == ValHistogram { + ts, h := it2.AtHistogram() + res2 = append(res2, res{t: ts, h: h}) + } + require.NoError(t, it2.Err()) + require.Equal(t, exp, res2) // 3. Test iterator Seek. // mid := len(exp) / 2