Add passive health checks
This commit is contained in:
parent
c20802b07e
commit
fc0fac8543
20 changed files with 696 additions and 6 deletions
|
|
@ -341,7 +341,7 @@ func (m *Manager) getLoadBalancerServiceHandler(ctx context.Context, serviceName
|
|||
var lb serverBalancer
|
||||
switch service.Strategy {
|
||||
// Here we are handling the empty value to comply with providers that are not applying defaults (e.g. REST provider)
|
||||
// TODO: remove this when all providers apply default values.
|
||||
// TODO: remove this empty check when all providers apply default values.
|
||||
case dynamic.BalancerStrategyWRR, "":
|
||||
lb = wrr.New(service.Sticky, service.HealthCheck != nil)
|
||||
case dynamic.BalancerStrategyP2C:
|
||||
|
|
@ -350,6 +350,17 @@ func (m *Manager) getLoadBalancerServiceHandler(ctx context.Context, serviceName
|
|||
return nil, fmt.Errorf("unsupported load-balancer strategy %q", service.Strategy)
|
||||
}
|
||||
|
||||
var passiveHealthChecker *healthcheck.PassiveServiceHealthChecker
|
||||
if service.PassiveHealthCheck != nil {
|
||||
passiveHealthChecker = healthcheck.NewPassiveHealthChecker(
|
||||
serviceName,
|
||||
lb,
|
||||
service.PassiveHealthCheck.MaxFailedAttempts,
|
||||
service.PassiveHealthCheck.FailureWindow,
|
||||
service.HealthCheck != nil,
|
||||
m.observabilityMgr.MetricsRegistry())
|
||||
}
|
||||
|
||||
healthCheckTargets := make(map[string]*url.URL)
|
||||
|
||||
for i, server := range shuffle(service.Servers, m.rand) {
|
||||
|
|
@ -368,6 +379,11 @@ func (m *Manager) getLoadBalancerServiceHandler(ctx context.Context, serviceName
|
|||
return nil, fmt.Errorf("error building proxy for server URL %s: %w", server.URL, err)
|
||||
}
|
||||
|
||||
if passiveHealthChecker != nil {
|
||||
// If passive health check is enabled, we wrap the proxy with the passive health checker.
|
||||
proxy = passiveHealthChecker.WrapHandler(ctx, proxy, target.String())
|
||||
}
|
||||
|
||||
// The retry wrapping must be done just before the proxy handler,
|
||||
// to make sure that the retry will not be triggered/disabled by
|
||||
// middlewares in the chain.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue