Skip to content

Commit

Permalink
[chore] [exporter/signalfx] Use NewDefaultClientConfig instead of man…
Browse files Browse the repository at this point in the history
…ually creating struct (#35543)

**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 2, 2024
1 parent 494cbd8 commit 52f731e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
27 changes: 22 additions & 5 deletions exporter/signalfxexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package signalfxexporter

import (
"net/http"
"net/url"
"path/filepath"
"testing"
Expand Down Expand Up @@ -38,6 +39,10 @@ func TestLoadConfig(t *testing.T) {
seventy := 70
hundred := 100
idleConnTimeout := 30 * time.Second
defaultMaxIdleConns := http.DefaultTransport.(*http.Transport).MaxIdleConns
defaultMaxIdleConnsPerHost := http.DefaultTransport.(*http.Transport).MaxIdleConnsPerHost
defaultMaxConnsPerHost := http.DefaultTransport.(*http.Transport).MaxConnsPerHost
defaultIdleConnTimeout := http.DefaultTransport.(*http.Transport).IdleConnTimeout

tests := []struct {
id component.ID
Expand All @@ -50,9 +55,10 @@ func TestLoadConfig(t *testing.T) {
Realm: "ap0",
ClientConfig: confighttp.ClientConfig{
Timeout: 10 * time.Second,
Headers: nil,
Headers: map[string]configopaque.String{},
MaxIdleConns: &hundred,
MaxIdleConnsPerHost: &hundred,
MaxConnsPerHost: &defaultMaxConnsPerHost,
IdleConnTimeout: &idleConnTimeout,
HTTP2ReadIdleTimeout: 10 * time.Second,
HTTP2PingTimeout: 10 * time.Second,
Expand Down Expand Up @@ -86,8 +92,13 @@ func TestLoadConfig(t *testing.T) {
ExcludeProperties: nil,
Correlation: &correlation.Config{
ClientConfig: confighttp.ClientConfig{
Endpoint: "",
Timeout: 5 * time.Second,
Endpoint: "",
Timeout: 5 * time.Second,
Headers: map[string]configopaque.String{},
MaxIdleConns: &defaultMaxIdleConns,
MaxIdleConnsPerHost: &defaultMaxIdleConnsPerHost,
MaxConnsPerHost: &defaultMaxConnsPerHost,
IdleConnTimeout: &defaultIdleConnTimeout,
},
StaleServiceTimeout: 5 * time.Minute,
SyncAttributes: map[string]string{
Expand Down Expand Up @@ -120,6 +131,7 @@ func TestLoadConfig(t *testing.T) {
},
MaxIdleConns: &seventy,
MaxIdleConnsPerHost: &seventy,
MaxConnsPerHost: &defaultMaxConnsPerHost,
IdleConnTimeout: &idleConnTimeout,
HTTP2ReadIdleTimeout: 10 * time.Second,
HTTP2PingTimeout: 10 * time.Second,
Expand Down Expand Up @@ -246,8 +258,13 @@ func TestLoadConfig(t *testing.T) {
},
Correlation: &correlation.Config{
ClientConfig: confighttp.ClientConfig{
Endpoint: "",
Timeout: 5 * time.Second,
Endpoint: "",
Timeout: 5 * time.Second,
Headers: map[string]configopaque.String{},
MaxIdleConns: &defaultMaxIdleConns,
MaxIdleConnsPerHost: &defaultMaxIdleConnsPerHost,
MaxConnsPerHost: &defaultMaxConnsPerHost,
IdleConnTimeout: &defaultIdleConnTimeout,
},
StaleServiceTimeout: 5 * time.Minute,
SyncAttributes: map[string]string{
Expand Down
16 changes: 8 additions & 8 deletions exporter/signalfxexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ func createDefaultConfig() component.Config {
maxConnCount := defaultMaxConns
idleConnTimeout := 30 * time.Second
timeout := 10 * time.Second
clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.Timeout = defaultHTTPTimeout
clientConfig.MaxIdleConns = &maxConnCount
clientConfig.MaxIdleConnsPerHost = &maxConnCount
clientConfig.IdleConnTimeout = &idleConnTimeout
clientConfig.HTTP2ReadIdleTimeout = defaultHTTP2ReadIdleTimeout
clientConfig.HTTP2PingTimeout = defaultHTTP2PingTimeout

return &Config{
BackOffConfig: configretry.NewDefaultBackOffConfig(),
QueueSettings: exporterhelper.NewDefaultQueueConfig(),
ClientConfig: confighttp.ClientConfig{
Timeout: defaultHTTPTimeout,
MaxIdleConns: &maxConnCount,
MaxIdleConnsPerHost: &maxConnCount,
IdleConnTimeout: &idleConnTimeout,
HTTP2ReadIdleTimeout: defaultHTTP2ReadIdleTimeout,
HTTP2PingTimeout: defaultHTTP2PingTimeout,
},
ClientConfig: clientConfig,
AccessTokenPassthroughConfig: splunk.AccessTokenPassthroughConfig{
AccessTokenPassthrough: true,
},
Expand Down
4 changes: 3 additions & 1 deletion exporter/signalfxexporter/internal/correlation/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import (

// DefaultConfig returns default configuration correlation values.
func DefaultConfig() *Config {
clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.Timeout = 5 * time.Second
return &Config{
ClientConfig: confighttp.ClientConfig{Timeout: 5 * time.Second},
ClientConfig: clientConfig,
StaleServiceTimeout: 5 * time.Minute,
SyncAttributes: map[string]string{
conventions.AttributeK8SPodUID: conventions.AttributeK8SPodUID,
Expand Down

0 comments on commit 52f731e

Please sign in to comment.