From dac26cef71dfcc25b3cadd8d9f3fe7b7122243f0 Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Tue, 29 Sep 2015 17:51:03 +0200 Subject: [PATCH] Rename global "labels" config option to "external_labels". --- cmd/prometheus/main.go | 4 ++++ config/config.go | 4 ++-- config/config_test.go | 2 +- config/testdata/conf.good.yml | 2 +- config/testdata/labelname.bad.yml | 2 +- config/testdata/labelname2.bad.yml | 2 +- config/testdata/unknown_attr.bad.yml | 2 +- notification/notification.go | 10 +++++----- storage/remote/remote.go | 10 +++++----- web/federate.go | 4 ++-- web/web.go | 6 +++--- 11 files changed, 26 insertions(+), 22 deletions(-) diff --git a/cmd/prometheus/main.go b/cmd/prometheus/main.go index 9be251c9a..b513ef196 100644 --- a/cmd/prometheus/main.go +++ b/cmd/prometheus/main.go @@ -206,6 +206,10 @@ func reloadConfig(filename string, rls ...Reloadable) (success bool) { conf, err := config.LoadFile(filename) if err != nil { log.Errorf("Couldn't load configuration (-config.file=%s): %v", filename, err) + // TODO(julius): Remove this notice when releasing 0.17.0 or 0.18.0. + if err.Error() == "unknown fields in global config: labels" { + log.Errorf("NOTE: The 'labels' setting in the global configuration section has been renamed to 'external_labels' and now has changed semantics (see release notes at https://github.com/prometheus/prometheus/blob/master/CHANGELOG.md). Please update your configuration file accordingly.") + } return false } success = true diff --git a/config/config.go b/config/config.go index eef034e17..e00e24535 100644 --- a/config/config.go +++ b/config/config.go @@ -274,7 +274,7 @@ type GlobalConfig struct { // How frequently to evaluate rules by default. EvaluationInterval Duration `yaml:"evaluation_interval,omitempty"` // The labels to add to any timeseries that this Prometheus instance scrapes. - Labels model.LabelSet `yaml:"labels,omitempty"` + ExternalLabels model.LabelSet `yaml:"external_labels,omitempty"` // Catches all undefined fields and must be empty after parsing. XXX map[string]interface{} `yaml:",inline"` @@ -292,7 +292,7 @@ func (c *GlobalConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { // isZero returns true iff the global config is the zero value. func (c *GlobalConfig) isZero() bool { - return c.Labels == nil && + return c.ExternalLabels == nil && c.ScrapeInterval == 0 && c.ScrapeTimeout == 0 && c.EvaluationInterval == 0 diff --git a/config/config_test.go b/config/config_test.go index a8571d54d..3e38cda33 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -32,7 +32,7 @@ var expectedConf = &Config{ ScrapeTimeout: DefaultGlobalConfig.ScrapeTimeout, EvaluationInterval: Duration(30 * time.Second), - Labels: model.LabelSet{ + ExternalLabels: model.LabelSet{ "monitor": "codelab", "foo": "bar", }, diff --git a/config/testdata/conf.good.yml b/config/testdata/conf.good.yml index 6b3745083..3e04c0a9a 100644 --- a/config/testdata/conf.good.yml +++ b/config/testdata/conf.good.yml @@ -4,7 +4,7 @@ global: evaluation_interval: 30s # scrape_timeout is set to the global default (10s). - labels: + external_labels: monitor: codelab foo: bar diff --git a/config/testdata/labelname.bad.yml b/config/testdata/labelname.bad.yml index 66ea324cf..c06853a26 100644 --- a/config/testdata/labelname.bad.yml +++ b/config/testdata/labelname.bad.yml @@ -1,3 +1,3 @@ global: - labels: + external_labels: not$allowed: value diff --git a/config/testdata/labelname2.bad.yml b/config/testdata/labelname2.bad.yml index 30da44b17..7afcd6bcf 100644 --- a/config/testdata/labelname2.bad.yml +++ b/config/testdata/labelname2.bad.yml @@ -1,3 +1,3 @@ global: - labels: + external_labels: 'not:allowed': value diff --git a/config/testdata/unknown_attr.bad.yml b/config/testdata/unknown_attr.bad.yml index 4baaf565c..8a53075f6 100644 --- a/config/testdata/unknown_attr.bad.yml +++ b/config/testdata/unknown_attr.bad.yml @@ -4,7 +4,7 @@ global: evaluation_interval: 30s # scrape_timeout is set to the global default (10s). - labels: + external_labels: monitor: codelab foo: bar diff --git a/notification/notification.go b/notification/notification.go index a43d05060..0b1e1a838 100644 --- a/notification/notification.go +++ b/notification/notification.go @@ -88,9 +88,9 @@ type NotificationHandler struct { notificationsQueueLength prometheus.Gauge notificationsQueueCapacity prometheus.Metric - globalLabels model.LabelSet - mtx sync.RWMutex - stopped chan struct{} + externalLabels model.LabelSet + mtx sync.RWMutex + stopped chan struct{} } // NotificationHandlerOptions are the configurable parameters of a NotificationHandler. @@ -151,7 +151,7 @@ func (n *NotificationHandler) ApplyConfig(conf *config.Config) bool { n.mtx.Lock() defer n.mtx.Unlock() - n.globalLabels = conf.GlobalConfig.Labels + n.externalLabels = conf.GlobalConfig.ExternalLabels return true } @@ -162,7 +162,7 @@ func (n *NotificationHandler) sendNotifications(reqs NotificationReqs) error { alerts := make([]map[string]interface{}, 0, len(reqs)) for _, req := range reqs { - for ln, lv := range n.globalLabels { + for ln, lv := range n.externalLabels { if _, ok := req.Labels[ln]; !ok { req.Labels[ln] = lv } diff --git a/storage/remote/remote.go b/storage/remote/remote.go index e570cc57c..e77443469 100644 --- a/storage/remote/remote.go +++ b/storage/remote/remote.go @@ -30,9 +30,9 @@ import ( // Storage collects multiple remote storage queues. type Storage struct { - queues []*StorageQueueManager - globalLabels model.LabelSet - mtx sync.RWMutex + queues []*StorageQueueManager + externalLabels model.LabelSet + mtx sync.RWMutex } // ApplyConfig updates the status state as the new config requires. @@ -41,7 +41,7 @@ func (s *Storage) ApplyConfig(conf *config.Config) bool { s.mtx.Lock() defer s.mtx.Unlock() - s.globalLabels = conf.GlobalConfig.Labels + s.externalLabels = conf.GlobalConfig.ExternalLabels return true } @@ -102,7 +102,7 @@ func (s *Storage) Append(smpl *model.Sample) { snew = *smpl snew.Metric = smpl.Metric.Clone() - for ln, lv := range s.globalLabels { + for ln, lv := range s.externalLabels { if _, ok := smpl.Metric[ln]; !ok { snew.Metric[ln] = lv } diff --git a/web/federate.go b/web/federate.go index 2f8b8aa93..d935421a7 100644 --- a/web/federate.go +++ b/web/federate.go @@ -80,13 +80,13 @@ func (h *Handler) federation(w http.ResponseWriter, req *http.Request) { Name: proto.String(string(ln)), Value: proto.String(string(lv)), }) - if _, ok := h.globalLabels[ln]; ok { + if _, ok := h.externalLabels[ln]; ok { globalUsed[ln] = struct{}{} } } // Attach global labels if they do not exist yet. - for ln, lv := range h.globalLabels { + for ln, lv := range h.externalLabels { if _, ok := globalUsed[ln]; !ok { protMetric.Label = append(protMetric.Label, &dto.LabelPair{ Name: proto.String(string(ln)), diff --git a/web/web.go b/web/web.go index 65673074c..6e8b27295 100644 --- a/web/web.go +++ b/web/web.go @@ -67,8 +67,8 @@ type Handler struct { options *Options statusInfo *PrometheusStatus - globalLabels model.LabelSet - mtx sync.RWMutex + externalLabels model.LabelSet + mtx sync.RWMutex } // ApplyConfig updates the status state as the new config requires. @@ -77,7 +77,7 @@ func (h *Handler) ApplyConfig(conf *config.Config) bool { h.mtx.Lock() defer h.mtx.Unlock() - h.globalLabels = conf.GlobalConfig.Labels + h.externalLabels = conf.GlobalConfig.ExternalLabels return true }