Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] [exporter/splunkhec] Use NewDefaultClientConfig instead of manually creating struct #35545

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_CreateMetricsExporter(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_CreateMetricsExporter(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