Fix similar issue for Next() as well.

Signed-off-by: Charles Korn <charles.korn@grafana.com>
This commit is contained in:
Charles Korn 2023-10-12 11:57:39 +11:00
parent 6976e003cb
commit 4bf8ec202c
No known key found for this signature in database
2 changed files with 29 additions and 1 deletions

View file

@ -576,7 +576,13 @@ func (c *chainSampleIterator) Next() chunkenc.ValueType {
// So, we don't call Next() on it here. // So, we don't call Next() on it here.
c.curr = c.iterators[0] c.curr = c.iterators[0]
for _, iter := range c.iterators[1:] { for _, iter := range c.iterators[1:] {
if iter.Next() != chunkenc.ValNone { if iter.Next() == chunkenc.ValNone {
if iter.Err() != nil {
// If any iterator is reporting an error, abort.
// If c.iterators[0] is reporting an error, we'll handle that below.
return chunkenc.ValNone
}
} else {
heap.Push(&c.h, iter) heap.Push(&c.h, iter)
} }
} }
@ -608,6 +614,9 @@ func (c *chainSampleIterator) Next() chunkenc.ValueType {
} }
// Current iterator does not hold the smallest timestamp. // Current iterator does not hold the smallest timestamp.
heap.Push(&c.h, c.curr) heap.Push(&c.h, c.curr)
} else if c.curr.Err() != nil {
// Abort if we've hit an error.
return chunkenc.ValNone
} else if len(c.h) == 0 { } else if len(c.h) == 0 {
// No iterator left to iterate. // No iterator left to iterate.
c.curr = nil c.curr = nil

View file

@ -1154,6 +1154,25 @@ func TestChainSampleIteratorSeekFailingIterator(t *testing.T) {
require.EqualError(t, merged.Err(), "something went wrong") require.EqualError(t, merged.Err(), "something went wrong")
} }
func TestChainSampleIteratorNextImmediatelyFailingIterator(t *testing.T) {
merged := ChainSampleIteratorFromIterators(nil, []chunkenc.Iterator{
NewListSeriesIterator(samples{fSample{0, 0.1}, fSample{1, 1.1}, fSample{2, 2.1}}),
errIterator{errors.New("something went wrong")},
})
require.Equal(t, chunkenc.ValNone, merged.Next())
require.EqualError(t, merged.Err(), "something went wrong")
// Next() does some special handling for the first iterator, so make sure it handles the first iterator returning an error too.
merged = ChainSampleIteratorFromIterators(nil, []chunkenc.Iterator{
errIterator{errors.New("something went wrong")},
NewListSeriesIterator(samples{fSample{0, 0.1}, fSample{1, 1.1}, fSample{2, 2.1}}),
})
require.Equal(t, chunkenc.ValNone, merged.Next())
require.EqualError(t, merged.Err(), "something went wrong")
}
func TestChainSampleIteratorSeekHistogramCounterResetHint(t *testing.T) { func TestChainSampleIteratorSeekHistogramCounterResetHint(t *testing.T) {
for sampleType, sampleFunc := range map[string]func(int64, histogram.CounterResetHint) chunks.Sample{ for sampleType, sampleFunc := range map[string]func(int64, histogram.CounterResetHint) chunks.Sample{
"histogram": func(ts int64, hint histogram.CounterResetHint) chunks.Sample { return histogramSample(ts, hint) }, "histogram": func(ts int64, hint histogram.CounterResetHint) chunks.Sample { return histogramSample(ts, hint) },