Skip to content

Commit

Permalink
Implement success ratio in health checks
Browse files Browse the repository at this point in the history
  • Loading branch information
francislavoie committed Apr 15, 2023
1 parent 2c61b50 commit 6d01018
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions modules/caddyhttp/reverseproxy/hosts.go
Expand Up @@ -84,6 +84,15 @@ func (u *Upstream) Healthy() bool {
if healthy && u.healthCheckPolicy != nil {
healthy = u.Host.Fails() < u.healthCheckPolicy.MaxFails
}
if healthy && u.healthCheckPolicy != nil &&
u.healthCheckPolicy.MinSuccessRatio > 0 {
successes := u.Host.Successes()
if successes >= u.healthCheckPolicy.MinSuccesses {
fails := u.Host.Fails()
healthRatio := float64(fails) / float64(successes)
healthy = healthRatio < (1 - float64(u.healthCheckPolicy.MinSuccessRatio))
}
}
if healthy && u.cb != nil {
healthy = u.cb.OK()
}
Expand Down

0 comments on commit 6d01018

Please sign in to comment.