From 9b8c671ec9ff6c81d0dadc33a8b1412c24baef62 Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Wed, 24 Apr 2013 12:42:58 +0200 Subject: [PATCH] Fixes/cleanups to renderView() samples truncation. --- model/metric.go | 13 +++---------- storage/metric/tiered.go | 4 ++-- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/model/metric.go b/model/metric.go index a9f0d3242..a8af0ffb7 100644 --- a/model/metric.go +++ b/model/metric.go @@ -96,15 +96,8 @@ type SamplePair struct { Timestamp time.Time } -func (s SamplePair) Equal(o SamplePair) (equal bool) { - switch { - case !s.Value.Equal(o.Value): - return - case !s.Timestamp.Equal(o.Timestamp): - return - } - - return true +func (s SamplePair) Equal(o SamplePair) bool { + return s.Value.Equal(o.Value) && s.Timestamp.Equal(o.Timestamp) } type Values []SamplePair @@ -158,7 +151,7 @@ func (v Values) TruncateBefore(t time.Time) (values Values) { index := sort.Search(len(v), func(i int) bool { timestamp := v[i].Timestamp - return timestamp.After(t) || timestamp.Equal(t) + return !timestamp.Before(t) }) switch index { diff --git a/storage/metric/tiered.go b/storage/metric/tiered.go index 5a7c447f3..c4364f731 100644 --- a/storage/metric/tiered.go +++ b/storage/metric/tiered.go @@ -417,13 +417,13 @@ func (t *tieredStorage) renderView(viewJob viewJob) { break } + chunk = chunk.TruncateBefore(targetTime) + lastChunkTime := chunk[len(chunk)-1].Timestamp if lastChunkTime.After(targetTime) { targetTime = lastChunkTime } - chunk = chunk.TruncateBefore(targetTime) - // For each op, extract all needed data from the current chunk. out := model.Values{} for _, op := range standingOps {