From 0f21bd31ca274d65f0ef7df9c51edad0502b9af3 Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Wed, 8 Jun 2016 15:54:04 +0200 Subject: [PATCH] config: deprecate `target_groups` for `static_configs` This change deprecates the `target_groups` option in favor of `static_configs`. The old configuration is still accepted but prints a warning. Configuration loading errors if both options are set. --- config/config.go | 15 +++++++++++++-- config/config_test.go | 6 +++--- config/testdata/conf.good.yml | 2 +- .../{tgroup.bad.json => static_config.bad.json} | 0 config/testdata/url_in_targetgroup.bad.yml | 2 +- retrieval/targetmanager.go | 4 ++-- 6 files changed, 20 insertions(+), 9 deletions(-) rename config/testdata/{tgroup.bad.json => static_config.bad.json} (100%) diff --git a/config/config.go b/config/config.go index 86bbfdf46..08593915b 100644 --- a/config/config.go +++ b/config/config.go @@ -23,6 +23,7 @@ import ( "strings" "time" + "github.com/prometheus/common/log" "github.com/prometheus/common/model" "gopkg.in/yaml.v2" ) @@ -399,7 +400,9 @@ type ScrapeConfig struct { TLSConfig TLSConfig `yaml:"tls_config,omitempty"` // List of labeled target groups for this job. - TargetGroups []*TargetGroup `yaml:"target_groups,omitempty"` + // XXX(fabxc): `target_groups` is deprecated. + TargetGroups []*TargetGroup `yaml:"target_groups,omitempty"` + StaticConfigs []*TargetGroup `yaml:"static_configs,omitempty"` // List of DNS service discovery configurations. DNSSDConfigs []*DNSSDConfig `yaml:"dns_sd_configs,omitempty"` // List of file service discovery configurations. @@ -445,9 +448,17 @@ func (c *ScrapeConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { if c.BasicAuth != nil && (len(c.BearerToken) > 0 || len(c.BearerTokenFile) > 0) { return fmt.Errorf("at most one of basic_auth, bearer_token & bearer_token_file must be configured") } + // Check `target_groups` deprecation. + if c.TargetGroups != nil && c.StaticConfigs != nil { + return fmt.Errorf("'target_groups' is deprecated, configure static targets via 'static_configs' only") + } + if c.TargetGroups != nil { + log.Warnf("The 'target_groups' option for scrape configurations is deprecated, use 'static_configs' instead") + c.StaticConfigs = c.TargetGroups + } // Check for users putting URLs in target groups. if len(c.RelabelConfigs) == 0 { - for _, tg := range c.TargetGroups { + for _, tg := range c.StaticConfigs { for _, t := range tg.Targets { if err = CheckTargetAddress(t[model.AddressLabel]); err != nil { return err diff --git a/config/config_test.go b/config/config_test.go index 655133b20..a7555d878 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -57,7 +57,7 @@ var expectedConf = &Config{ BearerTokenFile: "testdata/valid_token_file", - TargetGroups: []*TargetGroup{ + StaticConfigs: []*TargetGroup{ { Targets: []model.LabelSet{ {model.AddressLabel: "localhost:9090"}, @@ -409,8 +409,8 @@ func TestBadConfigs(t *testing.T) { } } -func TestBadTargetGroup(t *testing.T) { - content, err := ioutil.ReadFile("testdata/tgroup.bad.json") +func TestBadStaticConfigs(t *testing.T) { + content, err := ioutil.ReadFile("testdata/static_config.bad.json") if err != nil { t.Fatal(err) } diff --git a/config/testdata/conf.good.yml b/config/testdata/conf.good.yml index a28fc2029..b911db767 100644 --- a/config/testdata/conf.good.yml +++ b/config/testdata/conf.good.yml @@ -32,7 +32,7 @@ scrape_configs: - files: - bar/*.yaml - target_groups: + static_configs: - targets: ['localhost:9090', 'localhost:9191'] labels: my: label diff --git a/config/testdata/tgroup.bad.json b/config/testdata/static_config.bad.json similarity index 100% rename from config/testdata/tgroup.bad.json rename to config/testdata/static_config.bad.json diff --git a/config/testdata/url_in_targetgroup.bad.yml b/config/testdata/url_in_targetgroup.bad.yml index 48a184599..a57d757db 100644 --- a/config/testdata/url_in_targetgroup.bad.yml +++ b/config/testdata/url_in_targetgroup.bad.yml @@ -1,5 +1,5 @@ scrape_configs: - job_name: prometheus - target_groups: + static_configs: - targets: - http://bad diff --git a/retrieval/targetmanager.go b/retrieval/targetmanager.go index 2a25c48f2..b5de5962e 100644 --- a/retrieval/targetmanager.go +++ b/retrieval/targetmanager.go @@ -402,8 +402,8 @@ func providersFromConfig(cfg *config.ScrapeConfig) map[string]TargetProvider { for i, c := range cfg.AzureSDConfigs { app("azure", i, discovery.NewAzureDiscovery(c)) } - if len(cfg.TargetGroups) > 0 { - app("static", 0, NewStaticProvider(cfg.TargetGroups)) + if len(cfg.StaticConfigs) > 0 { + app("static", 0, NewStaticProvider(cfg.StaticConfigs)) } return providers