From 02b127f896cac697e9f5d3c3eb281c81093f4f56 Mon Sep 17 00:00:00 2001 From: mackjmr Date: Wed, 2 Oct 2024 14:40:41 +0200 Subject: [PATCH] [chore] [exporter/sumologic] Use NewDefaultClientConfig instead of manually creating struct **Description:** This PR makes usage of `NewDefaultClientConfig` instead of manually creating the confighttp.ClientConfig struct. **Link to tracking Issue:** #35457 --- exporter/sumologicexporter/config.go | 12 ++++++------ exporter/sumologicexporter/factory_test.go | 11 +++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/exporter/sumologicexporter/config.go b/exporter/sumologicexporter/config.go index dab1dc21bb5c..e4d88dd4b35d 100644 --- a/exporter/sumologicexporter/config.go +++ b/exporter/sumologicexporter/config.go @@ -63,13 +63,13 @@ type Config struct { // createDefaultClientConfig returns default http client settings func createDefaultClientConfig() confighttp.ClientConfig { - return confighttp.ClientConfig{ - Timeout: defaultTimeout, - Compression: DefaultCompressEncoding, - Auth: &configauth.Authentication{ - AuthenticatorID: component.NewID(sumologicextension.NewFactory().Type()), - }, + clientConfig := confighttp.NewDefaultClientConfig() + clientConfig.Timeout = defaultTimeout + clientConfig.Compression = DefaultCompressEncoding + clientConfig.Auth = &configauth.Authentication{ + AuthenticatorID: component.NewID(sumologicextension.NewFactory().Type()), } + return clientConfig } func (cfg *Config) Validate() error { diff --git a/exporter/sumologicexporter/factory_test.go b/exporter/sumologicexporter/factory_test.go index c4071e4612a4..677b834a11cd 100644 --- a/exporter/sumologicexporter/factory_test.go +++ b/exporter/sumologicexporter/factory_test.go @@ -4,6 +4,7 @@ package sumologicexporter import ( + "net/http" "testing" "time" @@ -11,6 +12,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/configauth" "go.opentelemetry.io/collector/config/confighttp" + "go.opentelemetry.io/collector/config/configopaque" "go.opentelemetry.io/collector/config/configretry" "go.opentelemetry.io/collector/exporter/exporterhelper" @@ -28,6 +30,10 @@ func TestCreateDefaultConfig(t *testing.T) { cfg := factory.CreateDefaultConfig() qs := exporterhelper.NewDefaultQueueConfig() qs.Enabled = false + defaultMaxIdleConns := http.DefaultTransport.(*http.Transport).MaxIdleConns + defaultMaxIdleConnsPerHost := http.DefaultTransport.(*http.Transport).MaxIdleConnsPerHost + defaultMaxConnsPerHost := http.DefaultTransport.(*http.Transport).MaxConnsPerHost + defaultIdleConnTimeout := http.DefaultTransport.(*http.Transport).IdleConnTimeout assert.Equal(t, &Config{ MaxRequestBodySize: 1_048_576, @@ -41,6 +47,11 @@ func TestCreateDefaultConfig(t *testing.T) { Auth: &configauth.Authentication{ AuthenticatorID: component.NewID(metadata.Type), }, + Headers: map[string]configopaque.String{}, + MaxIdleConns: &defaultMaxIdleConns, + MaxIdleConnsPerHost: &defaultMaxIdleConnsPerHost, + MaxConnsPerHost: &defaultMaxConnsPerHost, + IdleConnTimeout: &defaultIdleConnTimeout, }, BackOffConfig: configretry.NewDefaultBackOffConfig(), QueueSettings: qs,