diff --git a/config/config.go b/config/config.go index 03aff55ccb..77da619c28 100644 --- a/config/config.go +++ b/config/config.go @@ -409,7 +409,13 @@ type RelabelConfig struct { func (c *RelabelConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { *c = DefaultRelabelConfig type plain RelabelConfig - return unmarshal((*plain)(c)) + if err := unmarshal((*plain)(c)); err != nil { + return err + } + if c.Regex == nil { + return fmt.Errorf("relabel configuration requires a regular expression") + } + return nil } // Regexp encapsulates a regexp.Regexp and makes it YAML marshallable. diff --git a/config/config_test.go b/config/config_test.go index 4d25c41acd..ebabe72f65 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -164,6 +164,9 @@ var expectedErrors = []struct { }, { filename: "regex.bad.yml", errMsg: "error parsing regexp", + }, { + filename: "regex_missing.bad.yml", + errMsg: "relabel configuration requires a regular expression", }, { filename: "rules.bad.yml", errMsg: "invalid rule file path", diff --git a/config/testdata/regex_missing.bad.yml b/config/testdata/regex_missing.bad.yml new file mode 100644 index 0000000000..aff2cf096b --- /dev/null +++ b/config/testdata/regex_missing.bad.yml @@ -0,0 +1,4 @@ +scrape_configs: + - job_name: prometheus + relabel_configs: + - source_labels: ['blub']