failsafe-lib / failsafe

Fault tolerance and resilience patterns for the JVM
https://failsafe.dev
Apache License 2.0
4.2k stars 297 forks source link

Add time based thresholding to CircuitBreaker #237

Closed jhalterman closed 4 years ago

jhalterman commented 4 years ago

Work in progress...

This PR adds a few time based thresholding methods:

These methods allow a convenient way to specify 3 related configurations in a single call, as with the pre-existing withFailureThreshold and withSuccessThreshold methods.

This PR also changes some of the previous getters for retrieving thresholding configuration, which I lamented about, but hopefully adds some clear separation between configuration that is relevant for "count based" thresholding vs "time based" thresholding.

Previously getFailureThreshold returned a Ratio representing the threshold of failures to executions that the breaker would track and expect before transitioning the circuit to open. The ratio's numerator represented the failureThreshold and the denominator represented the failureThresholdingCapacity (so to speak). When we add time based thresholding, we don't have a thresholding capacity per se, but we do have a separate execution threshold. Behaviorally they're a bit different. So this PR gets rid of the Ratio that's returned by getFailureThreshold and getSuccessThreshold and breaks things apart to separate getter methods. The PR still retains the withFailureThreshold semantics for conveniently configuring multiple related values in a single call. And each parameter in a withFailureThreshold method now corresponds to a single getter with the same name.

See the CHANGES.md for details on what changed.

Fixes #208.

coveralls commented 4 years ago

Coverage Status

Coverage increased (+0.9%) to 93.301% when pulling e6ca6100a7db712103f9e25e72d4a54cb9e5769e on gh208 into 17dc2f9b8f1467ae752707b61d3314e5db793481 on master.