Rename global "labels" config option to "external_labels".

This commit is contained in:
Julius Volz 2015-09-29 17:51:03 +02:00
parent bf4e4a8ff0
commit dac26cef71
11 changed files with 26 additions and 22 deletions

View file

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

View file

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

View file

@ -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",
},

View file

@ -4,7 +4,7 @@ global:
evaluation_interval: 30s
# scrape_timeout is set to the global default (10s).
labels:
external_labels:
monitor: codelab
foo: bar

View file

@ -1,3 +1,3 @@
global:
labels:
external_labels:
not$allowed: value

View file

@ -1,3 +1,3 @@
global:
labels:
external_labels:
'not:allowed': value

View file

@ -4,7 +4,7 @@ global:
evaluation_interval: 30s
# scrape_timeout is set to the global default (10s).
labels:
external_labels:
monitor: codelab
foo: bar

View file

@ -88,7 +88,7 @@ type NotificationHandler struct {
notificationsQueueLength prometheus.Gauge
notificationsQueueCapacity prometheus.Metric
globalLabels model.LabelSet
externalLabels model.LabelSet
mtx sync.RWMutex
stopped chan struct{}
}
@ -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
}

View file

@ -31,7 +31,7 @@ import (
// Storage collects multiple remote storage queues.
type Storage struct {
queues []*StorageQueueManager
globalLabels model.LabelSet
externalLabels model.LabelSet
mtx sync.RWMutex
}
@ -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
}

View file

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

View file

@ -67,7 +67,7 @@ type Handler struct {
options *Options
statusInfo *PrometheusStatus
globalLabels model.LabelSet
externalLabels model.LabelSet
mtx sync.RWMutex
}
@ -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
}