diff --git a/main.go b/main.go index d9e69e869..7bc4af2b5 100644 --- a/main.go +++ b/main.go @@ -104,20 +104,10 @@ func (p *prometheus) close() { glog.Info("Rule Executor: Done") close(p.unwrittenSamples) - - if err := p.storage.Close(); err != nil { - glog.Error("Error closing local storage: ", err) - } - glog.Info("Local Storage: Done") - - if p.remoteTSDBQueue != nil { - p.remoteTSDBQueue.Close() - glog.Info("Remote Storage: Done") - } - - close(p.notifications) - glog.Info("Sundry Queues: Done") - glog.Info("See you next time!") + // Note: Before closing the remaining subsystems (storage, ...), we have + // to wait until p.unwrittenSamples is actually drained. Therefore, + // things are closed in main(), after the loop consuming + // p.unwrittenSamples has finished. } func main() { @@ -263,4 +253,21 @@ func main() { } } } + + // Note: It might appear tempting to move the code below into + // prometheus.Close(), but we have to wait for the unwrittenSamples loop + // above to exit before we can do the below. + if err := prometheus.storage.Close(); err != nil { + glog.Error("Error closing local storage: ", err) + } + glog.Info("Local Storage: Done") + + if prometheus.remoteTSDBQueue != nil { + prometheus.remoteTSDBQueue.Close() + glog.Info("Remote Storage: Done") + } + + close(prometheus.notifications) + glog.Info("Sundry Queues: Done") + glog.Info("See you next time!") } diff --git a/storage/metric/sample.go b/storage/metric/sample.go index d5f2ee9ff..c0e592c69 100644 --- a/storage/metric/sample.go +++ b/storage/metric/sample.go @@ -30,9 +30,9 @@ type SamplePair struct { Value clientmodel.SampleValue } -// TODO: can this method be deleted, or is it used in tests? // 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