Skip to content

Commit

Permalink
Make all new parameter type to pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
rrupapara committed Nov 12, 2021
1 parent 88716b1 commit 4d19847
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
19 changes: 13 additions & 6 deletions config/confighttp/confighttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,20 @@ type HTTPClientSettings struct {
Auth *configauth.Authentication `mapstructure:"auth,omitempty"`

// MaxIdleConns is used to set a limit to the maximum idle HTTP connections the client can keep open.
// Here pointer is used to differentiate `no input` from `zero value input`
// There's an already set value, and we want to override it only if an explicit value provided
MaxIdleConns *int `mapstructure:"max_idle_conns"`

// MaxIdleConnsPerHost is used to set a limit to the maximum idle HTTP connections the host can keep open.
MaxIdleConnsPerHost int `mapstructure:"max_idle_conns_per_host"`
// There's an already set value, and we want to override it only if an explicit value provided
MaxIdleConnsPerHost *int `mapstructure:"max_idle_conns_per_host"`

// MaxConnsPerHost limits the total number of connections per host, including connections in the dialing,
// active, and idle states.
MaxConnsPerHost int `mapstructure:"max_conns_per_host"`
// There's an already set value, and we want to override it only if an explicit value provided
MaxConnsPerHost *int `mapstructure:"max_conns_per_host"`

// IdleConnTimeout is the maximum amount of time a connection will remain open before closing itself.
// Here pointer is used to differentiate `no input` from `zero value input`
// There's an already set value, and we want to override it only if an explicit value provided
IdleConnTimeout *time.Duration `mapstructure:"idle_conn_timeout"`
}

Expand All @@ -96,8 +98,13 @@ func (hcs *HTTPClientSettings) ToClient(ext map[config.ComponentID]component.Ext
transport.MaxIdleConns = *hcs.MaxIdleConns
}

transport.MaxIdleConnsPerHost = hcs.MaxIdleConnsPerHost
transport.MaxConnsPerHost = hcs.MaxConnsPerHost
if hcs.MaxIdleConnsPerHost != nil {
transport.MaxIdleConnsPerHost = *hcs.MaxIdleConnsPerHost
}

if hcs.MaxConnsPerHost != nil {
transport.MaxConnsPerHost = *hcs.MaxConnsPerHost
}

if hcs.IdleConnTimeout != nil {
transport.IdleConnTimeout = *hcs.IdleConnTimeout
Expand Down
6 changes: 4 additions & 2 deletions config/confighttp/confighttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ func TestAllHTTPClientSettings(t *testing.T) {
config.NewComponentID("testauth"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}},
}
maxIdleConns := 50
maxIdleConnsPerHost := 40
maxConnsPerHost := 45
idleConnTimeout := 30 * time.Second
tests := []struct {
name string
Expand All @@ -65,8 +67,8 @@ func TestAllHTTPClientSettings(t *testing.T) {
ReadBufferSize: 1024,
WriteBufferSize: 512,
MaxIdleConns: &maxIdleConns,
MaxIdleConnsPerHost: 40,
MaxConnsPerHost: 45,
MaxIdleConnsPerHost: &maxIdleConnsPerHost,
MaxConnsPerHost: &maxConnsPerHost,
IdleConnTimeout: &idleConnTimeout,
CustomRoundTripper: func(next http.RoundTripper) (http.RoundTripper, error) { return next, nil },
},
Expand Down

0 comments on commit 4d19847

Please sign in to comment.