mirror of https://github.com/prometheus/prometheus
Merge pull request #1716 from prometheus/fabxc-static-configs
config: deprecate `target_groups` for `static_configs`pull/1718/head
commit
76ffdf4cc5
|
@ -23,6 +23,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/prometheus/common/log"
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
@ -399,7 +400,9 @@ type ScrapeConfig struct {
|
||||||
TLSConfig TLSConfig `yaml:"tls_config,omitempty"`
|
TLSConfig TLSConfig `yaml:"tls_config,omitempty"`
|
||||||
|
|
||||||
// List of labeled target groups for this job.
|
// 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.
|
// List of DNS service discovery configurations.
|
||||||
DNSSDConfigs []*DNSSDConfig `yaml:"dns_sd_configs,omitempty"`
|
DNSSDConfigs []*DNSSDConfig `yaml:"dns_sd_configs,omitempty"`
|
||||||
// List of file service discovery configurations.
|
// 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) {
|
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")
|
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.
|
// Check for users putting URLs in target groups.
|
||||||
if len(c.RelabelConfigs) == 0 {
|
if len(c.RelabelConfigs) == 0 {
|
||||||
for _, tg := range c.TargetGroups {
|
for _, tg := range c.StaticConfigs {
|
||||||
for _, t := range tg.Targets {
|
for _, t := range tg.Targets {
|
||||||
if err = CheckTargetAddress(t[model.AddressLabel]); err != nil {
|
if err = CheckTargetAddress(t[model.AddressLabel]); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -57,7 +57,7 @@ var expectedConf = &Config{
|
||||||
|
|
||||||
BearerTokenFile: "testdata/valid_token_file",
|
BearerTokenFile: "testdata/valid_token_file",
|
||||||
|
|
||||||
TargetGroups: []*TargetGroup{
|
StaticConfigs: []*TargetGroup{
|
||||||
{
|
{
|
||||||
Targets: []model.LabelSet{
|
Targets: []model.LabelSet{
|
||||||
{model.AddressLabel: "localhost:9090"},
|
{model.AddressLabel: "localhost:9090"},
|
||||||
|
@ -409,8 +409,8 @@ func TestBadConfigs(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBadTargetGroup(t *testing.T) {
|
func TestBadStaticConfigs(t *testing.T) {
|
||||||
content, err := ioutil.ReadFile("testdata/tgroup.bad.json")
|
content, err := ioutil.ReadFile("testdata/static_config.bad.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ scrape_configs:
|
||||||
- files:
|
- files:
|
||||||
- bar/*.yaml
|
- bar/*.yaml
|
||||||
|
|
||||||
target_groups:
|
static_configs:
|
||||||
- targets: ['localhost:9090', 'localhost:9191']
|
- targets: ['localhost:9090', 'localhost:9191']
|
||||||
labels:
|
labels:
|
||||||
my: label
|
my: label
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
scrape_configs:
|
scrape_configs:
|
||||||
- job_name: prometheus
|
- job_name: prometheus
|
||||||
target_groups:
|
static_configs:
|
||||||
- targets:
|
- targets:
|
||||||
- http://bad
|
- http://bad
|
||||||
|
|
|
@ -402,8 +402,8 @@ func providersFromConfig(cfg *config.ScrapeConfig) map[string]TargetProvider {
|
||||||
for i, c := range cfg.AzureSDConfigs {
|
for i, c := range cfg.AzureSDConfigs {
|
||||||
app("azure", i, discovery.NewAzureDiscovery(c))
|
app("azure", i, discovery.NewAzureDiscovery(c))
|
||||||
}
|
}
|
||||||
if len(cfg.TargetGroups) > 0 {
|
if len(cfg.StaticConfigs) > 0 {
|
||||||
app("static", 0, NewStaticProvider(cfg.TargetGroups))
|
app("static", 0, NewStaticProvider(cfg.StaticConfigs))
|
||||||
}
|
}
|
||||||
|
|
||||||
return providers
|
return providers
|
||||||
|
|
Loading…
Reference in New Issue