Fix sample deduplication in chainSampleIterator

Fixes https://github.com/prometheus/prometheus/issues/8558

Signed-off-by: Julius Volz <julius.volz@gmail.com>
This commit is contained in:
Julius Volz 2021-03-12 12:32:15 +01:00
parent 82ffdae1f3
commit cf4250cff3
2 changed files with 9 additions and 0 deletions

View File

@ -467,6 +467,7 @@ func (c *chainSampleIterator) Seek(t int64) bool {
} }
if len(c.h) > 0 { if len(c.h) > 0 {
c.curr = heap.Pop(&c.h).(chunkenc.Iterator) c.curr = heap.Pop(&c.h).(chunkenc.Iterator)
c.lastt, _ = c.curr.At()
return true return true
} }
c.curr = nil c.curr = nil

View File

@ -647,6 +647,14 @@ func TestChainSampleIteratorSeek(t *testing.T) {
seek: 2, seek: 2,
expected: []tsdbutil.Sample{sample{2, 2}, sample{3, 3}, sample{4, 4}, sample{5, 5}}, expected: []tsdbutil.Sample{sample{2, 2}, sample{3, 3}, sample{4, 4}, sample{5, 5}},
}, },
{
input: []chunkenc.Iterator{
NewListSeriesIterator(samples{sample{0, 0}, sample{2, 2}, sample{3, 3}}),
NewListSeriesIterator(samples{sample{0, 0}, sample{1, 1}, sample{2, 2}}),
},
seek: 0,
expected: []tsdbutil.Sample{sample{0, 0}, sample{1, 1}, sample{2, 2}, sample{3, 3}},
},
} { } {
merged := newChainSampleIterator(tc.input) merged := newChainSampleIterator(tc.input)
actual := []tsdbutil.Sample{} actual := []tsdbutil.Sample{}