Add health check timeout parameter
This commit is contained in:
parent
f10516deb7
commit
5acd43efaf
45 changed files with 189 additions and 28 deletions
|
@ -90,7 +90,10 @@ func TestServerLoadConfigHealthCheckOptions(t *testing.T) {
|
|||
for _, healthCheck := range healthChecks {
|
||||
t.Run(fmt.Sprintf("%s/hc=%t", lbMethod, healthCheck != nil), func(t *testing.T) {
|
||||
globalConfig := configuration.GlobalConfiguration{
|
||||
HealthCheck: &configuration.HealthCheckConfig{Interval: parse.Duration(5 * time.Second)},
|
||||
HealthCheck: &configuration.HealthCheckConfig{
|
||||
Interval: parse.Duration(5 * time.Second),
|
||||
Timeout: parse.Duration(3 * time.Second),
|
||||
},
|
||||
}
|
||||
entryPoints := map[string]EntryPoint{
|
||||
"http": {
|
||||
|
@ -424,6 +427,7 @@ func TestServerMultipleFrontendRules(t *testing.T) {
|
|||
func TestServerBuildHealthCheckOptions(t *testing.T) {
|
||||
lb := &testLoadBalancer{}
|
||||
globalInterval := 15 * time.Second
|
||||
globalTimeout := 3 * time.Second
|
||||
|
||||
testCases := []struct {
|
||||
desc string
|
||||
|
@ -452,6 +456,7 @@ func TestServerBuildHealthCheckOptions(t *testing.T) {
|
|||
Path: "/path",
|
||||
Interval: globalInterval,
|
||||
LB: lb,
|
||||
Timeout: 3 * time.Second,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -464,6 +469,7 @@ func TestServerBuildHealthCheckOptions(t *testing.T) {
|
|||
Path: "/path",
|
||||
Interval: globalInterval,
|
||||
LB: lb,
|
||||
Timeout: 3 * time.Second,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -476,6 +482,49 @@ func TestServerBuildHealthCheckOptions(t *testing.T) {
|
|||
Path: "/path",
|
||||
Interval: 5 * time.Minute,
|
||||
LB: lb,
|
||||
Timeout: 3 * time.Second,
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "unparseable timeout",
|
||||
hc: &types.HealthCheck{
|
||||
Path: "/path",
|
||||
Interval: "15s",
|
||||
Timeout: "unparseable",
|
||||
},
|
||||
expectedOpts: &healthcheck.Options{
|
||||
Path: "/path",
|
||||
Interval: globalInterval,
|
||||
Timeout: globalTimeout,
|
||||
LB: lb,
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "sub-zero timeout",
|
||||
hc: &types.HealthCheck{
|
||||
Path: "/path",
|
||||
Interval: "15s",
|
||||
Timeout: "-42s",
|
||||
},
|
||||
expectedOpts: &healthcheck.Options{
|
||||
Path: "/path",
|
||||
Interval: globalInterval,
|
||||
Timeout: globalTimeout,
|
||||
LB: lb,
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "parseable timeout",
|
||||
hc: &types.HealthCheck{
|
||||
Path: "/path",
|
||||
Interval: "15s",
|
||||
Timeout: "10s",
|
||||
},
|
||||
expectedOpts: &healthcheck.Options{
|
||||
Path: "/path",
|
||||
Interval: globalInterval,
|
||||
Timeout: 10 * time.Second,
|
||||
LB: lb,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -485,7 +534,10 @@ func TestServerBuildHealthCheckOptions(t *testing.T) {
|
|||
t.Run(test.desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
opts := buildHealthCheckOptions(lb, "backend", test.hc, &configuration.HealthCheckConfig{Interval: parse.Duration(globalInterval)})
|
||||
opts := buildHealthCheckOptions(lb, "backend", test.hc, &configuration.HealthCheckConfig{
|
||||
Interval: parse.Duration(globalInterval),
|
||||
Timeout: parse.Duration(globalTimeout),
|
||||
})
|
||||
assert.Equal(t, test.expectedOpts, opts, "health check options")
|
||||
})
|
||||
}
|
||||
|
|
|
@ -409,11 +409,28 @@ func buildHealthCheckOptions(lb healthcheck.BalancerHandler, backend string, hc
|
|||
}
|
||||
}
|
||||
|
||||
timeout := time.Duration(hcConfig.Timeout)
|
||||
if hc.Timeout != "" {
|
||||
timeoutOverride, err := time.ParseDuration(hc.Timeout)
|
||||
if err != nil {
|
||||
log.Errorf("Illegal health check timeout for backend '%s': %s", backend, err)
|
||||
} else if timeoutOverride <= 0 {
|
||||
log.Errorf("Health check timeout smaller than zero for backend '%s', backend", backend)
|
||||
} else {
|
||||
timeout = timeoutOverride
|
||||
}
|
||||
}
|
||||
|
||||
if timeout >= interval {
|
||||
log.Warnf("Health check timeout for backend '%s' should be lower than the health check interval. Interval set to timeout + 1 second (%s).", backend)
|
||||
}
|
||||
|
||||
return &healthcheck.Options{
|
||||
Scheme: hc.Scheme,
|
||||
Path: hc.Path,
|
||||
Port: hc.Port,
|
||||
Interval: interval,
|
||||
Timeout: timeout,
|
||||
LB: lb,
|
||||
Hostname: hc.Hostname,
|
||||
Headers: hc.Headers,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue