connor4312 / cockatiel

🐦 A resilience and fault-handling library. Supports Backoffs, Retries, Circuit Breakers, Timeouts, Bulkhead Isolation, and Fallbacks.
MIT License
1.59k stars 50 forks source link

Recovering from half-open state based on a success threshold #73

Open kevkcc opened 1 year ago

kevkcc commented 1 year ago

Hi, was wondering if there were plans and/or a suggested workaround for recovering from a half-open state based on a success threshold as described in Microsoft's circuit breaker pattern page: https://learn.microsoft.com/en-us/azure/architecture/patterns/circuit-breaker

Currently, the behaviour in cockatiel (as well as opossum) is we have one trial call and if this call succeeds, we recover back into the closed state and if this call fails, we fail back into the open state (0% error rate on 1 call). But maybe we want less than 30% error rate on the next 10 calls for instance.

Resilience4j offers something along these lines with permittedNumberOfCallsInHalfOpenState: https://javadoc.io/static/io.github.resilience4j/resilience4j-circuitbreaker/1.2.0/io/github/resilience4j/circuitbreaker/CircuitBreakerConfig.Builder.html#permittedNumberOfCallsInHalfOpenState-int-

Thanks for creating this great library!

connor4312 commented 1 year ago

Would be happy to add this. PR's welcome if you're up for it.