yammer / circuitbox

Circuit breaker built with large Ruby apps in mind.
Other
704 stars 59 forks source link

Circuit Opening Improvements #188

Closed matthewshafer closed 1 year ago

matthewshafer commented 1 year ago

While there are a few changes in this PR most of them were leading up to the last one, which I'll write about first.

If a circuit were to experience a failure right before a time window changing it could be possible for the failure and success counts to be calculated from different time windows. While this could happen with any circuit store it may be more common with stores that take longer to load keys. It's also possible in instances where between failure_count and success_count calls the system clock were to be modified. The change calculates one time window and uses that value when generating both failure and success keys to be looked up in the circuit store.

Because both keys are being generated in should_open? I implemented values_at in circuitbox's memory store which should be compatible with moneta adapters. This allows multiple keys to be loaded in one call to the circuit store, which should improve performance on stores that natively support this functionality. Additionally because of the changes I was making to the memory store I removed fetch_value and replaced its one use with ruby's safe navigation because that is more performant.

I noticed error_rate was always being called in should_open? even when the volume threshold was not passed so I moved this calculation into the passed_rate_threshold? method.