Documentation
¶
Index ¶
Constants ¶
View Source
const (
// NumBuckets is the number of buckets used for time-based sliding window.
NumBuckets = 10
)
Variables ¶
View Source
var ( // ErrCircuitOpen is returned when the circuit breaker is in the Open state. ErrCircuitOpen = errors.New("circuit breaker is open") )
Functions ¶
This section is empty.
Types ¶
type Breaker ¶
type Breaker struct {
// contains filtered or unexported fields
}
Breaker implements a circuit breaker state machine with sliding windows.
type Config ¶
type Config struct {
// WindowType specifies the type of sliding window.
WindowType WindowType
// WindowSize is the size of the count-based sliding window.
// Default is 100.
WindowSize uint32
// WindowDuration is the duration of the time-based sliding window.
// Default is 60 seconds.
WindowDuration time.Duration
// FailureRateThreshold is the failure rate percentage (0.0 to 100.0).
// If failures/total >= FailureRateThreshold/100, the circuit opens.
// Default is 50.0.
FailureRateThreshold float64
// MinimumCalls is the minimum number of calls in the current window before the failure rate is calculated.
// Default is 10.
MinimumCalls uint64
// ResetTimeout is the duration to wait in Open state before moving to Half-Open.
// Default is 60 seconds.
ResetTimeout time.Duration
// HalfOpenMaxCalls is the number of calls allowed in Half-Open state.
// Default is 10.
HalfOpenMaxCalls uint64
}
Config defines the configuration for the circuit breaker.
type WindowType ¶ added in v1.0.4
type WindowType int
WindowType specifies whether the window is count-based or time-based.
const ( // WindowCountBased uses the last N calls to calculate failure rate. WindowCountBased WindowType = iota // WindowTimeBased uses calls in the last N duration to calculate failure rate. WindowTimeBased )
Click to show internal directories.
Click to hide internal directories.