Documentation ¶
Overview ¶
Package breakerbp integrates with https://github.com/sony/gobreaker and provides a thrift compatible circuit breaker implementation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CircuitBreaker ¶ added in v0.8.0
type CircuitBreaker interface { // Execute should wrap the given function call in circuit breaker logic and return the result. Execute(func() (interface{}, error)) (interface{}, error) }
CircuitBreaker is the interface that baseplate expects a circuit breaker to implement.
type Config ¶
type Config struct { // Minimum requests that need to be sent during a time period before the breaker is eligible to transition from closed to open. MinRequestsToTrip int `yaml:"minRequestsToTrip"` // Percentage of requests that need to fail during a time period for the breaker to transition from closed to open. // Represented as a float in [0,1], where .05 means >=5% failures will trip the breaker. FailureThreshold float64 `yaml:"failureThreshold"` // Name for this circuit breaker, mostly used as a prefix to disambiguate logs when multiple cb are used. Name string `yaml:"name"` // EmitStatusMetrics sets whether the failure breaker will regularly update a gauge on the breakers state (closed or open/halfopen). // When enabled, it emits metrics using the interval of EmitStatusMetricsInterval. // If EmitStatusMetricsInterval <=0, metricsbp.SysStatsTickerInterval will be used as the fallback. // // Deprecated: Statsd metrics are deprecated. EmitStatusMetrics bool `yaml:"emitStatusMetrics"` // Deprecated: Statsd metrics are deprecated. EmitStatusMetricsInterval time.Duration `yaml:"emitStatusMetricsInterval"` // Logger is the logger to be called when the breaker changes states. Logger log.Wrapper `yaml:"logger"` // MaxRequestsHalfOpen represents he Maximum amount of requests that will be allowed through while the breaker // is in half-open state. If left unset (or set to 0), exactly 1 request will be allowed through while half-open. MaxRequestsHalfOpen uint32 `yaml:"maxRequestsHalfOpen"` // Interval represents the cyclical period of the 'Closed' state. // If 0, internal counts do not get reset while the breaker remains in the Closed state. Interval time.Duration `yaml:"interval"` // Timeout is the duration of the 'Open' state. After an 'Open' timeout duration has passed, the breaker enters 'half-open' state. Timeout time.Duration `yaml:"timeout"` }
Config represents the configuration for a FailureRatioBreaker.
type FailureRatioBreaker ¶
type FailureRatioBreaker struct {
// contains filtered or unexported fields
}
FailureRatioBreaker is a circuit breaker based on gobreaker that uses a low-water-mark and % failure threshold to trip.
func NewFailureRatioBreaker ¶
func NewFailureRatioBreaker(config Config) FailureRatioBreaker
NewFailureRatioBreaker creates a new FailureRatioBreaker with the provided configuration.
func (FailureRatioBreaker) Execute ¶ added in v0.6.1
func (cb FailureRatioBreaker) Execute(fn func() (interface{}, error)) (interface{}, error)
Execute wraps the given function call in circuit breaker logic and returns the result.
func (FailureRatioBreaker) State ¶ added in v0.9.0
func (cb FailureRatioBreaker) State() gobreaker.State
State returns the current state of the breaker.
func (FailureRatioBreaker) ThriftMiddleware ¶
func (cb FailureRatioBreaker) ThriftMiddleware(next thrift.TClient) thrift.TClient
ThriftMiddleware is a thrift.ClientMiddleware that handles circuit breaking.