Check relabel action at yaml unmarshal stage (#9224)
Signed-off-by: DrAuYueng <ouyang1204@gmail.com>
This commit is contained in:
parent
70f597b033
commit
e8be1d0a5c
|
@ -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) {
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
scrape_configs:
|
||||||
|
- job_name: prometheus
|
||||||
|
relabel_configs:
|
||||||
|
- action: null
|
|
@ -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")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue