Check relabel action at yaml unmarshal stage (#9224)

Signed-off-by: DrAuYueng <ouyang1204@gmail.com>
This commit is contained in:
DrAuYueng 2021-08-31 23:52:57 +08:00 committed by GitHub
parent 70f597b033
commit e8be1d0a5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 0 deletions

View File

@ -1302,6 +1302,10 @@ var expectedErrors = []struct {
filename: "http_url_bad_scheme.bad.yml", filename: "http_url_bad_scheme.bad.yml",
errMsg: "URL scheme must be 'http' or 'https'", 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) { func TestBadConfigs(t *testing.T) {

View File

@ -0,0 +1,4 @@
scrape_configs:
- job_name: prometheus
relabel_configs:
- action: null

View File

@ -100,6 +100,9 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
if c.Regex.Regexp == nil { if c.Regex.Regexp == nil {
c.Regex = MustNewRegexp("") c.Regex = MustNewRegexp("")
} }
if c.Action == "" {
return errors.Errorf("relabel action cannot be empty")
}
if c.Modulus == 0 && c.Action == HashMod { if c.Modulus == 0 && c.Action == HashMod {
return errors.Errorf("relabel configuration for hashmod requires non-zero modulus") return errors.Errorf("relabel configuration for hashmod requires non-zero modulus")
} }