-
Notifications
You must be signed in to change notification settings - Fork 81
Add lumping_interval Feature for Semian Circuit Breakers #606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
77226a1
to
079c0d0
Compare
lib/semian/circuit_breaker.rb
Outdated
@@ -26,6 +27,11 @@ def initialize(name, exceptions:, success_threshold:, error_threshold:, | |||
@error_timeout = error_timeout | |||
@exceptions = exceptions | |||
@half_open_resource_timeout = half_open_resource_timeout | |||
@lumping_interval = lumping_interval | |||
|
|||
if @lumping_interval >= @error_threshold_timeout && @lumping_interval > 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need the &&
here? I think what would make more sense is to prevent negative values for all parameters instead
lib/semian/circuit_breaker.rb
Outdated
if error_threshold_timeout_enabled | ||
@errors.reject! { |err_time| err_time + @error_threshold_timeout < time } | ||
end | ||
|
||
@errors << time | ||
if @lumping_interval == 0 || @errors.empty? || @errors.last < time - @lumping_interval |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the first condition necessary here? 🤔
079c0d0
to
a27c582
Compare
fix notation for index for SlidingWindow and edge case for empty array
a27c582
to
00c9d2d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, can we add the new feature to the README?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved, but suggested a clarification in the README
README.md
Outdated
the circuit is half-open (supported for MySQL, Net::HTTP and Redis). | ||
- **lumping_interval**. Interval for timeframe of errors to be lumped and recorded as one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- **lumping_interval**. Interval for timeframe of errors to be lumped and recorded as one. | |
- **lumping_interval**. If provided, errors within this interval will be lumped and recorded as one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would also be good to mention that it's in seconds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Changes:
push_time
,create_circuit_breaker
, andinitialize
functions to incorporate lumping intervalsRationale:
When it comes to real-world applications, errors can sometimes occur in short-term bursts due to insignificant network disruptions, outages, or other small "blips" in the network that rapidly self-resolve.
Under the current implementation, each error, no matter how close together in time, counts individually. This means that a short burst of errors, no matter how far apart they are in time, will affect the circuit breaker by accumulating the error count. This has a few issues:
Implementation: