diff --git a/config/config.go b/config/config.go index 482671182c..d399d26d9c 100644 --- a/config/config.go +++ b/config/config.go @@ -1019,6 +1019,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") } diff --git a/config/config_test.go b/config/config_test.go index 1da06cf0f5..e6590e18b2 100644 --- a/config/config_test.go +++ b/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, }, }, }, diff --git a/config/testdata/conf.good.yml b/config/testdata/conf.good.yml index e2387f074c..1038ea0d8b 100644 --- a/config/testdata/conf.good.yml +++ b/config/testdata/conf.good.yml @@ -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