diff --git a/pkg/dedup/merge_iter.go b/pkg/dedup/merge_iter.go index 786a021b6a2..7ccf1ebf83d 100644 --- a/pkg/dedup/merge_iter.go +++ b/pkg/dedup/merge_iter.go @@ -92,18 +92,23 @@ func (m *mergedSeriesIterator) At() (t int64, v float64) { return m.lastIter.At() } -func (it *mergedSeriesIterator) AtHistogram(h *histogram.Histogram) (int64, *histogram.Histogram) { - return it.lastIter.AtHistogram(h) +func (m *mergedSeriesIterator) AtHistogram(h *histogram.Histogram) (int64, *histogram.Histogram) { + return m.lastIter.AtHistogram(h) } -func (it *mergedSeriesIterator) AtFloatHistogram(fh *histogram.FloatHistogram) (int64, *histogram.FloatHistogram) { - return it.lastIter.AtFloatHistogram(fh) +func (m *mergedSeriesIterator) AtFloatHistogram(fh *histogram.FloatHistogram) (int64, *histogram.FloatHistogram) { + return m.lastIter.AtFloatHistogram(fh) } -func (it *mergedSeriesIterator) AtT() int64 { - return it.lastT +func (m *mergedSeriesIterator) AtT() int64 { + return m.lastT } +// Err All At() funcs should panic if called after Next() or Seek() return ValNone +// Only Err() should return nil even after Next() or Seek() return ValNone func (m *mergedSeriesIterator) Err() error { + if m.lastIter == nil { + return nil + } return m.lastIter.Err() } diff --git a/pkg/dedup/merge_iter_test.go b/pkg/dedup/merge_iter_test.go index d3166f5f489..ad56fa2ed3f 100644 --- a/pkg/dedup/merge_iter_test.go +++ b/pkg/dedup/merge_iter_test.go @@ -4,13 +4,24 @@ package dedup import ( + "math" "testing" "github.com/efficientgo/core/testutil" "github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/storage" + "github.com/prometheus/prometheus/tsdb/chunkenc" ) +func TestIteratorEdgeCases(t *testing.T) { + ms := NewMergedSeries(labels.Labels{}, []storage.Series{}) + it := ms.Iterator(nil) + testutil.Ok(t, it.Err()) + testutil.Equals(t, int64(math.MinInt64), it.AtT()) + testutil.Equals(t, chunkenc.ValNone, it.Next()) + testutil.Ok(t, it.Err()) +} + func TestMergedSeriesIterator(t *testing.T) { for _, tcase := range []struct { name string