diff --git a/modules/caddyhttp/reverseproxy/caddyfile.go b/modules/caddyhttp/reverseproxy/caddyfile.go index 4f27ca1e..c12fb2ec 100644 --- a/modules/caddyhttp/reverseproxy/caddyfile.go +++ b/modules/caddyhttp/reverseproxy/caddyfile.go @@ -78,6 +78,7 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) // fail_duration // max_fails // success_duration +// min_success_ratio // unhealthy_status // unhealthy_latency // unhealthy_request_count @@ -439,6 +440,22 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { } h.HealthChecks.Passive.SuccessDuration = caddy.Duration(dur) + case "min_success_ratio": + if !d.NextArg() { + return d.ArgErr() + } + if h.HealthChecks == nil { + h.HealthChecks = new(HealthChecks) + } + if h.HealthChecks.Passive == nil { + h.HealthChecks.Passive = new(PassiveHealthChecks) + } + ratio, err := caddyhttp.ParseRatio(d.Val()) + if err != nil { + return d.Errf("bad ratio value '%s': %v", d.Val(), err) + } + h.HealthChecks.Passive.MinSuccessRatio = ratio + case "fail_duration": if !d.NextArg() { return d.ArgErr() diff --git a/modules/caddyhttp/reverseproxy/healthchecks.go b/modules/caddyhttp/reverseproxy/healthchecks.go index 1362afa8..20ba0b9b 100644 --- a/modules/caddyhttp/reverseproxy/healthchecks.go +++ b/modules/caddyhttp/reverseproxy/healthchecks.go @@ -122,6 +122,11 @@ type PassiveHealthChecks struct { // How long to remember a successful request to a backend. Default is 0. SuccessDuration caddy.Duration `json:"success_duration,omitempty"` + // The minimum ratio of successful to failed requests necessary to + // consider a backend as healthy. Both fail and success durations + // must be configured for those stats to be counted. Default is 0 (no ratio). + MinSuccessRatio caddyhttp.Ratio `json:"min_success_ratio,omitempty"` + // Limits the number of simultaneous requests to a backend by // marking the backend as "down" if it has this many concurrent // requests or more.