mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 21:54:10 -08:00
Prevent invalid label names with labelmap (#3868)
This change ensures that the relabeling configurations using labelmap can't generate invalid label names.
This commit is contained in:
parent
1fd20fc954
commit
fc8cf08f42
|
@ -569,6 +569,9 @@ func (c *RelabelConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
if c.Action == RelabelReplace && !relabelTarget.MatchString(c.TargetLabel) {
|
if c.Action == RelabelReplace && !relabelTarget.MatchString(c.TargetLabel) {
|
||||||
return fmt.Errorf("%q is invalid 'target_label' for %s action", c.TargetLabel, c.Action)
|
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() {
|
if c.Action == RelabelHashMod && !model.LabelName(c.TargetLabel).IsValid() {
|
||||||
return fmt.Errorf("%q is invalid 'target_label' for %s action", c.TargetLabel, c.Action)
|
return fmt.Errorf("%q is invalid 'target_label' for %s action", c.TargetLabel, c.Action)
|
||||||
}
|
}
|
||||||
|
|
|
@ -635,6 +635,9 @@ var expectedErrors = []struct {
|
||||||
}, {
|
}, {
|
||||||
filename: "labeldrop5.bad.yml",
|
filename: "labeldrop5.bad.yml",
|
||||||
errMsg: "labeldrop action requires only 'regex', and no other fields",
|
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",
|
filename: "rules.bad.yml",
|
||||||
errMsg: "invalid rule file path",
|
errMsg: "invalid rule file path",
|
||||||
|
|
5
config/testdata/labelmap.bad.yml
vendored
Normal file
5
config/testdata/labelmap.bad.yml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
scrape_configs:
|
||||||
|
- job_name: prometheus
|
||||||
|
relabel_configs:
|
||||||
|
- action: labelmap
|
||||||
|
replacement: l-$1
|
Loading…
Reference in a new issue