Fix deprecated IdleTimeout config

This commit is contained in:
Marco Jantke 2017-09-20 18:14:03 +02:00 committed by Traefiker
parent f9225c54ff
commit 52c1909f24
3 changed files with 42 additions and 32 deletions

View file

@ -159,6 +159,21 @@ func NewTraefikDefaultPointersConfiguration() *TraefikConfiguration {
FilePath: "", FilePath: "",
} }
// default HealthCheckConfig
healthCheck := configuration.HealthCheckConfig{
Interval: flaeg.Duration(configuration.DefaultHealthCheckInterval),
}
// default RespondingTimeouts
respondingTimeouts := configuration.RespondingTimeouts{
IdleTimeout: flaeg.Duration(configuration.DefaultIdleTimeout),
}
// default ForwardingTimeouts
forwardingTimeouts := configuration.ForwardingTimeouts{
DialTimeout: flaeg.Duration(configuration.DefaultDialTimeout),
}
defaultConfiguration := configuration.GlobalConfiguration{ defaultConfiguration := configuration.GlobalConfiguration{
Docker: &defaultDocker, Docker: &defaultDocker,
File: &defaultFile, File: &defaultFile,
@ -176,8 +191,10 @@ func NewTraefikDefaultPointersConfiguration() *TraefikConfiguration {
Eureka: &defaultEureka, Eureka: &defaultEureka,
DynamoDB: &defaultDynamoDB, DynamoDB: &defaultDynamoDB,
Retry: &configuration.Retry{}, Retry: &configuration.Retry{},
HealthCheck: &configuration.HealthCheckConfig{}, HealthCheck: &healthCheck,
AccessLog: &defaultAccessLog, AccessLog: &defaultAccessLog,
RespondingTimeouts: &respondingTimeouts,
ForwardingTimeouts: &forwardingTimeouts,
} }
return &TraefikConfiguration{ return &TraefikConfiguration{
@ -202,12 +219,6 @@ func NewTraefikConfiguration() *TraefikConfiguration {
HealthCheck: &configuration.HealthCheckConfig{ HealthCheck: &configuration.HealthCheckConfig{
Interval: flaeg.Duration(configuration.DefaultHealthCheckInterval), Interval: flaeg.Duration(configuration.DefaultHealthCheckInterval),
}, },
RespondingTimeouts: &configuration.RespondingTimeouts{
IdleTimeout: flaeg.Duration(configuration.DefaultIdleTimeout),
},
ForwardingTimeouts: &configuration.ForwardingTimeouts{
DialTimeout: flaeg.Duration(configuration.DefaultDialTimeout),
},
CheckNewVersion: true, CheckNewVersion: true,
}, },
ConfigFile: "", ConfigFile: "",

View file

@ -127,7 +127,7 @@ func NewServer(globalConfiguration configuration.GlobalConfiguration) *Server {
// behaviour and backwards compatibility issues. // behaviour and backwards compatibility issues.
func createHTTPTransport(globalConfiguration configuration.GlobalConfiguration) *http.Transport { func createHTTPTransport(globalConfiguration configuration.GlobalConfiguration) *http.Transport {
dialer := &net.Dialer{ dialer := &net.Dialer{
Timeout: 30 * time.Second, Timeout: configuration.DefaultDialTimeout,
KeepAlive: 30 * time.Second, KeepAlive: 30 * time.Second,
DualStack: true, DualStack: true,
} }
@ -675,14 +675,13 @@ func buildServerTimeouts(globalConfig configuration.GlobalConfiguration) (readTi
writeTimeout = time.Duration(globalConfig.RespondingTimeouts.WriteTimeout) writeTimeout = time.Duration(globalConfig.RespondingTimeouts.WriteTimeout)
} }
// When RespondingTimeouts.IdleTimout is configured, always use that setting // Prefer legacy idle timeout parameter for backwards compatibility reasons
if globalConfig.RespondingTimeouts != nil { if globalConfig.IdleTimeout > 0 {
idleTimeout = time.Duration(globalConfig.RespondingTimeouts.IdleTimeout)
} else if globalConfig.IdleTimeout != 0 {
// Backwards compatibility for deprecated IdleTimeout
idleTimeout = time.Duration(globalConfig.IdleTimeout) idleTimeout = time.Duration(globalConfig.IdleTimeout)
log.Warn("top-level idle timeout configuration has been deprecated -- please use responding timeouts")
} else if globalConfig.RespondingTimeouts != nil {
idleTimeout = time.Duration(globalConfig.RespondingTimeouts.IdleTimeout)
} else { } else {
// Default value if neither the deprecated IdleTimeout nor the new RespondingTimeouts.IdleTimout are configured
idleTimeout = time.Duration(configuration.DefaultIdleTimeout) idleTimeout = time.Duration(configuration.DefaultIdleTimeout)
} }

View file

@ -83,7 +83,7 @@ func TestPrepareServerTimeouts(t *testing.T) {
IdleTimeout: flaeg.Duration(80 * time.Second), IdleTimeout: flaeg.Duration(80 * time.Second),
}, },
}, },
wantIdleTimeout: time.Duration(80 * time.Second), wantIdleTimeout: time.Duration(45 * time.Second),
wantReadTimeout: time.Duration(0 * time.Second), wantReadTimeout: time.Duration(0 * time.Second),
wantWriteTimeout: time.Duration(0 * time.Second), wantWriteTimeout: time.Duration(0 * time.Second),
}, },