Skip to content

Commit

Permalink
[chore] [exporter/sumologic] Use NewDefaultClientConfig instead of ma…
Browse files Browse the repository at this point in the history
…nually creating struct

**Description:**
This PR makes usage of `NewDefaultClientConfig` instead of manually creating the confighttp.ClientConfig struct.

**Link to tracking Issue:** open-telemetry#35457
  • Loading branch information
mackjmr committed Oct 2, 2024
1 parent 947d1b5 commit 02b127f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
12 changes: 6 additions & 6 deletions exporter/sumologicexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions exporter/sumologicexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
package sumologicexporter

import (
"net/http"
"testing"
"time"

"github.com/stretchr/testify/assert"
"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"

Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 02b127f

Please sign in to comment.