1
0
Fork 0

Add healthcheck interval

This commit is contained in:
Julien Salleyron 2017-02-06 22:59:50 +01:00 committed by Emile Vauge
parent 5e8805f24d
commit 6b6f010851
No known key found for this signature in database
GPG key ID: D808B4C167352E59
3 changed files with 24 additions and 6 deletions

View file

@ -26,6 +26,7 @@ func GetHealthCheck() *HealthCheck {
// BackendHealthCheck HealthCheck configuration for a backend // BackendHealthCheck HealthCheck configuration for a backend
type BackendHealthCheck struct { type BackendHealthCheck struct {
URL string URL string
Interval time.Duration
DisabledURLs []*url.URL DisabledURLs []*url.URL
lb loadBalancer lb loadBalancer
} }
@ -49,8 +50,8 @@ func newHealthCheck() *HealthCheck {
} }
// NewBackendHealthCheck Instantiate a new BackendHealthCheck // NewBackendHealthCheck Instantiate a new BackendHealthCheck
func NewBackendHealthCheck(URL string, lb loadBalancer) *BackendHealthCheck { func NewBackendHealthCheck(URL string, interval time.Duration, lb loadBalancer) *BackendHealthCheck {
return &BackendHealthCheck{URL, nil, lb} return &BackendHealthCheck{URL, interval, nil, lb}
} }
//SetBackendsConfiguration set backends configuration //SetBackendsConfiguration set backends configuration
@ -70,7 +71,7 @@ func (hc *HealthCheck) execute(ctx context.Context) {
currentBackendID := backendID currentBackendID := backendID
safe.Go(func() { safe.Go(func() {
for { for {
ticker := time.NewTicker(time.Second * 30) ticker := time.NewTicker(currentBackend.Interval)
select { select {
case <-ctx.Done(): case <-ctx.Done():
log.Debugf("Stopping all current Healthcheck goroutines") log.Debugf("Stopping all current Healthcheck goroutines")

View file

@ -658,7 +658,15 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo
continue frontend continue frontend
} }
if configuration.Backends[frontend.Backend].HealthCheck != nil { if configuration.Backends[frontend.Backend].HealthCheck != nil {
backendsHealthcheck[frontend.Backend] = healthcheck.NewBackendHealthCheck(configuration.Backends[frontend.Backend].HealthCheck.URL, rebalancer) var interval time.Duration
if configuration.Backends[frontend.Backend].HealthCheck.Interval != "" {
interval, err = time.ParseDuration(configuration.Backends[frontend.Backend].HealthCheck.Interval)
if err != nil {
log.Errorf("Wrong healthcheck interval: %s", err)
interval = time.Second * 30
}
}
backendsHealthcheck[frontend.Backend] = healthcheck.NewBackendHealthCheck(configuration.Backends[frontend.Backend].HealthCheck.URL, interval, rebalancer)
} }
} }
case types.Wrr: case types.Wrr:
@ -684,7 +692,15 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo
} }
} }
if configuration.Backends[frontend.Backend].HealthCheck != nil { if configuration.Backends[frontend.Backend].HealthCheck != nil {
backendsHealthcheck[frontend.Backend] = healthcheck.NewBackendHealthCheck(configuration.Backends[frontend.Backend].HealthCheck.URL, rr) var interval time.Duration
if configuration.Backends[frontend.Backend].HealthCheck.Interval != "" {
interval, err = time.ParseDuration(configuration.Backends[frontend.Backend].HealthCheck.Interval)
if err != nil {
log.Errorf("Wrong healthcheck interval: %s", err)
interval = time.Second * 30
}
}
backendsHealthcheck[frontend.Backend] = healthcheck.NewBackendHealthCheck(configuration.Backends[frontend.Backend].HealthCheck.URL, interval, rr)
} }
} }
maxConns := configuration.Backends[frontend.Backend].MaxConn maxConns := configuration.Backends[frontend.Backend].MaxConn

View file

@ -39,7 +39,8 @@ type CircuitBreaker struct {
// HealthCheck holds HealthCheck configuration // HealthCheck holds HealthCheck configuration
type HealthCheck struct { type HealthCheck struct {
URL string `json:"url,omitempty"` URL string `json:"url,omitempty"`
Interval string `json:"interval,omitempty"`
} }
// Server holds server configuration. // Server holds server configuration.