From d1ece12c706334899834f290a4d2aa348512c3ee Mon Sep 17 00:00:00 2001 From: Brian Brazil Date: Thu, 3 Nov 2016 13:34:15 +0000 Subject: [PATCH] Handle null Regex in the config as the empty regex. (#2150) --- config/config.go | 3 +++ config/config_test.go | 6 ++++++ config/testdata/conf.good.yml | 3 +++ 3 files changed, 12 insertions(+) diff --git a/config/config.go b/config/config.go index c83b73109..0aadd6d22 100644 --- a/config/config.go +++ b/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") } diff --git a/config/config_test.go b/config/config_test.go index 17642f76c..3c5cf550b 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 14a8436f8..36177cc98 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