Documentation ¶
Index ¶
- func CircuitsReset()
- func SetExporter(export MetricExport)
- func UseStatsd(address string, prefix string, dur time.Duration)
- type CircuitBreaker
- type CircuitHolder
- type Command
- func NewCommand(name string, group string, command Interface) *Command
- func NewCommandFunc(name string, group string, commandFunc CommandFunc) *Command
- func NewCommandFuncFallback(name string, group string, commandFunc CommandFunc, fallbackFunc CommandFunc) *Command
- func NewCommandWithOptions(name string, group string, command Interface, options CommandOptions) *Command
- type CommandError
- type CommandFunc
- type CommandFuncFallbackWrap
- type CommandFuncWrap
- type CommandOptions
- type Executor
- type FallbackInterface
- type HealthCounts
- type HealthCountsBucket
- type Interface
- type Metric
- func (m *Metric) Fail()
- func (m *Metric) Fallback()
- func (m *Metric) FallbackError()
- func (m *Metric) HealthCounts() HealthCounts
- func (m *Metric) LastFailure() time.Time
- func (m *Metric) LastSuccess() time.Time
- func (m *Metric) LastTimeout() time.Time
- func (m *Metric) Panic()
- func (m *Metric) Stats() sample.Sample
- func (m *Metric) Success(duration time.Duration)
- func (m *Metric) Timeout()
- type MetricExport
- type NilExport
- func (NilExport) Fail(group string, name string)
- func (NilExport) Fallback(group string, name string)
- func (NilExport) FallbackError(group string, name string)
- func (NilExport) Panic(group string, name string)
- func (NilExport) State(circuits *CircuitHolder)
- func (NilExport) Success(group string, name string, duration time.Duration)
- func (NilExport) Timeout(group string, name string)
- type StatsdExport
- func (s StatsdExport) Fail(group string, name string)
- func (s StatsdExport) Fallback(group string, name string)
- func (s StatsdExport) FallbackError(group string, name string)
- func (s StatsdExport) Panic(group string, name string)
- func (s StatsdExport) State(holder *CircuitHolder)
- func (s StatsdExport) Success(group string, name string, duration time.Duration)
- func (s StatsdExport) Timeout(group string, name string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CircuitsReset ¶
func CircuitsReset()
func SetExporter ¶
func SetExporter(export MetricExport)
Types ¶
type CircuitBreaker ¶
type CircuitBreaker struct {
// contains filtered or unexported fields
}
func NewCircuit ¶
func NewCircuit(group string, name string, options CommandOptions) *CircuitBreaker
func NewCircuitNoParams ¶
func NewCircuitNoParams(group string, name string) *CircuitBreaker
func (*CircuitBreaker) IsOpen ¶
func (c *CircuitBreaker) IsOpen() (bool, string)
func (*CircuitBreaker) Metric ¶
func (c *CircuitBreaker) Metric() *Metric
func (*CircuitBreaker) ToJSON ¶
func (c *CircuitBreaker) ToJSON() string
type CircuitHolder ¶
type CircuitHolder struct {
// contains filtered or unexported fields
}
func Circuits ¶
func Circuits() *CircuitHolder
func NewCircuitsHolder ¶
func NewCircuitsHolder() *CircuitHolder
func (*CircuitHolder) Get ¶
func (holder *CircuitHolder) Get(group string, name string) (*CircuitBreaker, bool)
func (*CircuitHolder) Set ¶
func (holder *CircuitHolder) Set(group string, name string, value *CircuitBreaker)
func (*CircuitHolder) ToJSON ¶
func (holder *CircuitHolder) ToJSON() string
type Command ¶
func NewCommand ¶
NewCommand- create a new command with the default values
func NewCommandFunc ¶
func NewCommandFunc(name string, group string, commandFunc CommandFunc) *Command
func NewCommandFuncFallback ¶
func NewCommandFuncFallback(name string, group string, commandFunc CommandFunc, fallbackFunc CommandFunc) *Command
func NewCommandWithOptions ¶
func NewCommandWithOptions(name string, group string, command Interface, options CommandOptions) *Command
type CommandError ¶
type CommandError struct {
// contains filtered or unexported fields
}
func NewCommandError ¶
func NewCommandError(group string, name string, runError error, fallbackError error) CommandError
type CommandFuncFallbackWrap ¶
type CommandFuncFallbackWrap struct {
// contains filtered or unexported fields
}
func (CommandFuncFallbackWrap) Fallback ¶
func (c CommandFuncFallbackWrap) Fallback() (interface{}, error)
func (CommandFuncFallbackWrap) Run ¶
func (c CommandFuncFallbackWrap) Run() (interface{}, error)
type CommandFuncWrap ¶
type CommandFuncWrap struct {
// contains filtered or unexported fields
}
func (CommandFuncWrap) Run ¶
func (c CommandFuncWrap) Run() (interface{}, error)
type CommandOptions ¶
type CommandOptions struct { ErrorsThreshold float64 MinimumNumberOfRequest int64 NumberOfSecondsToStore int NumberOfSamplesToStore int Timeout time.Duration }
CommandOptions, you can custimize the values, for the Circuit Breaker and the Metrics stores ErrorsThreshold - if number_of_errors / total_calls * 100 > errorThreshold the circuit will be open MinimumNumberOfRequest - if total_calls < minimumNumberOfRequest the circuit will be close NumberOfSecondsToStore - Is the number of seconds to count the stats, for example 10 stores just the last 10 seconds of calls NumberOfSamplesToStore - Is the number of samples to store for calculate the stats, greater means more precision to get Mean, Max, Min... Timeout - the timeout for the command
func CommandOptionsDefaults ¶
func CommandOptionsDefaults() CommandOptions
CommandOptionsDefaults ErrorsThreshold - 50 - If number_of_errors / total_calls * 100 > 50.0 the circuit will be open MinimumNumberOfRequest - if total_calls < 20 the circuit will be close NumberOfSecondsToStore - 20 seconds NumberOfSamplesToStore - 50 values Timeout - 2 * time.Seconds
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
func NewExecutor ¶
func NewExecutor(name string, group string, command Interface, options CommandOptions) *Executor
func (*Executor) HealthCounts ¶
func (ex *Executor) HealthCounts() HealthCounts
type FallbackInterface ¶
type HealthCounts ¶
type HealthCounts struct { HealthCountsBucket Total int64 ErrorPercentage float64 }
type HealthCountsBucket ¶
type HealthCountsBucket struct { Failures int64 Success int64 Fallback int64 FallbackErrors int64 Timeouts int64 Panics int64 // contains filtered or unexported fields }
func (*HealthCountsBucket) Reset ¶
func (c *HealthCountsBucket) Reset()
type Metric ¶
type Metric struct {
// contains filtered or unexported fields
}
func NewMetricWithParams ¶
func (*Metric) FallbackError ¶
func (m *Metric) FallbackError()
func (*Metric) HealthCounts ¶
func (m *Metric) HealthCounts() HealthCounts
func (*Metric) LastFailure ¶
func (*Metric) LastSuccess ¶
func (*Metric) LastTimeout ¶
type MetricExport ¶
type MetricExport interface { Success(group string, name string, duration time.Duration) Fail(group string, name string) Fallback(group string, name string) FallbackError(group string, name string) Timeout(group string, name string) Panic(group string, name string) State(circuits *CircuitHolder) }
func Exporter ¶
func Exporter() MetricExport
func NewNilExport ¶
func NewNilExport() MetricExport
func NewStatsdExport ¶
func NewStatsdExport(statsdClient statsd.Statter, prefix string) MetricExport
type NilExport ¶
type NilExport struct { }
func (NilExport) FallbackError ¶
func (NilExport) State ¶
func (NilExport) State(circuits *CircuitHolder)
type StatsdExport ¶
type StatsdExport struct {
// contains filtered or unexported fields
}
func (StatsdExport) Fail ¶
func (s StatsdExport) Fail(group string, name string)
func (StatsdExport) Fallback ¶
func (s StatsdExport) Fallback(group string, name string)
func (StatsdExport) FallbackError ¶
func (s StatsdExport) FallbackError(group string, name string)
func (StatsdExport) Panic ¶
func (s StatsdExport) Panic(group string, name string)
func (StatsdExport) State ¶
func (s StatsdExport) State(holder *CircuitHolder)
func (StatsdExport) Success ¶
func (s StatsdExport) Success(group string, name string, duration time.Duration)
func (StatsdExport) Timeout ¶
func (s StatsdExport) Timeout(group string, name string)