Fix issue where consumers of chainSampleIterator.Seek() can ignore errors

Signed-off-by: Charles Korn <charles.korn@grafana.com>
This commit is contained in:
Charles Korn 2023-10-11 15:16:17 +11:00
parent 56e19def27
commit 6976e003cb
No known key found for this signature in database
2 changed files with 48 additions and 1 deletions

View file

@ -497,7 +497,12 @@ func (c *chainSampleIterator) Seek(t int64) chunkenc.ValueType {
c.consecutive = false
c.h = samplesIteratorHeap{}
for _, iter := range c.iterators {
if iter.Seek(t) != chunkenc.ValNone {
if iter.Seek(t) == chunkenc.ValNone {
if iter.Err() != nil {
// If any iterator is reporting an error, abort.
return chunkenc.ValNone
}
} else {
heap.Push(&c.h, iter)
}
}

View file

@ -1144,6 +1144,16 @@ func TestChainSampleIteratorSeek(t *testing.T) {
}
}
func TestChainSampleIteratorSeekFailingIterator(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.Seek(0))
require.EqualError(t, merged.Err(), "something went wrong")
}
func TestChainSampleIteratorSeekHistogramCounterResetHint(t *testing.T) {
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) },
@ -1539,3 +1549,35 @@ func TestMergeGenericQuerierWithSecondaries_ErrorHandling(t *testing.T) {
})
}
}
type errIterator struct {
err error
}
func (e errIterator) Next() chunkenc.ValueType {
return chunkenc.ValNone
}
func (e errIterator) Seek(t int64) chunkenc.ValueType {
return chunkenc.ValNone
}
func (e errIterator) At() (int64, float64) {
return 0, 0
}
func (e errIterator) AtHistogram() (int64, *histogram.Histogram) {
return 0, nil
}
func (e errIterator) AtFloatHistogram() (int64, *histogram.FloatHistogram) {
return 0, nil
}
func (e errIterator) AtT() int64 {
return 0
}
func (e errIterator) Err() error {
return e.err
}