Merge pull request #788 from prometheus/fabxc/cfg-re

config: error on missing regex in relabel config.
This commit is contained in:
Fabian Reinartz 2015-06-11 14:49:39 +02:00
commit bc09484608
3 changed files with 14 additions and 1 deletions

View file

@ -409,7 +409,13 @@ type RelabelConfig struct {
func (c *RelabelConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
*c = DefaultRelabelConfig
type plain RelabelConfig
return unmarshal((*plain)(c))
if err := unmarshal((*plain)(c)); err != nil {
return err
}
if c.Regex == nil {
return fmt.Errorf("relabel configuration requires a regular expression")
}
return nil
}
// Regexp encapsulates a regexp.Regexp and makes it YAML marshallable.

View file

@ -164,6 +164,9 @@ var expectedErrors = []struct {
}, {
filename: "regex.bad.yml",
errMsg: "error parsing regexp",
}, {
filename: "regex_missing.bad.yml",
errMsg: "relabel configuration requires a regular expression",
}, {
filename: "rules.bad.yml",
errMsg: "invalid rule file path",

4
config/testdata/regex_missing.bad.yml vendored Normal file
View file

@ -0,0 +1,4 @@
scrape_configs:
- job_name: prometheus
relabel_configs:
- source_labels: ['blub']