mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-25 13:13:47 +03:00
Implement success ratio in health checks
This commit is contained in:
parent
2c61b50b5f
commit
6d010189a5
1 changed files with 9 additions and 0 deletions
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue