diff --git a/config/config.go b/config/config.go index f757c5c248..2c72d14df4 100644 --- a/config/config.go +++ b/config/config.go @@ -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. diff --git a/config/config_test.go b/config/config_test.go index 8e4590b3f6..506d5a8d0a 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -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`, }, } diff --git a/config/testdata/remote_read_url_missing.bad.yml b/config/testdata/remote_read_url_missing.bad.yml new file mode 100644 index 0000000000..524c1c68ec --- /dev/null +++ b/config/testdata/remote_read_url_missing.bad.yml @@ -0,0 +1,2 @@ +remote_read: + - url: diff --git a/config/testdata/remote_write_url_missing.bad.yml b/config/testdata/remote_write_url_missing.bad.yml new file mode 100644 index 0000000000..50780199c0 --- /dev/null +++ b/config/testdata/remote_write_url_missing.bad.yml @@ -0,0 +1,2 @@ +remote_write: + - url: