diff --git a/config/config.go b/config/config.go index 9c80d4f63..824044f1d 100644 --- a/config/config.go +++ b/config/config.go @@ -569,6 +569,9 @@ func (c *RelabelConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { if c.Action == RelabelReplace && !relabelTarget.MatchString(c.TargetLabel) { return fmt.Errorf("%q is invalid 'target_label' for %s action", c.TargetLabel, c.Action) } + if c.Action == RelabelLabelMap && !relabelTarget.MatchString(c.Replacement) { + return fmt.Errorf("%q is invalid 'replacement' for %s action", c.Replacement, c.Action) + } if c.Action == RelabelHashMod && !model.LabelName(c.TargetLabel).IsValid() { return fmt.Errorf("%q is invalid 'target_label' for %s action", c.TargetLabel, c.Action) } diff --git a/config/config_test.go b/config/config_test.go index 88f3b4d3e..07cbb1b56 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -635,6 +635,9 @@ var expectedErrors = []struct { }, { filename: "labeldrop5.bad.yml", errMsg: "labeldrop action requires only 'regex', and no other fields", + }, { + filename: "labelmap.bad.yml", + errMsg: "\"l-$1\" is invalid 'replacement' for labelmap action", }, { filename: "rules.bad.yml", errMsg: "invalid rule file path", diff --git a/config/testdata/labelmap.bad.yml b/config/testdata/labelmap.bad.yml new file mode 100644 index 000000000..29d265399 --- /dev/null +++ b/config/testdata/labelmap.bad.yml @@ -0,0 +1,5 @@ +scrape_configs: + - job_name: prometheus + relabel_configs: + - action: labelmap + replacement: l-$1