Fix view's GetRangeValues() reverse iteration behavior.

This commit is contained in:
Julius Volz 2013-03-21 17:57:57 +01:00
parent 0be0aa59c2
commit 081d250929
1 changed files with 18 additions and 11 deletions

View File

@ -14,7 +14,6 @@
package metric package metric
import ( import (
"fmt"
"github.com/prometheus/prometheus/model" "github.com/prometheus/prometheus/model"
"github.com/ryszard/goskiplist/skiplist" "github.com/ryszard/goskiplist/skiplist"
"sort" "sort"
@ -22,8 +21,6 @@ import (
) )
var ( var (
_ = fmt.Sprintf("")
// firstSupertime is the smallest valid supertime that may be seeked to. // firstSupertime is the smallest valid supertime that may be seeked to.
firstSupertime = []byte{0, 0, 0, 0, 0, 0, 0, 0} firstSupertime = []byte{0, 0, 0, 0, 0, 0, 0, 0}
// lastSupertime is the largest valid supertime that may be seeked to. // lastSupertime is the largest valid supertime that may be seeked to.
@ -177,23 +174,33 @@ func (v view) GetRangeValues(f model.Fingerprint, i model.Interval) (samples []m
return return
} }
iterator := series.values.Seek(skipListTime(i.NewestInclusive)) iterator := series.values.Seek(skipListTime(i.OldestInclusive))
if iterator == nil { if iterator == nil {
return // If the iterator is nil, it means we seeked past the end of the series,
// so we seek to the last value instead. Due to the reverse ordering
// defined on skipListTime, this corresponds to the sample with the
// earliest timestamp.
iterator = series.values.SeekToLast()
if iterator == nil {
// The list is empty.
return
}
} }
for { for {
timestamp := time.Time(iterator.Key().(skipListTime)) timestamp := time.Time(iterator.Key().(skipListTime))
if timestamp.Before(i.OldestInclusive) { if timestamp.After(i.NewestInclusive) {
break break
} }
samples = append(samples, model.SamplePair{ if !timestamp.Before(i.OldestInclusive) {
Value: iterator.Value().(value).get(), samples = append(samples, model.SamplePair{
Timestamp: timestamp, Value: iterator.Value().(value).get(),
}) Timestamp: timestamp,
})
}
if !iterator.Next() { if !iterator.Previous() {
break break
} }
} }