diff --git a/storage/local/series.go b/storage/local/series.go index 8b853ecb9..e1cc69947 100644 --- a/storage/local/series.go +++ b/storage/local/series.go @@ -540,9 +540,6 @@ func (it *memorySeriesIterator) GetValueAtTime(t clientmodel.Timestamp) metric.V // GetBoundaryValues implements SeriesIterator. func (it *memorySeriesIterator) GetBoundaryValues(in metric.Interval) metric.Values { - return it.GetRangeValues(in) - - // TODO: The following doesn't work as expected. Fix it. it.lock() defer it.unlock() @@ -550,9 +547,8 @@ func (it *memorySeriesIterator) GetBoundaryValues(in metric.Interval) metric.Val i := sort.Search(len(it.chunks), func(i int) bool { return !it.chunks[i].lastTime().Before(in.OldestInclusive) }) - values := metric.Values{} - for ; i < len(it.chunks); i++ { - c := it.chunks[i] + values := make(metric.Values, 0, 2) + for i, c := range it.chunks[i:] { var chunkIt chunkIterator if c.firstTime().After(in.NewestInclusive) { if len(values) == 1 { @@ -585,6 +581,13 @@ func (it *memorySeriesIterator) GetBoundaryValues(in metric.Interval) metric.Val break } } + if len(values) == 1 { + // We found exactly one value. In that case, add the most recent we know. + values = append( + values, + it.chunks[len(it.chunks)-1].newIterator().getValueAtTime(in.NewestInclusive)[0], + ) + } if len(values) == 2 && values[0].Equal(&values[1]) { return values[:1] } diff --git a/storage/metric/sample.go b/storage/metric/sample.go index c0e592c69..ab592a0ad 100644 --- a/storage/metric/sample.go +++ b/storage/metric/sample.go @@ -32,7 +32,6 @@ type SamplePair struct { // Equal returns true if this SamplePair and o have equal Values and equal // Timestamps. -// TODO: can this method be deleted, or is it used in tests? func (s *SamplePair) Equal(o *SamplePair) bool { if s == o { return true