Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

MitulShah1
Copy link

This PR contains Circuit Breaker Middleware

@aldas @jrhrmsll @lammel Would appreciate it if you can review this PR.

}

e := echo.New()
e.Use(circuitbreaker.CircuitBreakerMiddleware(cbConfig))
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

failureCount int
successCount int
state CircuitBreakerState
mutex sync.Mutex
Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Updated

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
Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

func (cb *CircuitBreaker) monitorReset() {
for {
select {
case <-time.After(cb.resetTimeout):
Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks changed to ticker

cb.failureCount = 0 // Reset failure count
}
cb.mutex.Unlock()
case <-cb.exitChan:
Copy link
Contributor

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?

@MitulShah1
Copy link
Author

@aldas I've made changes, can you please check again?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants