mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-13 00:54:04 -08:00
Merge pull request #1129 from prometheus/rename-global-labels
Rename global "labels" config option to "external_labels".
This commit is contained in:
commit
db382b4570
|
@ -206,6 +206,10 @@ func reloadConfig(filename string, rls ...Reloadable) (success bool) {
|
||||||
conf, err := config.LoadFile(filename)
|
conf, err := config.LoadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Couldn't load configuration (-config.file=%s): %v", filename, err)
|
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
|
return false
|
||||||
}
|
}
|
||||||
success = true
|
success = true
|
||||||
|
|
|
@ -274,7 +274,7 @@ type GlobalConfig struct {
|
||||||
// How frequently to evaluate rules by default.
|
// How frequently to evaluate rules by default.
|
||||||
EvaluationInterval Duration `yaml:"evaluation_interval,omitempty"`
|
EvaluationInterval Duration `yaml:"evaluation_interval,omitempty"`
|
||||||
// The labels to add to any timeseries that this Prometheus instance scrapes.
|
// 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.
|
// Catches all undefined fields and must be empty after parsing.
|
||||||
XXX map[string]interface{} `yaml:",inline"`
|
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.
|
// isZero returns true iff the global config is the zero value.
|
||||||
func (c *GlobalConfig) isZero() bool {
|
func (c *GlobalConfig) isZero() bool {
|
||||||
return c.Labels == nil &&
|
return c.ExternalLabels == nil &&
|
||||||
c.ScrapeInterval == 0 &&
|
c.ScrapeInterval == 0 &&
|
||||||
c.ScrapeTimeout == 0 &&
|
c.ScrapeTimeout == 0 &&
|
||||||
c.EvaluationInterval == 0
|
c.EvaluationInterval == 0
|
||||||
|
|
|
@ -32,7 +32,7 @@ var expectedConf = &Config{
|
||||||
ScrapeTimeout: DefaultGlobalConfig.ScrapeTimeout,
|
ScrapeTimeout: DefaultGlobalConfig.ScrapeTimeout,
|
||||||
EvaluationInterval: Duration(30 * time.Second),
|
EvaluationInterval: Duration(30 * time.Second),
|
||||||
|
|
||||||
Labels: model.LabelSet{
|
ExternalLabels: model.LabelSet{
|
||||||
"monitor": "codelab",
|
"monitor": "codelab",
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
},
|
},
|
||||||
|
|
2
config/testdata/conf.good.yml
vendored
2
config/testdata/conf.good.yml
vendored
|
@ -4,7 +4,7 @@ global:
|
||||||
evaluation_interval: 30s
|
evaluation_interval: 30s
|
||||||
# scrape_timeout is set to the global default (10s).
|
# scrape_timeout is set to the global default (10s).
|
||||||
|
|
||||||
labels:
|
external_labels:
|
||||||
monitor: codelab
|
monitor: codelab
|
||||||
foo: bar
|
foo: bar
|
||||||
|
|
||||||
|
|
2
config/testdata/labelname.bad.yml
vendored
2
config/testdata/labelname.bad.yml
vendored
|
@ -1,3 +1,3 @@
|
||||||
global:
|
global:
|
||||||
labels:
|
external_labels:
|
||||||
not$allowed: value
|
not$allowed: value
|
||||||
|
|
2
config/testdata/labelname2.bad.yml
vendored
2
config/testdata/labelname2.bad.yml
vendored
|
@ -1,3 +1,3 @@
|
||||||
global:
|
global:
|
||||||
labels:
|
external_labels:
|
||||||
'not:allowed': value
|
'not:allowed': value
|
||||||
|
|
2
config/testdata/unknown_attr.bad.yml
vendored
2
config/testdata/unknown_attr.bad.yml
vendored
|
@ -4,7 +4,7 @@ global:
|
||||||
evaluation_interval: 30s
|
evaluation_interval: 30s
|
||||||
# scrape_timeout is set to the global default (10s).
|
# scrape_timeout is set to the global default (10s).
|
||||||
|
|
||||||
labels:
|
external_labels:
|
||||||
monitor: codelab
|
monitor: codelab
|
||||||
foo: bar
|
foo: bar
|
||||||
|
|
||||||
|
|
|
@ -88,9 +88,9 @@ type NotificationHandler struct {
|
||||||
notificationsQueueLength prometheus.Gauge
|
notificationsQueueLength prometheus.Gauge
|
||||||
notificationsQueueCapacity prometheus.Metric
|
notificationsQueueCapacity prometheus.Metric
|
||||||
|
|
||||||
globalLabels model.LabelSet
|
externalLabels model.LabelSet
|
||||||
mtx sync.RWMutex
|
mtx sync.RWMutex
|
||||||
stopped chan struct{}
|
stopped chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotificationHandlerOptions are the configurable parameters of a NotificationHandler.
|
// NotificationHandlerOptions are the configurable parameters of a NotificationHandler.
|
||||||
|
@ -151,7 +151,7 @@ func (n *NotificationHandler) ApplyConfig(conf *config.Config) bool {
|
||||||
n.mtx.Lock()
|
n.mtx.Lock()
|
||||||
defer n.mtx.Unlock()
|
defer n.mtx.Unlock()
|
||||||
|
|
||||||
n.globalLabels = conf.GlobalConfig.Labels
|
n.externalLabels = conf.GlobalConfig.ExternalLabels
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,7 +162,7 @@ func (n *NotificationHandler) sendNotifications(reqs NotificationReqs) error {
|
||||||
|
|
||||||
alerts := make([]map[string]interface{}, 0, len(reqs))
|
alerts := make([]map[string]interface{}, 0, len(reqs))
|
||||||
for _, req := range reqs {
|
for _, req := range reqs {
|
||||||
for ln, lv := range n.globalLabels {
|
for ln, lv := range n.externalLabels {
|
||||||
if _, ok := req.Labels[ln]; !ok {
|
if _, ok := req.Labels[ln]; !ok {
|
||||||
req.Labels[ln] = lv
|
req.Labels[ln] = lv
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,9 @@ import (
|
||||||
|
|
||||||
// Storage collects multiple remote storage queues.
|
// Storage collects multiple remote storage queues.
|
||||||
type Storage struct {
|
type Storage struct {
|
||||||
queues []*StorageQueueManager
|
queues []*StorageQueueManager
|
||||||
globalLabels model.LabelSet
|
externalLabels model.LabelSet
|
||||||
mtx sync.RWMutex
|
mtx sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyConfig updates the status state as the new config requires.
|
// 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()
|
s.mtx.Lock()
|
||||||
defer s.mtx.Unlock()
|
defer s.mtx.Unlock()
|
||||||
|
|
||||||
s.globalLabels = conf.GlobalConfig.Labels
|
s.externalLabels = conf.GlobalConfig.ExternalLabels
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ func (s *Storage) Append(smpl *model.Sample) {
|
||||||
snew = *smpl
|
snew = *smpl
|
||||||
snew.Metric = smpl.Metric.Clone()
|
snew.Metric = smpl.Metric.Clone()
|
||||||
|
|
||||||
for ln, lv := range s.globalLabels {
|
for ln, lv := range s.externalLabels {
|
||||||
if _, ok := smpl.Metric[ln]; !ok {
|
if _, ok := smpl.Metric[ln]; !ok {
|
||||||
snew.Metric[ln] = lv
|
snew.Metric[ln] = lv
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,13 +80,13 @@ func (h *Handler) federation(w http.ResponseWriter, req *http.Request) {
|
||||||
Name: proto.String(string(ln)),
|
Name: proto.String(string(ln)),
|
||||||
Value: proto.String(string(lv)),
|
Value: proto.String(string(lv)),
|
||||||
})
|
})
|
||||||
if _, ok := h.globalLabels[ln]; ok {
|
if _, ok := h.externalLabels[ln]; ok {
|
||||||
globalUsed[ln] = struct{}{}
|
globalUsed[ln] = struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attach global labels if they do not exist yet.
|
// 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 {
|
if _, ok := globalUsed[ln]; !ok {
|
||||||
protMetric.Label = append(protMetric.Label, &dto.LabelPair{
|
protMetric.Label = append(protMetric.Label, &dto.LabelPair{
|
||||||
Name: proto.String(string(ln)),
|
Name: proto.String(string(ln)),
|
||||||
|
|
|
@ -67,8 +67,8 @@ type Handler struct {
|
||||||
options *Options
|
options *Options
|
||||||
statusInfo *PrometheusStatus
|
statusInfo *PrometheusStatus
|
||||||
|
|
||||||
globalLabels model.LabelSet
|
externalLabels model.LabelSet
|
||||||
mtx sync.RWMutex
|
mtx sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyConfig updates the status state as the new config requires.
|
// 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()
|
h.mtx.Lock()
|
||||||
defer h.mtx.Unlock()
|
defer h.mtx.Unlock()
|
||||||
|
|
||||||
h.globalLabels = conf.GlobalConfig.Labels
|
h.externalLabels = conf.GlobalConfig.ExternalLabels
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue