Skip to content

Commit 31cfebc

Browse files
committed
Implement success ratio in health checks
1 parent 3e51e6f commit 31cfebc

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

modules/caddyhttp/reverseproxy/hosts.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ func (u *Upstream) Healthy() bool {
8484
if healthy && u.healthCheckPolicy != nil {
8585
healthy = u.Host.Fails() < u.healthCheckPolicy.MaxFails
8686
}
87+
if healthy && u.healthCheckPolicy != nil &&
88+
u.healthCheckPolicy.MinSuccessRatio > 0 {
89+
successes := u.Host.Successes()
90+
if successes >= u.healthCheckPolicy.MinSuccesses {
91+
fails := u.Host.Fails()
92+
healthRatio := float64(fails) / float64(successes)
93+
healthy = healthRatio < (1 - float64(u.healthCheckPolicy.MinSuccessRatio))
94+
}
95+
}
8796
if healthy && u.cb != nil {
8897
healthy = u.cb.OK()
8998
}

0 commit comments

Comments
 (0)