Documentation
¶
Index ¶
Constants ¶
const ( // No means the service is not overloaded No = false // Yes means the service is overloaded Yes = true )
Variables ¶
var AlwaysClosedSettings = Settings{ ErrorRateThresholdPct: 0, ErrorRateWindow: 10 * time.Second, MinQPSForOpen: 10, CoolDownInterval: 10 * time.Second, HalfOpenSuccessCount: 1, }
AlwaysClosedSettings is a configuration that never trips the circuit breaker.
var CircuitBreakerKey = cbCtxKey{}
Key used to store circuit breaker
Functions ¶
func WithCircuitBreaker ¶
func WithCircuitBreaker(ctx context.Context, cb *CircuitBreaker) context.Context
WithCircuitBreaker stores the circuit breaker into a new context
Types ¶
type CircuitBreaker ¶
CircuitBreaker is a state machine to prevent sending requests that are likely to fail.
func FromContext ¶
func FromContext(ctx context.Context) *CircuitBreaker
FromContext retrieves the circuit breaker from the context
func NewCircuitBreaker ¶
func NewCircuitBreaker(name string, st Settings) *CircuitBreaker
NewCircuitBreaker returns a new CircuitBreaker configured with the given Settings.
func (*CircuitBreaker) ChangeSettings ¶
func (cb *CircuitBreaker) ChangeSettings(apply func(config *Settings))
ChangeSettings changes the CircuitBreaker settings. The changes will be reflected only in the next evaluation window.
func (*CircuitBreaker) Execute ¶
func (cb *CircuitBreaker) Execute(call func() (Overloading, error)) error
Execute calls the given function if the CircuitBreaker is closed and returns the result of execution. Execute returns an error instantly if the CircuitBreaker is open. https://github.com/tikv/rfcs/blob/master/text/0115-circuit-breaker.md
func (*CircuitBreaker) IsEnabled ¶
func (cb *CircuitBreaker) IsEnabled() bool
IsEnabled returns true if the circuit breaker is enabled.
type Settings ¶
type Settings struct { // Defines the error rate threshold to trip the circuit breaker. ErrorRateThresholdPct uint32 // Defines the average qps over the `error_rate_window` that must be met before evaluating the error rate threshold. MinQPSForOpen uint32 // Defines how long to track errors before evaluating error_rate_threshold. ErrorRateWindow time.Duration // Defines how long to wait after circuit breaker is open before go to half-open state to send a probe request. CoolDownInterval time.Duration // Defines how many subsequent requests to test after cooldown period before fully close the circuit. HalfOpenSuccessCount uint32 }
Settings describes configuration for Circuit Breaker