Documentation ¶
Overview ¶
Package circuit provides a circuit breaker implementation.
Index ¶
- Constants
- type Breaker
- type NotifyFunc
- type Observer
- type Option
- func WithCooldown(cooldown time.Duration) Option
- func WithFailureRatio(ratio float64) Option
- func WithFilter(filter func(error) error) Option
- func WithJitterFactor(jitter float64) Option
- func WithLogger(log logr.Logger) Option
- func WithMinResults(min int) Option
- func WithMinSuccess(min int) Option
- func WithNotifyFunc(notify NotifyFunc) Option
- func WithObserver(observer Observer) Option
- func WithSpacing(spacing time.Duration) Option
- func WithWindow(window time.Duration) Option
- type State
Constants ¶
const ( DefaultWindow = 10 * time.Second DefaultCooldown = 5 * time.Second DefaultSpacing = 2 * time.Second DefaultJitterFactor = 0.25 DefaultMinSuccess = 3 DefaultMinResults = 5 DefaultFailureRatio = 0.5 )
Default values.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Breaker ¶
type Breaker struct {
// contains filtered or unexported fields
}
A Breaker is a circuit breaker.
func NewBreaker ¶
NewBreaker returns a circuit breaker with the given options.
func (*Breaker) AddNotifyFunc ¶
func (b *Breaker) AddNotifyFunc(notify NotifyFunc)
AddNotifyFunc adds the notify function to be called in a critical section when the State of the circuit breaker changes.
func (*Breaker) Allow ¶
Allow returns a value indicating if an operation is allowed. If the operation is allowed, its result MUST be recorded.
type NotifyFunc ¶
type NotifyFunc func(state State)
A NotifyFunc is a function that is called in a critical section when the state of a circuit breaker changes.
type Observer ¶
type Observer interface { // ObserverStateChange is a called in a critical section // when the state of the circuit breaker changes. ObserveStateChange(state State) }
An Observer observes changes to circuit breakers.
type Option ¶
An Option provides an override to defaults.
func WithCooldown ¶
WithCooldown returns an Option that sets the cooldown time before probes will be allowed when the circuit breaker is Open. The default is 5s.
func WithFailureRatio ¶
WithFailureRatio returns an Option that sets the minimum failure ratio in a window required to switch the circuit breaker from Closed to Open. The default is 50%.
func WithFilter ¶
WithFilter returns an Option that specifies a function to filter expected error results that should not be counted as a failure (e.g. Canceled, InvalidArgument, NotFound, etc.).
func WithJitterFactor ¶
WithJitterFactor returns an Option that sets the random jitter factor applied to cooldown and spacing delays. The default is 25%.
func WithLogger ¶
WithLogger returns an Option that specifies the logger.
func WithMinResults ¶
WithMinResults returns an Option that sets the minimum number of results in a window required to switch the circuit breaker from Closed to Open. The default is 5.
func WithMinSuccess ¶
WithMinSuccess returns an Option that sets the minimum number of consecutive successful probes required to switch the circuit breaker from HalfOpen to Closed. The default is 3.
func WithNotifyFunc ¶
func WithNotifyFunc(notify NotifyFunc) Option
WithNotifyFunc returns an Option that adds a function to be called in a critical section when the State of the circuit breaker changes.
func WithObserver ¶
WithObserver returns an Option that adds an Observer.
func WithSpacing ¶
WithSpacing returns an Option that sets the spacing time between allowed probes when the circuit breaker is HalfOpen. The default is 2s.
func WithWindow ¶
WithWindow returns an Option that sets the window of time after which results are reset when the circuit breaker is Closed. The default is 10s.
Directories ¶
Path | Synopsis |
---|---|
Package circuitprom provides a Prometheus collector for circuit breakers.
|
Package circuitprom provides a Prometheus collector for circuit breakers. |