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

This commit is contained in:
Brian Brazil 2016-11-03 13:34:15 +00:00 committed by GitHub
parent fc4d9c13e8
commit d1ece12c70
3 changed files with 12 additions and 0 deletions

View File

@ -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")
}

View File

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

View File

@ -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