-
Notifications
You must be signed in to change notification settings - Fork 2
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: replace circuit breaker with library #98
feat: replace circuit breaker with library #98
Conversation
Previous implementation of circuit breaker was simplistic. It is replaced with a third-party library "gobreaker/v2". The function signature "recoverAfter" was removed to fit the implementation of the library. Test cases for circuit breaker were modified accordingly.
|
||
lock := &sync.RWMutex{} | ||
semiOpenLock := &sync.Mutex{} | ||
func NewCircuitBreakerMiddleware(threshold uint, period time.Duration) func(next wasabi.RequestHandler) wasabi.RequestHandler { |
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.
Let's update type of threshold
to uint32
to be in consistent.
if err != nil { | ||
return err |
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.
Could you check for gobreaker.ErrOpenState
error and return instead ErrCircuitBreakerOpen
to hide dependency on the gobreaker... to have possibility to replace library in the future.
"time" | ||
|
||
"github.com/ksysoev/wasabi" | ||
"github.com/ksysoev/wasabi/dispatch" | ||
"github.com/sony/gobreaker/v2" | ||
) | ||
|
||
type CircuitBreakerState uint8 |
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.
Probably this type is not needed anymore.
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.
@KianYang-Lee left few comments, rest looks good
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, Thanks for your contribution
Previous implementation of circuit breaker was simplistic. It is replaced with a third-party library "gobreaker/v2". The function signature "recoverAfter" was removed to fit the implementation of the library. Test cases for circuit breaker were modified accordingly.
Closes #77