-
Notifications
You must be signed in to change notification settings - Fork 77
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
Add Circuit Breaker implementation #1738
Conversation
Signed-off-by: hlts2 <[email protected]>
[WARNING:INTCFG] Changes in |
[CHATOPS:HELP] ChatOps commands.
|
Codecov Report
@@ Coverage Diff @@
## master #1738 +/- ##
==========================================
- Coverage 31.64% 31.27% -0.37%
==========================================
Files 372 381 +9
Lines 32313 32698 +385
==========================================
+ Hits 10224 10225 +1
- Misses 21696 22071 +375
- Partials 393 402 +9
Continue to review full report at Codecov.
|
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.
Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit
golangci
internal/circuitbreaker/breaker.go|105 col 6| variable name 'ok' is too short for the scope of its usage (varnamelen)
internal/circuitbreaker/manager.go|48 col 6| variable name 'st' is too short for the scope of its usage (varnamelen)
internal/circuitbreaker/breaker.go|106 col 6| variable name 'st' is too short for the scope of its usage (varnamelen)
internal/circuitbreaker/options.go|95 col 14| parameter name 'b' is too short for the scope of its usage (varnamelen)
internal/circuitbreaker/options.go|112 col 14| parameter name 'b' is too short for the scope of its usage (varnamelen)
internal/observability/metrics/circuitbreaker/circuitbreaker.go|57 col 2| variable name 'ms' is too short for the scope of its usage (varnamelen)
) | ||
|
||
func (s State) String() string { | ||
switch s { |
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.
🚫 [golangci] reported by reviewdog 🐶
missing cases in switch of type State: StateUnknown (exhaustive)
Signed-off-by: hlts2 <[email protected]>
Signed-off-by: hlts2 <[email protected]>
Signed-off-by: hlts2 <[email protected]>
Deploying with Cloudflare Pages
|
Signed-off-by: hlts2 <[email protected]>
return nil | ||
} | ||
tests := []test{ | ||
// TODO test cases |
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.
🚫 [golangci] reported by reviewdog 🐶
internal/errors/circuitbreaker_test.go:47: Line contains TODO/BUG/FIXME: "TODO test cases" (godox)
}, | ||
*/ | ||
|
||
// TODO test cases |
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.
🚫 [golangci] reported by reviewdog 🐶
internal/errors/circuitbreaker_test.go:59: Line contains TODO/BUG/FIXME: "TODO test cases" (godox)
return nil | ||
} | ||
tests := []test{ | ||
// TODO test cases |
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.
🚫 [golangci] reported by reviewdog 🐶
internal/errors/circuitbreaker_test.go:120: Line contains TODO/BUG/FIXME: "TODO test cases" (godox)
}, | ||
*/ | ||
|
||
// TODO test cases |
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.
🚫 [golangci] reported by reviewdog 🐶
internal/errors/circuitbreaker_test.go:132: Line contains TODO/BUG/FIXME: "TODO test cases" (godox)
return nil | ||
} | ||
tests := []test{ | ||
// TODO test cases |
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.
🚫 [golangci] reported by reviewdog 🐶
internal/errors/circuitbreaker_test.go:196: Line contains TODO/BUG/FIXME: "TODO test cases" (godox)
|
||
// Do invokes the breaker matching the given key. | ||
func (bm *breakerManager) Do(ctx context.Context, key string, fn func(ctx context.Context) (interface{}, error)) (val interface{}, err error) { | ||
var st State |
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.
🚫 [golangci] reported by reviewdog 🐶
variable name 'st' is too short for the scope of its usage (varnamelen)
cnt.onFail() | ||
|
||
var ok bool | ||
var st State |
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.
🚫 [golangci] reported by reviewdog 🐶
variable name 'st' is too short for the scope of its usage (varnamelen)
cnt := b.count.Load().(*count) | ||
cnt.onFail() | ||
|
||
var ok bool |
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.
🚫 [golangci] reported by reviewdog 🐶
variable name 'ok' is too short for the scope of its usage (varnamelen)
// WithOpenTimeout returns an option that sets the timeout of "Open" state. | ||
// After this period, the state will be changed from "Open" to "HalfOpen". | ||
func WithOpenTimeout(timeout string) BreakerOption { | ||
return func(b *breaker) error { |
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.
🚫 [golangci] reported by reviewdog 🐶
parameter name 'b' is too short for the scope of its usage (varnamelen)
// WithClosedRefreshTimeout returns an option that sets the timeout of "Closed" state. | ||
// After this period, the counter will be refreshed. | ||
func WithClosedRefreshTimeout(timeout string) BreakerOption { | ||
return func(b *breaker) error { |
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.
🚫 [golangci] reported by reviewdog 🐶
parameter name 'b' is too short for the scope of its usage (varnamelen)
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
type args struct { | ||
opts []BreakerOption | ||
} | ||
type want struct { |
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.
🚫 [golangci] reported by reviewdog 🐶
type want
is unused (unused)
Description:
WHY
When checking backoff metrics with Grafana, I noticed a large number of unnecessary backoff retries.
WHAT
I developed the Circuit Breaker function to prevent a large number of unnecessary retries.
Related Issue:
How Has This Been Tested?:
Environment:
Types of changes:
Changes to Core Features:
Checklist: