diff --git a/config/config.go b/config/config.go index f757c5c248e984bb96915305a1273eb67f163471..2c72d14df4373de729706540cbfb4275e5957254 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 8e4590b3f65002c99f6475a8507aed1ffd01fb01..506d5a8d0aa06a39c0b7365aa32408834889bad1 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 0000000000000000000000000000000000000000..524c1c68ecc32b26d65a59119ab3678810695db3 --- /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 0000000000000000000000000000000000000000..50780199c02ab4dc0652cb6437e7f8899c7f500d --- /dev/null +++ b/config/testdata/remote_write_url_missing.bad.yml @@ -0,0 +1,2 @@ +remote_write: + - url: