Documentation
¶
Overview ¶
CircuitBreaker package implements circuit breaker pattern which acts as a proxy for a particular remote service. It trips the circuit if requests are likely to be failed to remote service and untrips it after requests would be successful.
Trip function is used to open the circuit based on the circuit counters Ex. if fail/(fail+success) > 0.5, trip circuit.
Circuit remains in open state for OpenTime duration and then changes to half-open state where the service is monitored.
OpenCircuit function is used to open the circuit from half-open state based on the circuit counters.
UnTrip function is used to close the circuit from half-open state based on the circuit counters. Ex. if success/(fail+success) > 0.9, untrip circuit if tripped.
Circuit counters will determine the status of the service.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CircuitBreaker ¶
type CircuitBreaker struct {
// contains filtered or unexported fields
}
CircuitBreaker acts as proxy for requests to a particular service. It opens the circuit if requests are likely to get fail otherwise allows the requests to pass the circuit.
func NewCircuitBreaker ¶
func NewCircuitBreaker(circuitName string, tripFunc, untripFunc, openFunc func(CircuitCounters) bool, openT int) *CircuitBreaker
NewCircuitBreaker returns circuitbreaker with custom settings
func NewDefaultCircuitBreaker ¶
func NewDefaultCircuitBreaker() *CircuitBreaker
NewDefaultCircuitBreaker returns circuitbreaker with default settings
func (*CircuitBreaker) ResetCounters ¶
func (cb *CircuitBreaker) ResetCounters()
ResetCounters will reset circuit counters It is invoked when state changes
func (*CircuitBreaker) Spark ¶
func (cb *CircuitBreaker) Spark(request func() (interface{}, error)) (interface{}, error)
Spark requests in the circuit of remote service if the circuit is in close/half-open state request would be passed else if the circuit is in open state request would be failed
type CircuitCounters ¶
CircuitCounters are counters for the circuit which is used to determine/change the state of circuit.
TODO implement Timeout and Rejection counter feedback to circuit