-
Notifications
You must be signed in to change notification settings - Fork 187
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 structSettings
:
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 asInterval
(i.e. the number of buckets is1
), the behavior ofCircuitBreaker
does not change at all. - If
Interval
is zero (no matter what valueBucketPeriod
takes),CircuitBreaker
doesn't clear the internalCounts
during the closed state.
- If
-
Adjust the value of
Interval
to be an integer multiple ofBucketPeriod
:
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 theBucketCounts
.- Sum up
ConsecutiveSuccesses
/ConsecutiveFailures
only if its value is the same asRequests
- Sum up
type Counts struct {
Requests uint32
TotalSuccesses uint32
TotalFailures uint32
ConsecutiveSuccesses uint32
ConsecutiveFailures uint32
}