diff --git a/exporter/elasticsearchexporter/config_test.go b/exporter/elasticsearchexporter/config_test.go index d831801721dd..e279ca472cea 100644 --- a/exporter/elasticsearchexporter/config_test.go +++ b/exporter/elasticsearchexporter/config_test.go @@ -73,14 +73,14 @@ func TestConfig(t *testing.T) { Enabled: false, }, Pipeline: "mypipeline", - ClientConfig: confighttp.ClientConfig{ - Timeout: 2 * time.Minute, - MaxIdleConns: &defaultMaxIdleConns, - IdleConnTimeout: &defaultIdleConnTimeout, - Headers: map[string]configopaque.String{ + ClientConfig: withDefaultHTTPClientConfig(func(cfg *confighttp.ClientConfig) { + cfg.Timeout = 2 * time.Minute + cfg.MaxIdleConns = &defaultMaxIdleConns + cfg.IdleConnTimeout = &defaultIdleConnTimeout + cfg.Headers = map[string]configopaque.String{ "myheader": "test", - }, - }, + } + }), Authentication: AuthenticationSettings{ User: "elastic", Password: "search", @@ -143,14 +143,14 @@ func TestConfig(t *testing.T) { Enabled: false, }, Pipeline: "mypipeline", - ClientConfig: confighttp.ClientConfig{ - Timeout: 2 * time.Minute, - MaxIdleConns: &defaultMaxIdleConns, - IdleConnTimeout: &defaultIdleConnTimeout, - Headers: map[string]configopaque.String{ + ClientConfig: withDefaultHTTPClientConfig(func(cfg *confighttp.ClientConfig) { + cfg.Timeout = 2 * time.Minute + cfg.MaxIdleConns = &defaultMaxIdleConns + cfg.IdleConnTimeout = &defaultIdleConnTimeout + cfg.Headers = map[string]configopaque.String{ "myheader": "test", - }, - }, + } + }), Authentication: AuthenticationSettings{ User: "elastic", Password: "search", @@ -213,14 +213,14 @@ func TestConfig(t *testing.T) { Enabled: false, }, Pipeline: "mypipeline", - ClientConfig: confighttp.ClientConfig{ - Timeout: 2 * time.Minute, - MaxIdleConns: &defaultMaxIdleConns, - IdleConnTimeout: &defaultIdleConnTimeout, - Headers: map[string]configopaque.String{ + ClientConfig: withDefaultHTTPClientConfig(func(cfg *confighttp.ClientConfig) { + cfg.Timeout = 2 * time.Minute + cfg.MaxIdleConns = &defaultMaxIdleConns + cfg.IdleConnTimeout = &defaultIdleConnTimeout + cfg.Headers = map[string]configopaque.String{ "myheader": "test", - }, - }, + } + }), Authentication: AuthenticationSettings{ User: "elastic", Password: "search", @@ -423,3 +423,11 @@ func withDefaultConfig(fns ...func(*Config)) *Config { } return cfg } + +func withDefaultHTTPClientConfig(fns ...func(config *confighttp.ClientConfig)) confighttp.ClientConfig { + cfg := confighttp.NewDefaultClientConfig() + for _, fn := range fns { + fn(&cfg) + } + return cfg +} diff --git a/exporter/opensearchexporter/config_test.go b/exporter/opensearchexporter/config_test.go index 142a1b819a03..d6840945c588 100644 --- a/exporter/opensearchexporter/config_test.go +++ b/exporter/opensearchexporter/config_test.go @@ -49,16 +49,16 @@ func TestLoadConfig(t *testing.T) { expected: &Config{ Dataset: "ngnix", Namespace: "eu", - ClientConfig: confighttp.ClientConfig{ - Endpoint: sampleEndpoint, - Timeout: 2 * time.Minute, - Headers: map[string]configopaque.String{ + ClientConfig: withDefaultHTTPClientConfig(func(config *confighttp.ClientConfig) { + config.Endpoint = sampleEndpoint + config.Timeout = 2 * time.Minute + config.Headers = map[string]configopaque.String{ "myheader": "test", - }, - MaxIdleConns: &maxIdleConns, - IdleConnTimeout: &idleConnTimeout, - Auth: &configauth.Authentication{AuthenticatorID: component.MustNewID("sample_basic_auth")}, - }, + } + config.MaxIdleConns = &maxIdleConns + config.IdleConnTimeout = &idleConnTimeout + config.Auth = &configauth.Authentication{AuthenticatorID: component.MustNewID("sample_basic_auth")} + }), BackOffConfig: configretry.BackOffConfig{ Enabled: true, InitialInterval: 100 * time.Millisecond, @@ -133,3 +133,11 @@ func withDefaultConfig(fns ...func(*Config)) *Config { } return cfg } + +func withDefaultHTTPClientConfig(fns ...func(config *confighttp.ClientConfig)) confighttp.ClientConfig { + cfg := confighttp.NewDefaultClientConfig() + for _, fn := range fns { + fn(&cfg) + } + return cfg +} diff --git a/exporter/zipkinexporter/config_test.go b/exporter/zipkinexporter/config_test.go index a27c6c7ae8e4..0d27f9816bda 100644 --- a/exporter/zipkinexporter/config_test.go +++ b/exporter/zipkinexporter/config_test.go @@ -57,16 +57,16 @@ func TestLoadConfig(t *testing.T) { NumConsumers: 2, QueueSize: 10, }, - ClientConfig: confighttp.ClientConfig{ - Endpoint: "https://somedest:1234/api/v2/spans", - WriteBufferSize: 524288, - Timeout: 5 * time.Second, - TLSSetting: configtls.ClientConfig{ + ClientConfig: withDefaultHTTPClientConfig(func(config *confighttp.ClientConfig) { + config.Endpoint = "https://somedest:1234/api/v2/spans" + config.WriteBufferSize = 524288 + config.Timeout = 5 * time.Second + config.TLSSetting = configtls.ClientConfig{ InsecureSkipVerify: true, - }, - MaxIdleConns: &maxIdleConns, - IdleConnTimeout: &idleConnTimeout, - }, + } + config.MaxIdleConns = &maxIdleConns + config.IdleConnTimeout = &idleConnTimeout + }), Format: "proto", DefaultServiceName: "test_name", }, @@ -87,3 +87,11 @@ func TestLoadConfig(t *testing.T) { }) } } + +func withDefaultHTTPClientConfig(fns ...func(config *confighttp.ClientConfig)) confighttp.ClientConfig { + cfg := confighttp.NewDefaultClientConfig() + for _, fn := range fns { + fn(&cfg) + } + return cfg +}