From 458550560c7a21e8fced14fd2689a8bf2c8fba94 Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Wed, 10 Jun 2015 23:40:39 +0200 Subject: [PATCH] config: error on missing regex in relabel config. Fixes issue #787. --- config/config.go | 8 +++++++- config/config_test.go | 3 +++ config/testdata/regex_missing.bad.yml | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 config/testdata/regex_missing.bad.yml 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']