diff --git a/storage/merge.go b/storage/merge.go index bf81fcc6d..2a68ad96a 100644 --- a/storage/merge.go +++ b/storage/merge.go @@ -431,7 +431,7 @@ func ChainedSeriesMerge(series ...Series) Series { for _, s := range series { iterators = append(iterators, s.Iterator()) } - return newChainSampleIterator(iterators) + return NewChainSampleIterator(iterators) }, } } @@ -447,7 +447,10 @@ type chainSampleIterator struct { lastt int64 } -func newChainSampleIterator(iterators []chunkenc.Iterator) chunkenc.Iterator { +// NewChainSampleIterator returns a single iterator that iterates over the samples from the given iterators in a sorted +// fashion. If samples overlap, one sample from overlapped ones is kept (randomly) and all others with the same +// timestamp are dropped. +func NewChainSampleIterator(iterators []chunkenc.Iterator) chunkenc.Iterator { return &chainSampleIterator{ iterators: iterators, h: nil, diff --git a/storage/merge_test.go b/storage/merge_test.go index d44ffce7c..23eab0f70 100644 --- a/storage/merge_test.go +++ b/storage/merge_test.go @@ -631,7 +631,7 @@ func TestChainSampleIterator(t *testing.T) { expected: []tsdbutil.Sample{sample{0, 0}, sample{1, 1}, sample{2, 2}, sample{3, 3}}, }, } { - merged := newChainSampleIterator(tc.input) + merged := NewChainSampleIterator(tc.input) actual, err := ExpandSamples(merged, nil) require.NoError(t, err) require.Equal(t, tc.expected, actual) @@ -677,7 +677,7 @@ func TestChainSampleIteratorSeek(t *testing.T) { 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{} if merged.Seek(tc.seek) { t, v := merged.At()