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 2a29793 commit 497bfd0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions modules/caddyhttp/reverseproxy/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ 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 &&
u.Host.Successes() >= u.healthCheckPolicy.MinSuccesses {
healthRatio := float64(u.Host.Successes()) / float64(u.Host.Fails())
healthy = healthRatio < float64(u.healthCheckPolicy.MinSuccessRatio)
}
if healthy && u.cb != nil {
healthy = u.cb.OK()
}
Expand Down

0 comments on commit 497bfd0

Please sign in to comment.