config: error on missing regex in relabel config.

Fixes issue #787.
This commit is contained in:
Fabian Reinartz 2015-06-10 23:40:39 +02:00
parent db4df06414
commit 458550560c
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']