Skip to content

Commit

Permalink
Fix global config YAML issues
Browse files Browse the repository at this point in the history
  • Loading branch information
fabxc committed Feb 15, 2016
1 parent b3fb91e commit 37c709f
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 61 deletions.
26 changes: 16 additions & 10 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,27 +302,33 @@ type GlobalConfig struct {

// UnmarshalYAML implements the yaml.Unmarshaler interface.
func (c *GlobalConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
if err := unmarshal(c); err != nil {
// Create a clean global config as the previous one was already populated
// by the default due to the YAML parser behavior for empty blocks.
gc := &GlobalConfig{}
type plain GlobalConfig
if err := unmarshal((*plain)(gc)); err != nil {
return err
}
// First set the correct scrape interval, then check that the timeout
// (inferred or explicit) is not greater than that.
if c.ScrapeInterval == 0 {
c.ScrapeInterval = DefaultGlobalConfig.ScrapeInterval
if gc.ScrapeInterval == 0 {
gc.ScrapeInterval = DefaultGlobalConfig.ScrapeInterval
}
if c.ScrapeTimeout > c.ScrapeInterval {
if gc.ScrapeTimeout > gc.ScrapeInterval {
return fmt.Errorf("global scrape timeout greater than scrape interval")
}
if c.ScrapeTimeout == 0 {
if DefaultGlobalConfig.ScrapeTimeout > c.ScrapeInterval {
c.ScrapeTimeout = c.ScrapeInterval
if gc.ScrapeTimeout == 0 {
if DefaultGlobalConfig.ScrapeTimeout > gc.ScrapeInterval {
gc.ScrapeTimeout = gc.ScrapeInterval
} else {
c.ScrapeTimeout = DefaultGlobalConfig.ScrapeTimeout
gc.ScrapeTimeout = DefaultGlobalConfig.ScrapeTimeout
}
}
if c.EvaluationInterval == 0 {
c.EvaluationInterval = DefaultGlobalConfig.EvaluationInterval
if gc.EvaluationInterval == 0 {
gc.EvaluationInterval = DefaultGlobalConfig.EvaluationInterval
}
*c = *gc

return checkOverflow(c.XXX, "global config")
}

Expand Down
1 change: 1 addition & 0 deletions config/testdata/global_timeout.good.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
global:
scrape_timeout: 1h
scrape_interval: 1h
102 changes: 51 additions & 51 deletions web/ui/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 37c709f

Please sign in to comment.