Skip to content

Commit

Permalink
Merge pull request #229 from sak0/fix_circuitbreaker_resume
Browse files Browse the repository at this point in the history
fix resume circuitbreaker
  • Loading branch information
ChaoyongLiang authored Jan 21, 2025
2 parents 9203e8b + a354448 commit d50069b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
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

0 comments on commit d50069b

Please sign in to comment.