From 8fa719f778a68c2ca2d9be810a9bbcbe85e2a227 Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Thu, 3 Sep 2015 13:44:03 +0200 Subject: [PATCH] Attach global labels to remote storage samples --- cmd/prometheus/main.go | 5 ++++- storage/remote/remote.go | 31 +++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/cmd/prometheus/main.go b/cmd/prometheus/main.go index 7acd49cad..5e17405e4 100644 --- a/cmd/prometheus/main.go +++ b/cmd/prometheus/main.go @@ -57,6 +57,8 @@ func Main() int { return 0 } + var reloadables []Reloadable + var ( memStorage = local.NewMemorySeriesStorage(&cfg.storage) remoteStorage = remote.New(&cfg.remote) @@ -64,6 +66,7 @@ func Main() int { ) if remoteStorage != nil { sampleAppender = append(sampleAppender, remoteStorage) + reloadables = append(reloadables, remoteStorage) } var ( @@ -93,7 +96,7 @@ func Main() int { webHandler := web.New(memStorage, queryEngine, ruleManager, status, &cfg.web) - reloadables := []Reloadable{status, targetManager, ruleManager, webHandler, notificationHandler} + reloadables = append(reloadables, status, targetManager, ruleManager, webHandler, notificationHandler) if !reloadConfig(cfg.configFile, reloadables...) { return 1 diff --git a/storage/remote/remote.go b/storage/remote/remote.go index 3e8e25c56..aab7f34d3 100644 --- a/storage/remote/remote.go +++ b/storage/remote/remote.go @@ -14,18 +14,32 @@ package remote import ( + "sync" "time" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" + "github.com/prometheus/prometheus/config" "github.com/prometheus/prometheus/storage/remote/influxdb" "github.com/prometheus/prometheus/storage/remote/opentsdb" ) // Storage collects multiple remote storage queues. type Storage struct { - queues []*StorageQueueManager + queues []*StorageQueueManager + globalLabels model.LabelSet + mtx sync.RWMutex +} + +// ApplyConfig updates the status state as the new config requires. +// Returns true on success. +func (s *Storage) ApplyConfig(conf *config.Config) bool { + s.mtx.Lock() + defer s.mtx.Unlock() + + s.globalLabels = conf.GlobalConfig.Labels + return true } // New returns a new remote Storage. @@ -70,8 +84,21 @@ func (s *Storage) Stop() { // Append implements storage.SampleAppender. func (s *Storage) Append(smpl *model.Sample) { + s.mtx.RLock() + + var snew model.Sample + snew = *smpl + snew.Metric = smpl.Metric.Clone() + + for ln, lv := range s.globalLabels { + if _, ok := smpl.Metric[ln]; !ok { + snew.Metric[ln] = lv + } + } + s.mtx.RUnlock() + for _, q := range s.queues { - q.Append(smpl) + q.Append(&snew) } }