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

Add min_successes

This commit is contained in:
Francis Lavoie 2023-04-15 08:44:12 -04:00
parent c8b8c3a7b2
commit 2c61b50b5f
No known key found for this signature in database
GPG key ID: 0F66EE1687682239
3 changed files with 29 additions and 0 deletions

View file

@ -79,6 +79,7 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error)
// max_fails <num>
// success_duration <duration>
// min_success_ratio <ratio>
// min_success <num>
// unhealthy_status <status>
// unhealthy_latency <duration>
// unhealthy_request_count <num>
@ -456,6 +457,22 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
}
h.HealthChecks.Passive.MinSuccessRatio = ratio
case "min_successes":
if !d.NextArg() {
return d.ArgErr()
}
if h.HealthChecks == nil {
h.HealthChecks = new(HealthChecks)
}
if h.HealthChecks.Passive == nil {
h.HealthChecks.Passive = new(PassiveHealthChecks)
}
count, err := strconv.Atoi(d.Val())
if err != nil {
return d.Errf("invalid minimum success count '%s': %v", d.Val(), err)
}
h.HealthChecks.Passive.MinSuccesses = count
case "fail_duration":
if !d.NextArg() {
return d.ArgErr()

View file

@ -127,6 +127,14 @@ type PassiveHealthChecks struct {
// must be configured for those stats to be counted. Default is 0 (no ratio).
MinSuccessRatio caddyhttp.Ratio `json:"min_success_ratio,omitempty"`
// The minimum number of successful requests before considering the
// minimum success ratio. Default is 5. Requires MinSuccessRatio >= 0.
//
// If there are less than this many successful requests, then the ratio is
// ignored, because of a lack of data. This ensures that the upstream isn't
// prematurely considered unhealthy because no requests have happened yet.
MinSuccesses int `json:"min_successes,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.

View file

@ -352,6 +352,10 @@ func (h *Handler) Provision(ctx caddy.Context) error {
if h.HealthChecks.Passive.FailDuration > 0 && h.HealthChecks.Passive.MaxFails == 0 {
h.HealthChecks.Passive.MaxFails = 1
}
if h.HealthChecks.Passive.MinSuccessRatio > 0 && h.HealthChecks.Passive.MinSuccesses == 0 {
h.HealthChecks.Passive.MinSuccesses = 5
}
}
// if active health checks are enabled, configure them and start a worker