-
Notifications
You must be signed in to change notification settings - Fork 95
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
Implement circuit breaker #129
base: master
Are you sure you want to change the base?
Conversation
circuitbreaker/README.md
Outdated
} | ||
|
||
e := echo.New() | ||
e.Use(circuitbreaker.CircuitBreakerMiddleware(cbConfig)) |
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.
This example would be better if middleware is added to the route.
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.
Updated
circuitbreaker/circuit_breaker.go
Outdated
failureCount int | ||
successCount int | ||
state CircuitBreakerState | ||
mutex sync.Mutex |
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.
sync.RWMutex would be probably more appropriate here
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.
Thanks, Updated
circuitbreaker/circuit_breaker.go
Outdated
ResetTimeout time.Duration // Interval for monitoring the circuit state | ||
SuccessReset int // Number of successful attempts to move to closed state | ||
OnOpen func(ctx echo.Context) error // Callback for open state | ||
OnHalfOpen func(ctx echo.Context) error // Callback for half-open 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.
some of these callbacks are not used
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.
Added
circuitbreaker/circuit_breaker.go
Outdated
func (cb *CircuitBreaker) monitorReset() { | ||
for { | ||
select { | ||
case <-time.After(cb.resetTimeout): |
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 time.NewTicker
https://pkg.go.dev/time#example-NewTicker would be more suitable
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.
Thanks changed to ticker
circuitbreaker/circuit_breaker.go
Outdated
cb.failureCount = 0 // Reset failure count | ||
} | ||
cb.mutex.Unlock() | ||
case <-cb.exitChan: |
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.
where is this chan used so we could receive something here?
@aldas I've made changes, can you please check again? |
This PR contains Circuit Breaker Middleware
@aldas @jrhrmsll @lammel Would appreciate it if you can review this PR.