ReadonlypolicyRecords what happens to each call and refuses the ones the circuit is not open to.
Belongs inside a retry, so every attempt is counted rather than one outage counting once, and outside the waiting policies, so an open circuit refuses immediately instead of queueing for a slot it will not use.
Failures counted so far: consecutive ones, or the ones inside the window for a breaker judging on rates.
Calls remembered in the window, or 0 for a breaker counting consecutive failures.
"open" while the circuit refuses calls, "half-open" once the reset
window has passed and the next call will be tried, "closed" otherwise.
Reading it changes nothing, which is what makes it safe for a health endpoint.
Stops calling a dependency that is failing, and tries one call when the reset window has passed.
The state lives on the object rather than in the options of a policy, so its scope is whatever you share it with: one breaker per dependency is usually right, and a breaker created inside a client factory is usually a breaker per client, which measures nothing.
Consecutive failures are the simple trip condition and the wrong one above a certain volume: 40% of calls failing, interleaved with successes, never reaches five in a row. Pass a
windowinstead and the breaker judges the share of recent calls that failed, or that took too long, which is what a dependency in trouble actually looks like.Constructing one starts no timer. The window is compared against the clock when a call arrives.