From 8e756c064d380c6c09b93851ff82abfed3dcb1ca Mon Sep 17 00:00:00 2001 From: Lukasz Raczylo Date: Thu, 26 Nov 2026 04:15:29 +0000 Subject: [PATCH] docs(shared-state): state what the discovery threshold counts With sharedState on, breaker.failureThreshold counts failed refreshes across all route instances and replicas. It no longer counts three in a row on one instance. The README and the wiring comment now say so. --- README.md | 3 ++- shared_state_wire.go | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ee606eb..66e0b3a 100644 --- a/README.md +++ b/README.md @@ -740,6 +740,7 @@ How it works: - A breaker counts consecutive failures across all replicas. A success on any replica resets the count and closes an open breaker. The replica whose flush takes the count from below the threshold to the threshold or above opens the breaker for all replicas. Open times and thresholds are the local ones: 3 failures and 30 seconds, doubling to 5 minutes, for the request breaker; the `breaker` block for the discovery breaker; 3 failures and 30 seconds for the decision breaker. - A breaker reads as open when its local breaker or the shared breaker is open. +- With `redis.sharedState` on, the discovery `breaker.failureThreshold` counts failed refreshes across every route instance of every replica, not consecutive failures on one instance. Each instance runs its own discovery loop and adds each failed refresh to the shared count. Any success on any instance resets the count. The count also expires after twice `breaker.maxOpenDuration`. With the default threshold of `3` and several instances, a single round of failed refreshes can open the shared breaker. Raise `failureThreshold` for a large fleet. The local breaker of each instance still counts consecutive failures on that instance. - In-flight load is the larger of the local count and the shared count. A request that never ends stops counting after its start epoch leaves the read window. The window is the longest request timeout in 5 minute epochs, plus one epoch. - The request path never calls Redis. It reads a local copy. A background loop sends the counts and refreshes the copy every second, so a change on one replica reaches the others in about 1 second. The token-size estimate refreshes every 60 seconds with the router learning loop, and it applies after 50 shared samples. - A Redis outage never fails or slows a request, and `redis.failOpen` does not apply to this state. After 3 failed refreshes in a row the gateway drops the shared values and uses its own local state. A failed token-size refresh keeps the last ratios. @@ -767,7 +768,7 @@ How it works: | Field | Type | Default | Semantics | |---|---|---|---| -| `failureThreshold` | `int` | `3` | Consecutive failed discovery refreshes that open the breaker — see [Provider health](#provider-health-discovery-circuit-breaker). `0` uses the default. Must be between `1` and `100`, or construction fails. | +| `failureThreshold` | `int` | `3` | Consecutive failed discovery refreshes that open the breaker — see [Provider health](#provider-health-discovery-circuit-breaker). With `redis.sharedState` on, it counts failed refreshes across all route instances and replicas instead — see [Shared state across replicas](#shared-state-across-replicas). `0` uses the default. Must be between `1` and `100`, or construction fails. | | `openDuration` | `string` (Go duration) | `1m` | Base backoff a newly opened breaker waits before its first half-open probe; doubles on every further failed probe, capped at `maxOpenDuration`. Invalid or non-positive duration string is a construction error. | | `maxOpenDuration` | `string` (Go duration) | `6h` | Ceiling on the backoff `openDuration` doubles into. Must be `>= openDuration` and no more than `24h`, or construction fails. Deliberately longer than the default `discoveryInterval` (1h) — see [Provider health](#provider-health-discovery-circuit-breaker) for why a value at or below `discoveryInterval` suppresses nothing. | diff --git a/shared_state_wire.go b/shared_state_wire.go index 1f0c779..ca63eae 100644 --- a/shared_state_wire.go +++ b/shared_state_wire.go @@ -20,6 +20,8 @@ func (g *Gateway) wireSharedState(cfg *Config) { if err != nil { brk = breakerConfig{failureThreshold: defaultBreakerFailureThreshold, openBase: defaultBreakerOpenDuration, openMax: defaultBreakerMaxOpenDuration} } + // With a shared breaker, brk.failureThreshold counts failed refreshes across all route instances and replicas + // inside 2*openMax, not consecutive failures on one instance. g.registry.shareBreaker(newSharedBreaker(g.sharedState, sharedKindDiscovery, ids, brk.failureThreshold, brk.openBase, brk.openMax, 2*brk.openMax)) }