storage/remote: make tests use separate remote write configs
So tests can be run in parallel without races.
@@ -30,7 +30,8 @@ import (
"github.com/prometheus/prometheus/model/relabel"
)
-var cfg = config.RemoteWriteConfig{
+func testRemoteWriteConfig() *config.RemoteWriteConfig {
+ return &config.RemoteWriteConfig{
Name: "dev",
URL: &common_config.URL{
URL: &url.URL{
@@ -40,6 +41,7 @@ var cfg = config.RemoteWriteConfig{
},
QueueConfig: config.DefaultQueueConfig,
}
+}
func TestNoDuplicateWriteConfigs(t *testing.T) {
dir, err := ioutil.TempDir("", "TestNoDuplicateWriteConfigs")
@@ -136,14 +138,17 @@ func TestRestartOnNameChange(t *testing.T) {
require.NoError(t, os.RemoveAll(dir))
}()
+ cfg := testRemoteWriteConfig()
+
hash, err := toHash(cfg)
require.NoError(t, err)
s := NewWriteStorage(nil, nil, dir, time.Millisecond, nil)
+
conf := &config.Config{
GlobalConfig: config.DefaultGlobalConfig,
RemoteWriteConfigs: []*config.RemoteWriteConfig{
- &cfg,
+ cfg,
},
}
require.NoError(t, s.ApplyConfig(conf))
@@ -238,7 +243,7 @@ func TestUpdateExternalLabels(t *testing.T) {
conf := &config.Config{
GlobalConfig: config.GlobalConfig{},
RemoteWriteConfigs: []*config.RemoteWriteConfig{
- &cfg,
+ testRemoteWriteConfig(),
},
}
hash, err := toHash(conf.RemoteWriteConfigs[0])
@@ -270,14 +275,19 @@ func TestWriteStorageApplyConfigsIdempotent(t *testing.T) {
conf := &config.Config{
GlobalConfig: config.GlobalConfig{},
RemoteWriteConfigs: []*config.RemoteWriteConfig{
- &config.DefaultRemoteWriteConfig,
- },
- }
+ {
+ RemoteTimeout: config.DefaultRemoteWriteConfig.RemoteTimeout,
+ QueueConfig: config.DefaultRemoteWriteConfig.QueueConfig,
+ MetadataConfig: config.DefaultRemoteWriteConfig.MetadataConfig,
+ HTTPClientConfig: config.DefaultRemoteWriteConfig.HTTPClientConfig,
// We need to set URL's so that metric creation doesn't panic.
- conf.RemoteWriteConfigs[0].URL = &common_config.URL{
+ URL: &common_config.URL{
URL: &url.URL{
Host: "http://test-storage.com",
},
+ },
+ },
+ },
}
hash, err := toHash(conf.RemoteWriteConfigs[0])
require.NoError(t, err)
