From e29d9394e52cb381e4befaeaaa0ea412cf3c0ea7 Mon Sep 17 00:00:00 2001 From: Alexey Miroshkin Date: Mon, 29 Aug 2016 16:01:45 +0200 Subject: [PATCH] Forbid invalid relabel configurations This fix adds check if target_label value is set in case if action is replace or hashmod Issue [#1900] --- config/config.go | 3 +++ config/config_test.go | 6 ++++++ config/testdata/target_label_hashmod_missing.bad.yml | 6 ++++++ config/testdata/target_label_missing.bad.yml | 4 ++++ 4 files changed, 19 insertions(+) create mode 100644 config/testdata/target_label_hashmod_missing.bad.yml create mode 100644 config/testdata/target_label_missing.bad.yml diff --git a/config/config.go b/config/config.go index 171c5ed6f..3141ca8e6 100644 --- a/config/config.go +++ b/config/config.go @@ -963,6 +963,9 @@ func (c *RelabelConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { if c.Modulus == 0 && c.Action == RelabelHashMod { return fmt.Errorf("relabel configuration for hashmod requires non-zero modulus") } + if (c.Action == RelabelReplace || c.Action == RelabelHashMod) && c.TargetLabel == "" { + return fmt.Errorf("relabel configuration for %s action requires 'target_label' value", c.Action) + } return nil } diff --git a/config/config_test.go b/config/config_test.go index 23d5d822e..2b0d1b8da 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -397,6 +397,12 @@ var expectedErrors = []struct { }, { filename: "url_in_targetgroup.bad.yml", errMsg: "\"http://bad\" is not a valid hostname", + }, { + filename: "target_label_missing.bad.yml", + errMsg: "relabel configuration for replace action requires 'target_label' value", + }, { + filename: "target_label_hashmod_missing.bad.yml", + errMsg: "relabel configuration for hashmod action requires 'target_label' value", }, } diff --git a/config/testdata/target_label_hashmod_missing.bad.yml b/config/testdata/target_label_hashmod_missing.bad.yml new file mode 100644 index 000000000..c919ac707 --- /dev/null +++ b/config/testdata/target_label_hashmod_missing.bad.yml @@ -0,0 +1,6 @@ +scrape_configs: + - job_name: prometheus + relabel_configs: + - source_labels: [__address__] + modulus: 8 + action: hashmod diff --git a/config/testdata/target_label_missing.bad.yml b/config/testdata/target_label_missing.bad.yml new file mode 100644 index 000000000..d7e8de3f9 --- /dev/null +++ b/config/testdata/target_label_missing.bad.yml @@ -0,0 +1,4 @@ +scrape_configs: + - job_name: prometheus + relabel_configs: + - regex: abcdef