Browse Source

Handle null Regex in the config as the empty regex. (#2150)

pull/2156/head
Brian Brazil 8 years ago committed by GitHub
parent
commit
d1ece12c70
  1. 3
      config/config.go
  2. 6
      config/config_test.go
  3. 3
      config/testdata/conf.good.yml

3
config/config.go

@ -1017,6 +1017,9 @@ func (c *RelabelConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
if err := checkOverflow(c.XXX, "relabel_config"); err != nil {
return err
}
if c.Regex.Regexp == nil {
c.Regex = MustNewRegexp("")
}
if c.Modulus == 0 && c.Action == RelabelHashMod {
return fmt.Errorf("relabel configuration for hashmod requires non-zero modulus")
}

6
config/config_test.go

@ -115,6 +115,12 @@ var expectedConf = &Config{
Regex: DefaultRelabelConfig.Regex,
Replacement: "static",
Action: RelabelReplace,
}, {
TargetLabel: "abc",
Separator: ";",
Regex: MustNewRegexp(""),
Replacement: "static",
Action: RelabelReplace,
},
},
},

3
config/testdata/conf.good.yml vendored

@ -54,6 +54,9 @@ scrape_configs:
target_label: cde
- replacement: static
target_label: abc
- regex:
replacement: static
target_label: abc
bearer_token_file: valid_token_file

Loading…
Cancel
Save