Skip to content

Draft Specification for Time‐Based Rolling Window

Yoshiyuki Mineo edited this page Oct 14, 2024 · 7 revisions
  • Support time-based rolling window

    • do not support count-based rolling window
  • Add BucketPeriod to the struct Settings:

type Settings struct {
	Name          string
	MaxRequests   uint32
	Interval      time.Duration
        BucketPeriod  time.Duration
	Timeout       time.Duration
	ReadyToTrip   func(counts Counts) bool
	OnStateChange func(name string, from State, to State)
	IsSuccessful  func(err error) bool
}
  • Keep compatibility with the current version

    • If BucketPeriod is zero or the same value as Interval (i.e. the number of buckets is 1), the behavior of CircuitBreaker does not change at all.
    • If Interval is zero (no matter what value BucketPeriod takes), CircuitBreaker doesn't clear the internal Counts during the closed state.
  • Adjust the value of Interval to be an integer multiple of BucketPeriod:
    Internal = (Internal + BucketPeriod - 1) / BucketPeriod * BucketPeriod
    numBuckets = Internal / BucketPeriod

  • Each bucket has BucketCounts:

type BucketCounts struct {
	Requests             uint32
	TotalSuccesses       uint32
	TotalFailures        uint32
	ConsecutiveSuccesses uint32
	ConsecutiveFailures  uint32
}
  • The existing struct Counts holds the totals of all the BucketCounts.
    • Sum up ConsecutiveSuccesses/ConsecutiveFailures only if its value is the same as Requests
type Counts struct {
	Requests             uint32
	TotalSuccesses       uint32
	TotalFailures        uint32
	ConsecutiveSuccesses uint32
	ConsecutiveFailures  uint32
}
Clone this wiki locally