Browse Source

config: prevent overwrite of DefaultGlobalConfig

pull/773/head
Fabian Reinartz 10 years ago
parent
commit
f6c33a2347
  1. 6
      config/config.go
  2. 8
      config/config_test.go
  3. 2
      config/testdata/global_timeout.good.yml

6
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"`

8
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)

2
config/testdata/global_timeout.good.yml vendored

@ -0,0 +1,2 @@
global:
scrape_timeout: 1h
Loading…
Cancel
Save