mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-26 06:04:05 -08:00
Fix missing defaults for empty global config blocks
This commit is contained in:
parent
2a53b107c1
commit
187fe4e3d3
|
@ -147,6 +147,12 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
if err := unmarshal((*plain)(c)); err != nil {
|
if err := unmarshal((*plain)(c)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// If a global block was open but empty the default global config is overwritten.
|
||||||
|
// We have to restore it here.
|
||||||
|
if c.GlobalConfig.isZero() {
|
||||||
|
c.GlobalConfig = DefaultGlobalConfig
|
||||||
|
}
|
||||||
|
|
||||||
for _, rf := range c.RuleFiles {
|
for _, rf := range c.RuleFiles {
|
||||||
if !patRulePath.MatchString(rf) {
|
if !patRulePath.MatchString(rf) {
|
||||||
return fmt.Errorf("invalid rule file path %q", rf)
|
return fmt.Errorf("invalid rule file path %q", rf)
|
||||||
|
@ -196,6 +202,14 @@ func (c *GlobalConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
return checkOverflow(c.XXX, "global config")
|
return checkOverflow(c.XXX, "global config")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isZero returns true iff the global config is the zero value.
|
||||||
|
func (c *GlobalConfig) isZero() bool {
|
||||||
|
return c.Labels == nil &&
|
||||||
|
c.ScrapeInterval == 0 &&
|
||||||
|
c.ScrapeTimeout == 0 &&
|
||||||
|
c.EvaluationInterval == 0
|
||||||
|
}
|
||||||
|
|
||||||
// ScrapeConfig configures a scraping unit for Prometheus.
|
// ScrapeConfig configures a scraping unit for Prometheus.
|
||||||
type ScrapeConfig struct {
|
type ScrapeConfig struct {
|
||||||
// The job name to which the job label is set by default.
|
// The job name to which the job label is set by default.
|
||||||
|
|
|
@ -261,3 +261,16 @@ func TestEmptyConfig(t *testing.T) {
|
||||||
t.Fatalf("want %v, got %v", exp, c)
|
t.Fatalf("want %v, got %v", exp, c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEmptyGlobalBlock(t *testing.T) {
|
||||||
|
c, err := Load("global:\n")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Unexpected error parsing empty config file: %s", err)
|
||||||
|
}
|
||||||
|
exp := DefaultConfig
|
||||||
|
exp.original = "global:\n"
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(*c, exp) {
|
||||||
|
t.Fatalf("want %v, got %v", exp, c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue