diff --git a/config/config_test.go b/config/config_test.go index d5cc092a27..4d9155a381 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -1302,6 +1302,10 @@ var expectedErrors = []struct { filename: "http_url_bad_scheme.bad.yml", errMsg: "URL scheme must be 'http' or 'https'", }, + { + filename: "empty_scrape_config_action.bad.yml", + errMsg: "relabel action cannot be empty", + }, } func TestBadConfigs(t *testing.T) { diff --git a/config/testdata/empty_scrape_config_action.bad.yml b/config/testdata/empty_scrape_config_action.bad.yml new file mode 100644 index 0000000000..8e5f747a25 --- /dev/null +++ b/config/testdata/empty_scrape_config_action.bad.yml @@ -0,0 +1,4 @@ +scrape_configs: + - job_name: prometheus + relabel_configs: + - action: null diff --git a/pkg/relabel/relabel.go b/pkg/relabel/relabel.go index 0bd00fe8ac..ec452f5b52 100644 --- a/pkg/relabel/relabel.go +++ b/pkg/relabel/relabel.go @@ -100,6 +100,9 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error { if c.Regex.Regexp == nil { c.Regex = MustNewRegexp("") } + if c.Action == "" { + return errors.Errorf("relabel action cannot be empty") + } if c.Modulus == 0 && c.Action == HashMod { return errors.Errorf("relabel configuration for hashmod requires non-zero modulus") }