Check if label value is valid when unmarhsaling external labels from

YAML, add a test to config_tests for valid/invalid external label
value.

Signed-off-by: Callum Styan <callumstyan@gmail.com>
This commit is contained in:
Callum Styan 2019-03-14 14:16:29 -07:00 committed by Tom Wilkie
parent 807fd33ecc
commit 5603b857a9
3 changed files with 9 additions and 0 deletions

View File

@ -304,6 +304,9 @@ func (c *GlobalConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
if !model.LabelName(l.Name).IsValid() {
return fmt.Errorf("%q is not a valid label name", l.Name)
}
if !model.LabelValue(l.Value).IsValid() {
return fmt.Errorf("%q is not a valid label value", l.Value)
}
}
// First set the correct scrape interval, then check that the timeout

View File

@ -714,6 +714,9 @@ var expectedErrors = []struct {
}, {
filename: "labelname2.bad.yml",
errMsg: `"not:allowed" is not a valid label name`,
}, {
filename: "labelvalue.bad.yml",
errMsg: `"\xff" is not a valid label value`,
}, {
filename: "regex.bad.yml",
errMsg: "error parsing regexp",

3
config/testdata/labelvalue.bad.yml vendored Normal file
View File

@ -0,0 +1,3 @@
global:
external_labels:
name: !!binary "/w=="