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 (#35545)

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

**Link to tracking Issue:** #35457
  • Loading branch information
mackjmr authored Oct 30, 2024
1 parent 5f3ff6c commit c40c6a6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 35 deletions.
35 changes: 18 additions & 17 deletions exporter/splunkhecexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ func TestLoadConfig(t *testing.T) {
hundred := 100
idleConnTimeout := 10 * time.Second

clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.Timeout = 10 * time.Second
clientConfig.Endpoint = "https://splunk:8088/services/collector"
clientConfig.TLSSetting = configtls.ClientConfig{
Config: configtls.Config{
CAFile: "",
CertFile: "",
KeyFile: "",
},
InsecureSkipVerify: false,
}
clientConfig.HTTP2PingTimeout = 10 * time.Second
clientConfig.HTTP2ReadIdleTimeout = 10 * time.Second
clientConfig.MaxIdleConns = &hundred
clientConfig.MaxIdleConnsPerHost = &hundred
clientConfig.IdleConnTimeout = &idleConnTimeout

tests := []struct {
id component.ID
expected component.Config
Expand All @@ -61,23 +78,7 @@ func TestLoadConfig(t *testing.T) {
MaxContentLengthLogs: 2 * 1024 * 1024,
MaxContentLengthMetrics: 2 * 1024 * 1024,
MaxContentLengthTraces: 2 * 1024 * 1024,
ClientConfig: confighttp.ClientConfig{
Timeout: 10 * time.Second,
Endpoint: "https://splunk:8088/services/collector",
TLSSetting: configtls.ClientConfig{
Config: configtls.Config{
CAFile: "",
CertFile: "",
KeyFile: "",
},
InsecureSkipVerify: false,
},
MaxIdleConns: &hundred,
MaxIdleConnsPerHost: &hundred,
IdleConnTimeout: &idleConnTimeout,
HTTP2ReadIdleTimeout: 10 * time.Second,
HTTP2PingTimeout: 10 * time.Second,
},
ClientConfig: clientConfig,
BackOffConfig: configretry.BackOffConfig{
Enabled: true,
InitialInterval: 10 * time.Second,
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
17 changes: 9 additions & 8 deletions exporter/splunkhecexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ func TestCreateInstanceViaFactory(t *testing.T) {
}

func TestFactory_CreateMetrics(t *testing.T) {
clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.Endpoint = "https://example.com:8000"
config := &Config{
Token: "testToken",
ClientConfig: confighttp.ClientConfig{
Endpoint: "https://example.com:8000",
},
Token: "testToken",
ClientConfig: clientConfig,
}

params := exportertest.NewNopSettings()
Expand All @@ -91,11 +91,12 @@ func TestFactory_CreateMetrics(t *testing.T) {
}

func TestFactory_EnabledBatchingMakesExporterMutable(t *testing.T) {
clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.Endpoint = "https://example.com:8000"

config := &Config{
Token: "testToken",
ClientConfig: confighttp.ClientConfig{
Endpoint: "https://example.com:8000",
},
Token: "testToken",
ClientConfig: clientConfig,
}

me, err := createMetricsExporter(context.Background(), exportertest.NewNopSettings(), config)
Expand Down

0 comments on commit c40c6a6

Please sign in to comment.