Fix GetBoundaryValues.

Change-Id: I8f8bbdb88e9b24e4c37ff869126ed9343f261ce2
This commit is contained in:
Bjoern Rabenstein 2014-10-10 15:34:09 +02:00
parent 4fc8ad6677
commit 83b4fa868d
2 changed files with 9 additions and 7 deletions

View file

@ -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]
}

View file

@ -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