diff --git a/config/config.go b/config/config.go index c94eda712..03aff55cc 100644 --- a/config/config.go +++ b/config/config.go @@ -46,7 +46,7 @@ func LoadFromFile(filename string) (*Config, error) { var ( // The default top-level configuration. DefaultConfig = Config{ - GlobalConfig: &DefaultGlobalConfig, + GlobalConfig: DefaultGlobalConfig, } // The default global configuration. @@ -56,7 +56,7 @@ var ( EvaluationInterval: Duration(1 * time.Minute), } - // Te default scrape configuration. + // The default scrape configuration. DefaultScrapeConfig = ScrapeConfig{ // ScrapeTimeout and ScrapeInterval default to the // configured globals. @@ -89,7 +89,7 @@ var ( // Config is the top-level configuration for Prometheus's config files. type Config struct { - GlobalConfig *GlobalConfig `yaml:"global"` + GlobalConfig GlobalConfig `yaml:"global"` RuleFiles []string `yaml:"rule_files,omitempty"` ScrapeConfigs []*ScrapeConfig `yaml:"scrape_configs,omitempty"` diff --git a/config/config_test.go b/config/config_test.go index 13a7ee54a..b72e2f97e 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -13,7 +13,7 @@ import ( ) var expectedConf = &Config{ - GlobalConfig: &GlobalConfig{ + GlobalConfig: GlobalConfig{ ScrapeInterval: Duration(15 * time.Second), ScrapeTimeout: DefaultGlobalConfig.ScrapeTimeout, EvaluationInterval: Duration(30 * time.Second), @@ -118,6 +118,12 @@ var expectedConf = &Config{ } func TestLoadConfig(t *testing.T) { + // Parse a valid file that sets a global scrape timeout. This tests whether parsing + // an overwritten default field in the global config permanently changes the default. + if _, err := LoadFromFile("testdata/global_timeout.good.yml"); err != nil { + t.Errorf("Error parsing %s: %s", "testdata/conf.good.yml", err) + } + c, err := LoadFromFile("testdata/conf.good.yml") if err != nil { t.Errorf("Error parsing %s: %s", "testdata/conf.good.yml", err) diff --git a/config/testdata/global_timeout.good.yml b/config/testdata/global_timeout.good.yml new file mode 100644 index 000000000..2ad107136 --- /dev/null +++ b/config/testdata/global_timeout.good.yml @@ -0,0 +1,2 @@ +global: + scrape_timeout: 1h