-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
feat(utils): Add core CircuitBreaker
functionality
#74560
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #74560 +/- ##
==========================================
+ Coverage 78.14% 78.15% +0.01%
==========================================
Files 6731 6731
Lines 300214 300243 +29
Branches 51642 51646 +4
==========================================
+ Hits 234608 234664 +56
+ Misses 59285 59256 -29
- Partials 6321 6323 +2
|
try: | ||
self._set_in_redis( | ||
[ | ||
(self.broken_state_key, broken_state_expiry, broken_state_timeout), | ||
(self.recovery_state_key, recovery_state_expiry, recovery_state_timeout), | ||
] | ||
) |
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.
Having get and set separate might lead to some concurrency weirdness, but I think the worst that can happen is it gets set to BROKEN multiple times in the same moment, which is fine.
55205da
to
20822f6
Compare
6bd2c86
to
526edc4
Compare
9b4a941
to
d5c9975
Compare
e0d7108
to
347a4b1
Compare
46f8edb
to
347a4b1
Compare
8609b63
to
df575da
Compare
347a4b1
to
a6d8786
Compare
#74559) This is a follow-up to #74557, which added the beginnings of a rate-limit-based circuit breaker, in the form of a new `CircuitBreaker` class. In this PR, various helpers, for checking the state of the breaker and the underlying rate limiters and for communicating with redis, have been added to the class. It also adds a `MockCircuitBreaker` subclass for use in tests, which contains a number of methods for mocking both circuit breaker and rate limiter state. Note that though these helpers don't have accompanying tests, they are tested (indirectly) in the final PR in the series[1], as part of testing the methods which use them. [1] #74560
a6d8786
to
1713e4b
Compare
This completes the work, started in #74557 and #74559, of adding a new, class-and-rate-limit-based circuit breaker implementation to the codebase. In this PR, the core
record_error
andshould_allow_request
methods are added to theCircuitBreaker
class, along with accompaying tests.