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

fix resume circuitbreaker #229

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions plugin/circuitbreaker/composite/counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ func (rc *ResourceCounters) HalfOpenToClose() {
rc.log.Infof("previous status %s, current status %s, resource %s, rule %s", status.GetStatus(),
newStatus.GetStatus(), rc.resource.String(), status.GetCircuitBreaker())
rc.reportCircuitStatus(newStatus)

for _, counter := range rc.counters {
counter.Resume()
}
}

func (rc *ResourceCounters) HalfOpenToOpen() {
Expand Down
6 changes: 6 additions & 0 deletions plugin/circuitbreaker/composite/trigger/consecutive.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,9 @@ func (c *ConsecutiveCounter) Report(success bool) {
atomic.StoreInt32(&c.consecutiveErrors, 0)
}
}

func (c *ConsecutiveCounter) Resume() {
if c.isSuspend() {
c.resume()
}
}
2 changes: 2 additions & 0 deletions plugin/circuitbreaker/composite/trigger/counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ type Options struct {
type TriggerCounter interface {
// Report .
Report(success bool)
// Resume .
Resume()
}

func newBaseCounter(rule string, opt *Options) *baseCounter {
Expand Down
6 changes: 6 additions & 0 deletions plugin/circuitbreaker/composite/trigger/err_rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ func (c *ErrRateCounter) Report(success bool) {
}
}

func (c *ErrRateCounter) Resume() {
if c.isSuspend() {
c.resume()
}
}

func getBucketInterval(interval time.Duration) time.Duration {
bucketSize := math.Ceil(float64(interval) / float64(bucketCount))
return time.Duration(bucketSize)
Expand Down
Loading