diff --git a/chunkenc/chunk.go b/chunkenc/chunk.go index 5e807b4f..bc6c2010 100644 --- a/chunkenc/chunk.go +++ b/chunkenc/chunk.go @@ -56,7 +56,7 @@ type Appender interface { Append(int64, float64) } -// Iterator is a simple iterator that can only get the next value. +// Iterator iterates over the data of a time series. type Iterator interface { // Seek advances the iterator forward to the given timestamp. // If there's no value exactly at t, it advances to the first value diff --git a/head_test.go b/head_test.go index 040ae828..34bdd57b 100644 --- a/head_test.go +++ b/head_test.go @@ -740,7 +740,7 @@ func TestDelete_e2e(t *testing.T) { smpls = deletedSamples(smpls, del.drange) // Only append those series for which samples exist as mockSeriesSet // doesn't skip series with no samples. - // TODO: But sometimes SeriesSet returns an empty SeriesIterator + // TODO: But sometimes SeriesSet returns an empty chunkenc.Iterator if len(smpls) > 0 { matchedSeries = append(matchedSeries, newSeries( m.Map(), diff --git a/querier.go b/querier.go index 5b218c3d..a39b41d7 100644 --- a/querier.go +++ b/querier.go @@ -54,9 +54,9 @@ type Series interface { Labels() labels.Labels // Iterator returns a new iterator of the data of the series. - Iterator() SeriesIterator + Iterator() chunkenc.Iterator - // ChunkIterator returns a new iterator for the non-overlapping chunks of the series. + // ChunkIterator returns a new iterator that iterates over non-overlapping chunks of the series. ChunkIterator() ChunkIterator } @@ -876,7 +876,7 @@ func (s *chunkSeries) Labels() labels.Labels { return s.labels } -func (s *chunkSeries) Iterator() SeriesIterator { +func (s *chunkSeries) Iterator() chunkenc.Iterator { return newChunkSeriesIterator(s.chunks, s.intervals, s.mint, s.maxt) } @@ -884,20 +884,6 @@ func (s *chunkSeries) ChunkIterator() ChunkIterator { return &chunkIterator{chunks: s.chunks} } -// SeriesIterator iterates over the data of a time series. -type SeriesIterator interface { - // Seek advances the iterator forward to the given timestamp. - // If there's no value exactly at t, it advances to the first value - // after t. - Seek(t int64) bool - // At returns the current timestamp/value pair. - At() (t int64, v float64) - // Next advances the iterator by one. - Next() bool - // Err returns the current error. - Err() error -} - // chainedSeries implements a series for a list of time-sorted series. // They all must have the same labels. type chainedSeries struct { @@ -908,7 +894,7 @@ func (s *chainedSeries) Labels() labels.Labels { return s.series[0].Labels() } -func (s *chainedSeries) Iterator() SeriesIterator { +func (s *chainedSeries) Iterator() chunkenc.Iterator { return newChainedSeriesIterator(s.series...) } @@ -926,7 +912,7 @@ type chainedSeriesIterator struct { series []Series // series in time order i int - cur SeriesIterator + cur chunkenc.Iterator } func newChainedSeriesIterator(s ...Series) *chainedSeriesIterator { @@ -987,7 +973,7 @@ func (s *verticalChainedSeries) Labels() labels.Labels { return s.series[0].Labels() } -func (s *verticalChainedSeries) Iterator() SeriesIterator { +func (s *verticalChainedSeries) Iterator() chunkenc.Iterator { return newVerticalMergeSeriesIterator(s.series...) } @@ -998,14 +984,14 @@ func (s *verticalChainedSeries) ChunkIterator() ChunkIterator { // verticalMergeSeriesIterator implements a series iterator over a list // of time-sorted, time-overlapping iterators. type verticalMergeSeriesIterator struct { - a, b SeriesIterator + a, b chunkenc.Iterator aok, bok, initialized bool curT int64 curV float64 } -func newVerticalMergeSeriesIterator(s ...Series) SeriesIterator { +func newVerticalMergeSeriesIterator(s ...Series) chunkenc.Iterator { if len(s) == 1 { return s[0].Iterator() } else if len(s) == 2 { @@ -1148,7 +1134,6 @@ func (it *verticalMergeChunkIterator) Next() bool { return true } - it.curMeta, it.err = mergeOverlappingChunks(aCurMeta, bCurMeta, it.aReuseIter, it.bReuseIter) if it.err != nil { return false @@ -1189,9 +1174,9 @@ func mergeOverlappingChunks(a, b chunks.Meta, aReuseIter, bReuseIter chunkenc.It } return chunks.Meta{ - MinTime: mint, - MaxTime: maxt, - Chunk: chk, + MinTime: mint, + MaxTime: maxt, + Chunk: chk, }, nil } diff --git a/querier_test.go b/querier_test.go index 15e4f27e..cc48c95d 100644 --- a/querier_test.go +++ b/querier_test.go @@ -179,7 +179,7 @@ Outer: } } -func expandSeriesIterator(it SeriesIterator) (r []tsdbutil.Sample, err error) { +func expandSeriesIterator(it chunkenc.Iterator) (r []tsdbutil.Sample, err error) { for it.Next() { t, v := it.At() r = append(r, sample{t: t, v: v}) @@ -271,7 +271,7 @@ func TestBlockQuerier(t *testing.T) { newSeries := func(l map[string]string, s []tsdbutil.Sample) Series { return &mockSeries{ labels: func() labels.Labels { return labels.FromMap(l) }, - iterator: func() SeriesIterator { return newListSeriesIterator(s) }, + iterator: func() chunkenc.Iterator { return newListSeriesIterator(s) }, } } @@ -409,7 +409,7 @@ func TestBlockQuerierDelete(t *testing.T) { newSeries := func(l map[string]string, s []tsdbutil.Sample) Series { return &mockSeries{ labels: func() labels.Labels { return labels.FromMap(l) }, - iterator: func() SeriesIterator { return newListSeriesIterator(s) }, + iterator: func() chunkenc.Iterator { return newListSeriesIterator(s) }, } } @@ -665,10 +665,10 @@ func TestBaseChunkSeries(t *testing.T) { // TODO: Remove after simpleSeries is merged type itSeries struct { - si SeriesIterator + si chunkenc.Iterator } -func (s itSeries) Iterator() SeriesIterator { return s.si } +func (s itSeries) Iterator() chunkenc.Iterator { return s.si } func (s itSeries) Labels() labels.Labels { return labels.Labels{} } func (s itSeries) ChunkIterator() ChunkIterator { return nil } @@ -1013,7 +1013,7 @@ func TestSeriesIterator(t *testing.T) { t.Run("Seek", func(t *testing.T) { for _, tc := range seekcases { - ress := []SeriesIterator{ + ress := []chunkenc.Iterator{ newChainedSeriesIterator( itSeries{newListSeriesIterator(tc.a)}, itSeries{newListSeriesIterator(tc.b)}, @@ -1478,17 +1478,17 @@ func (m mockIndex) LabelNames() ([]string, error) { type mockSeries struct { labels func() labels.Labels - iterator func() SeriesIterator + iterator func() chunkenc.Iterator } func newSeries(l map[string]string, s []tsdbutil.Sample) Series { return &mockSeries{ labels: func() labels.Labels { return labels.FromMap(l) }, - iterator: func() SeriesIterator { return newListSeriesIterator(s) }, + iterator: func() chunkenc.Iterator { return newListSeriesIterator(s) }, } } func (m *mockSeries) Labels() labels.Labels { return m.labels() } -func (m *mockSeries) Iterator() SeriesIterator { return m.iterator() } +func (m *mockSeries) Iterator() chunkenc.Iterator { return m.iterator() } func (m *mockSeries) ChunkIterator() ChunkIterator { return nil } type listSeriesIterator struct { diff --git a/tsdbutil/buffer.go b/tsdbutil/buffer.go index dc2d960d..8f615d8e 100644 --- a/tsdbutil/buffer.go +++ b/tsdbutil/buffer.go @@ -15,25 +15,13 @@ package tsdbutil import ( "math" -) -// SeriesIterator iterates over the data of a time series. -type SeriesIterator interface { - // Seek advances the iterator forward to the given timestamp. - // If there's no value exactly at t, it advances to the first value - // after t. - Seek(t int64) bool - // At returns the current timestamp/value pair. - At() (t int64, v float64) - // Next advances the iterator by one. - Next() bool - // Err returns the current error. - Err() error -} + "github.com/prometheus/tsdb/chunkenc" +) // BufferedSeriesIterator wraps an iterator with a look-back buffer. type BufferedSeriesIterator struct { - it SeriesIterator + it chunkenc.Iterator buf *sampleRing lastTime int64 @@ -41,7 +29,7 @@ type BufferedSeriesIterator struct { // NewBuffer returns a new iterator that buffers the values within the time range // of the current element and the duration of delta before. -func NewBuffer(it SeriesIterator, delta int64) *BufferedSeriesIterator { +func NewBuffer(it chunkenc.Iterator, delta int64) *BufferedSeriesIterator { return &BufferedSeriesIterator{ it: it, buf: newSampleRing(delta, 16), @@ -56,7 +44,7 @@ func (b *BufferedSeriesIterator) PeekBack() (t int64, v float64, ok bool) { } // Buffer returns an iterator over the buffered data. -func (b *BufferedSeriesIterator) Buffer() SeriesIterator { +func (b *BufferedSeriesIterator) Buffer() chunkenc.Iterator { return b.buf.iterator() } @@ -145,7 +133,7 @@ func (r *sampleRing) reset() { r.f = 0 } -func (r *sampleRing) iterator() SeriesIterator { +func (r *sampleRing) iterator() chunkenc.Iterator { return &sampleRingIterator{r: r, i: -1} }