Make sure that url for remote_read/write is not nil (#3024)

This commit is contained in:
Yuki Ito 2017-08-07 00:49:45 -07:00 committed by Brian Brazil
parent 62047e5c97
commit 1bf3b91ae0
4 changed files with 18 additions and 2 deletions

View file

@ -1404,7 +1404,7 @@ func (re Regexp) MarshalYAML() (interface{}, error) {
// RemoteWriteConfig is the configuration for writing to remote storage.
type RemoteWriteConfig struct {
URL *URL `yaml:"url,omitempty"`
URL *URL `yaml:"url"`
RemoteTimeout model.Duration `yaml:"remote_timeout,omitempty"`
WriteRelabelConfigs []*RelabelConfig `yaml:"write_relabel_configs,omitempty"`
@ -1424,6 +1424,9 @@ func (c *RemoteWriteConfig) UnmarshalYAML(unmarshal func(interface{}) error) err
if err := unmarshal((*plain)(c)); err != nil {
return err
}
if c.URL == nil {
return fmt.Errorf("url for remote_write is empty")
}
// The UnmarshalYAML method of HTTPClientConfig is not being called because it's not a pointer.
// We cannot make it a pointer as the parser panics for inlined pointer structs.
@ -1463,7 +1466,7 @@ type QueueConfig struct {
// RemoteReadConfig is the configuration for reading from remote storage.
type RemoteReadConfig struct {
URL *URL `yaml:"url,omitempty"`
URL *URL `yaml:"url"`
RemoteTimeout model.Duration `yaml:"remote_timeout,omitempty"`
// We cannot do proper Go type embedding below as the parser will then parse
@ -1481,6 +1484,9 @@ func (c *RemoteReadConfig) UnmarshalYAML(unmarshal func(interface{}) error) erro
if err := unmarshal((*plain)(c)); err != nil {
return err
}
if c.URL == nil {
return fmt.Errorf("url for remote_read is empty")
}
// The UnmarshalYAML method of HTTPClientConfig is not being called because it's not a pointer.
// We cannot make it a pointer as the parser panics for inlined pointer structs.

View file

@ -668,6 +668,12 @@ var expectedErrors = []struct {
}, {
filename: "unknown_global_attr.bad.yml",
errMsg: "unknown fields in global config: nonexistent_field",
}, {
filename: "remote_read_url_missing.bad.yml",
errMsg: `url for remote_read is empty`,
}, {
filename: "remote_write_url_missing.bad.yml",
errMsg: `url for remote_write is empty`,
},
}

View file

@ -0,0 +1,2 @@
remote_read:
- url:

View file

@ -0,0 +1,2 @@
remote_write:
- url: