Fix iterator behavior in view.GetSampleAtTime()

pull/84/head
Julius Volz 2013-03-16 01:26:56 -07:00 committed by Matt T. Proud
parent bb9c5ed7aa
commit 4e7db57e76
1 changed files with 11 additions and 7 deletions

View File

@ -126,18 +126,22 @@ func (v view) Close() {
}
func (v view) GetValueAtTime(f model.Fingerprint, t time.Time) (s []model.SamplePair) {
var (
series, ok = v.fingerprintToSeries[f]
)
series, ok := v.fingerprintToSeries[f]
if !ok {
return
}
var (
iterator = series.values.Seek(skipListTime(t))
)
iterator := series.values.Seek(skipListTime(t))
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
}
}
defer iterator.Close()