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/signalfx] Use NewDefaultClientConfig instead of manually creating struct #35543

Merged
Merged
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
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