mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Forbid invalid relabel configurations
This fix adds check if target_label value is set in case if action is replace or hashmod Issue [#1900]
This commit is contained in:
parent
c7bd563b26
commit
e29d9394e5
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
6
config/testdata/target_label_hashmod_missing.bad.yml
vendored
Normal file
6
config/testdata/target_label_hashmod_missing.bad.yml
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
scrape_configs:
|
||||
- job_name: prometheus
|
||||
relabel_configs:
|
||||
- source_labels: [__address__]
|
||||
modulus: 8
|
||||
action: hashmod
|
4
config/testdata/target_label_missing.bad.yml
vendored
Normal file
4
config/testdata/target_label_missing.bad.yml
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
scrape_configs:
|
||||
- job_name: prometheus
|
||||
relabel_configs:
|
||||
- regex: abcdef
|
Loading…
Reference in a new issue