1
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-16 21:56:40 -05:00

Implement success ratio in health checks

This commit is contained in:
Francis Lavoie 2023-04-15 09:06:41 -04:00
parent 2c61b50b5f
commit 6d010189a5
No known key found for this signature in database
GPG key ID: 0F66EE1687682239

View file

@ -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()
}