Documentation
¶
Index ¶
- Constants
- type Counter
- type FailureHandler
- type FailureThresholdReachedError
- type InvalidOptionError
- type InvocationError
- type InvocationTimeoutError
- type IsAlreadyInDesiredStateError
- type IsOnOpenStateError
- type OnFailure
- type OnStateChange
- type OnSuccess
- type Operate
- type Operator
- type Option
- func WithCloser(minSuccessRatio float32, minRequests uint32) Option
- func WithCounter(c Counter) Option
- func WithFailureHandlers(state State, handlers ...FailureHandler) Option
- func WithInitialState(state State) Option
- func WithInvocationTimeout(duration time.Duration) Option
- func WithOpener(state State, minSuccessRatio float32, minRequests uint32) Option
- func WithResetTimer(t Timer) Option
- func WithRestrictors(restrictors ...Restrictor) Option
- func WithStateChangeHandlers(handlers ...StateChangeHandler) Option
- func WithSuccessHandlers(state State, handlers ...SuccessHandler) Option
- type Restrictor
- type Shift
- type State
- type StateChangeHandler
- type Stats
- type SuccessHandler
- type Timer
- type UnknownStateError
Constants ¶
const ( // CtxState holds state context key CtxState = ctxKey("state") // CtxStats holds stats context key CtxStats = ctxKey("stats") )
const (
// Version matches with the current version of the package
Version = "1.0.0"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Counter ¶ added in v1.0.0
type Counter interface { Increment(metric string) Stats(metrics ...string) map[string]uint32 Reset() }
Counter is an interface to increment, reset and fetch invocation stats
type FailureHandler ¶ added in v1.0.0
FailureHandler is an interface to handle failure events
type FailureThresholdReachedError ¶ added in v1.0.0
type FailureThresholdReachedError struct{}
FailureThresholdReachedError is a error type for failure threshold
func (*FailureThresholdReachedError) Error ¶ added in v1.0.0
func (e *FailureThresholdReachedError) Error() string
type InvalidOptionError ¶
InvalidOptionError is a error tyoe for options
func (*InvalidOptionError) Error ¶
func (e *InvalidOptionError) Error() string
type InvocationError ¶ added in v1.0.0
InvocationError is an error type to wrap invocation errors
func (*InvocationError) Error ¶ added in v1.0.0
func (e *InvocationError) Error() string
func (*InvocationError) Unwrap ¶ added in v1.0.0
func (e *InvocationError) Unwrap() error
type InvocationTimeoutError ¶ added in v1.0.0
InvocationTimeoutError is a error type for invocation timeouts
func (*InvocationTimeoutError) Error ¶ added in v1.0.0
func (e *InvocationTimeoutError) Error() string
type IsAlreadyInDesiredStateError ¶ added in v1.0.0
IsAlreadyInDesiredStateError is an error type for stating the current state is already in desired state
func (*IsAlreadyInDesiredStateError) Error ¶ added in v1.0.0
func (e *IsAlreadyInDesiredStateError) Error() string
type IsOnOpenStateError ¶ added in v1.0.0
type IsOnOpenStateError struct{}
IsOnOpenStateError is a error type for open state
func (*IsOnOpenStateError) Error ¶ added in v1.0.0
func (e *IsOnOpenStateError) Error() string
type OnFailure ¶
OnFailure is a function to run as a callback on any error like timeout and invocation errors
type OnStateChange ¶
OnStateChange is a function to run on any state changes
func (OnStateChange) Handle ¶
func (fn OnStateChange) Handle(from, to State, stats Stats)
Handle implements StateChangeHandler for OnStateChange func
type Option ¶
Option is a type for circuit breaker options
func WithCloser ¶ added in v1.0.0
WithCloser builds an option to set the default success criteria trip to 'close' state. (If the success criteria matches then the circuit breaker trips to the 'close' state.)
As runtime behaviour, it appends a success handler for the given state to trip circuit breaker into the 'close' state when the given thresholds reached
Definitions of the params are state: StateHalfOpen(always half-open it is a hidden param) minSuccessRatio: min success ratio to trip the circuit breaker to close state minRequests: min number of requests before checking the ratio
Params with example: state: StateHalfOpen, minSuccessRatio: 99.5%, minRequests: 1000 The above configuration means that: On 'half-open' state, at min 1000 requests, if it counts 995 success then will trip to 'close' state
func WithCounter ¶ added in v1.0.0
WithCounter builds option to set stats counter
func WithFailureHandlers ¶ added in v1.0.0
func WithFailureHandlers(state State, handlers ...FailureHandler) Option
WithFailureHandlers builds option to set on failure handlers, the provided handlers will be evaluate in the given order as option
func WithInitialState ¶
WithInitialState builds option to set initial state
func WithInvocationTimeout ¶
WithInvocationTimeout builds option to set invocation timeout duration
func WithOpener ¶ added in v1.0.0
WithOpener builds an option to set the default failure criteria to trip to 'open' state. (If the failure criteria matches then the circuit breaker trips to the 'open' state.)
As runtime behaviour, it prepends a failure handler for the given state to trip circuit breaker into the 'open' state when the given thresholds reached.
Definitions of the params are state: StateClose, StateHalfOpen minSuccessRatio: min success ratio ratio to keep the Circuit Breaker as is minRequests: min number of requests before checking the ratio
Params with example: state: StateClose, minSuccessRatio: 95%, minRequests: 10 The above configuration means that: On 'close' state, at min 10 requests, if it calculates the success ratio less than or equal to 95% then will trip to 'open' state
func WithResetTimer ¶
WithResetTimer builds option to set reset timer
func WithRestrictors ¶
func WithRestrictors(restrictors ...Restrictor) Option
WithRestrictors builds option to set restrictors to restrict the invocations Restrictors does not effect the current state, but they can block the invocation depending on its own internal state values. If a restrictor blocks an invocation then it returns an error and `On Failure Handlers` get executed in order.
func WithStateChangeHandlers ¶ added in v1.0.0
func WithStateChangeHandlers(handlers ...StateChangeHandler) Option
WithStateChangeHandlers builds option to set state change handlers, the provided handlers will be evaluate in the given order as option
func WithSuccessHandlers ¶ added in v1.0.0
func WithSuccessHandlers(state State, handlers ...SuccessHandler) Option
WithSuccessHandlers builds option to set on failure handlers, the provided handlers will be evaluate in the given order as option
type Restrictor ¶
type Restrictor interface { // Check checks if restriction allows to run current invocation and errors // if not allowed the invocation Check(context.Context) (bool, error) // Defer executes exit rules of the restrictor right after the run process Defer() }
Restrictor allows adding restriction to circuit breaker
type Shift ¶ added in v1.0.0
type Shift struct {
// contains filtered or unexported fields
}
Shift is an optioned circuit breaker implementation
type StateChangeHandler ¶ added in v1.0.0
StateChangeHandler is an interface to handle state change events
type Stats ¶ added in v1.0.0
type Stats struct {
SuccessCount, FailureCount, TimeoutCount, RejectCount uint32
}
Stats is a structure which holds cb invocation metrics
type SuccessHandler ¶ added in v1.0.0
SuccessHandler is an interface to handle success events
type Timer ¶
type Timer interface { // Next returns the current duration and sets the next duration according to // the given error Next(error) time.Duration // Reset resets the current duration to the initial duration Reset() }
Timer is an interface to set reset time duration dynamically depending on the occurred error on the invocation
type UnknownStateError ¶ added in v1.0.0
type UnknownStateError struct {
State State
}
UnknownStateError is a error tyoe for states
func (*UnknownStateError) Error ¶ added in v1.0.0
func (e *UnknownStateError) Error() string
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package mock is a generated GoMock package.
|
Package mock is a generated GoMock package. |