Skip to content

Commit

Permalink
[chore] [exporter/splunkhec] 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 a191550 commit 52c4b7b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
6 changes: 6 additions & 0 deletions exporter/splunkhecexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package splunkhecexporter

import (
"net/http"
"path/filepath"
"testing"
"time"
Expand All @@ -13,6 +14,7 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/config/configretry"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/confmap/confmaptest"
Expand All @@ -24,6 +26,8 @@ import (
)

func TestLoadConfig(t *testing.T) {
defaultMaxConnsPerHost := http.DefaultTransport.(*http.Transport).MaxConnsPerHost

t.Parallel()

cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
Expand Down Expand Up @@ -77,6 +81,8 @@ func TestLoadConfig(t *testing.T) {
IdleConnTimeout: &idleConnTimeout,
HTTP2ReadIdleTimeout: 10 * time.Second,
HTTP2PingTimeout: 10 * time.Second,
Headers: map[string]configopaque.String{},
MaxConnsPerHost: &defaultMaxConnsPerHost,
},
BackOffConfig: configretry.BackOffConfig{
Enabled: true,
Expand Down
22 changes: 12 additions & 10 deletions exporter/splunkhecexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,19 @@ func createDefaultConfig() component.Config {

defaultMaxConns := defaultMaxIdleCons
defaultIdleConnTimeout := defaultIdleConnTimeout

clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.Timeout = defaultHTTPTimeout
clientConfig.IdleConnTimeout = &defaultIdleConnTimeout
clientConfig.MaxIdleConnsPerHost = &defaultMaxConns
clientConfig.MaxIdleConns = &defaultMaxConns
clientConfig.HTTP2ReadIdleTimeout = defaultHTTP2ReadIdleTimeout
clientConfig.HTTP2PingTimeout = defaultHTTP2PingTimeout

return &Config{
LogDataEnabled: true,
ProfilingDataEnabled: true,
ClientConfig: confighttp.ClientConfig{
Timeout: defaultHTTPTimeout,
IdleConnTimeout: &defaultIdleConnTimeout,
MaxIdleConnsPerHost: &defaultMaxConns,
MaxIdleConns: &defaultMaxConns,
HTTP2ReadIdleTimeout: defaultHTTP2ReadIdleTimeout,
HTTP2PingTimeout: defaultHTTP2PingTimeout,
},
LogDataEnabled: true,
ProfilingDataEnabled: true,
ClientConfig: clientConfig,
SplunkAppName: defaultSplunkAppName,
BackOffConfig: configretry.NewDefaultBackOffConfig(),
QueueSettings: exporterhelper.NewDefaultQueueConfig(),
Expand Down

0 comments on commit 52c4b7b

Please sign in to comment.