Attach global labels to remote storage samples

pull/1051/head
Fabian Reinartz 9 years ago
parent 5fed076a76
commit 8fa719f778

@ -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

@ -14,11 +14,13 @@
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"
)
@ -26,6 +28,18 @@ import (
// Storage collects multiple remote storage queues.
type Storage struct {
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)
}
}

Loading…
Cancel
Save