Ensure new metrics are watermarked early.

With the checking of fingerprint freshness to cull stale metrics
from queries, we should write watermarks early to aid in more
accurate responses.
This commit is contained in:
Matt T. Proud 2013-06-21 09:42:45 +02:00 committed by Julius Volz
parent de8757f925
commit a1a23fbaf8
1 changed files with 11 additions and 9 deletions

View File

@ -488,26 +488,28 @@ func (l *LevelDBMetricPersistence) refreshHighWatermarks(groups map[model.Finger
batch := leveldb.NewBatch() batch := leveldb.NewBatch()
defer batch.Close() defer batch.Close()
mutationCount := 0
for fingerprint, samples := range groups {
value := &dto.MetricHighWatermark{} value := &dto.MetricHighWatermark{}
newestSampleTimestamp := samples[len(samples)-1].Timestamp for fingerprint, samples := range groups {
value.Reset()
present, err := l.MetricHighWatermarks.Get(fingerprint.ToDTO(), value) present, err := l.MetricHighWatermarks.Get(fingerprint.ToDTO(), value)
if err != nil { if err != nil {
return err return err
} }
newestSampleTimestamp := samples[len(samples)-1].Timestamp
if !present { if !present {
value.Timestamp = proto.Int64(newestSampleTimestamp.Unix())
batch.Put(fingerprint.ToDTO(), value)
continue continue
} }
// BUG(matt): Repace this with watermark management. // BUG(matt): Repace this with watermark management.
if newestSampleTimestamp.Before(time.Unix(*value.Timestamp, 0)) { if !newestSampleTimestamp.Before(time.Unix(value.GetTimestamp(), 0)) {
continue
}
value.Timestamp = proto.Int64(newestSampleTimestamp.Unix()) value.Timestamp = proto.Int64(newestSampleTimestamp.Unix())
batch.Put(fingerprint.ToDTO(), value) batch.Put(fingerprint.ToDTO(), value)
mutationCount++ }
} }
err = l.MetricHighWatermarks.Commit(batch) err = l.MetricHighWatermarks.Commit(batch)