1
0
Fork 0

Add health check timeout parameter

This commit is contained in:
Jared Biel 2018-09-27 13:16:03 -05:00 committed by Traefiker Bot
parent f10516deb7
commit 5acd43efaf
45 changed files with 189 additions and 28 deletions

View file

@ -42,11 +42,12 @@ type Options struct {
Port int
Transport http.RoundTripper
Interval time.Duration
Timeout time.Duration
LB BalancerHandler
}
func (opt Options) String() string {
return fmt.Sprintf("[Hostname: %s Headers: %v Path: %s Port: %d Interval: %s]", opt.Hostname, opt.Headers, opt.Path, opt.Port, opt.Interval)
return fmt.Sprintf("[Hostname: %s Headers: %v Path: %s Port: %d Interval: %s Timeout: %s]", opt.Hostname, opt.Headers, opt.Path, opt.Port, opt.Interval, opt.Timeout)
}
// BackendConfig HealthCheck configuration for a backend
@ -180,9 +181,8 @@ func newHealthCheck(metrics metricsRegistry) *HealthCheck {
// NewBackendConfig Instantiate a new BackendConfig
func NewBackendConfig(options Options, backendName string) *BackendConfig {
return &BackendConfig{
Options: options,
name: backendName,
requestTimeout: 5 * time.Second,
Options: options,
name: backendName,
}
}
@ -197,7 +197,7 @@ func checkHealth(serverURL *url.URL, backend *BackendConfig) error {
req = backend.addHeadersAndHost(req)
client := http.Client{
Timeout: backend.requestTimeout,
Timeout: backend.Options.Timeout,
Transport: backend.Options.Transport,
}

View file

@ -15,7 +15,8 @@ import (
"github.com/vulcand/oxy/roundrobin"
)
const healthCheckInterval = 100 * time.Millisecond
const healthCheckInterval = 200 * time.Millisecond
const healthCheckTimeout = 100 * time.Millisecond
type testHandler struct {
done func()
@ -105,6 +106,7 @@ func TestSetBackendsConfiguration(t *testing.T) {
backend := NewBackendConfig(Options{
Path: "/path",
Interval: healthCheckInterval,
Timeout: healthCheckTimeout,
LB: lb,
}, "backendName")