Skip to content

Commit

Permalink
Merge pull request prometheus#1129 from prometheus/rename-global-labels
Browse files Browse the repository at this point in the history
Rename global "labels" config option to "external_labels".
  • Loading branch information
juliusv committed Sep 30, 2015
2 parents 4dbb3ab + dac26ce commit db382b4
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 22 deletions.
4 changes: 4 additions & 0 deletions cmd/prometheus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down
2 changes: 1 addition & 1 deletion config/testdata/conf.good.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ global:
evaluation_interval: 30s
# scrape_timeout is set to the global default (10s).

labels:
external_labels:
monitor: codelab
foo: bar

Expand Down
2 changes: 1 addition & 1 deletion config/testdata/labelname.bad.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
global:
labels:
external_labels:
not$allowed: value
2 changes: 1 addition & 1 deletion config/testdata/labelname2.bad.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
global:
labels:
external_labels:
'not:allowed': value
2 changes: 1 addition & 1 deletion config/testdata/unknown_attr.bad.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ global:
evaluation_interval: 30s
# scrape_timeout is set to the global default (10s).

labels:
external_labels:
monitor: codelab
foo: bar

Expand Down
10 changes: 5 additions & 5 deletions notification/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}
Expand Down
10 changes: 5 additions & 5 deletions storage/remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions web/federate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
6 changes: 3 additions & 3 deletions web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}
Expand Down

0 comments on commit db382b4

Please sign in to comment.