breakerbp

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2020 License: BSD-3-Clause Imports: 7 Imported by: 0

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 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

	// 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

	// Name for this circuit breaker, mostly used as a prefix to disambiguate logs when multiple cb are used.
	Name string

	// 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 defined by metricsbp.SysStatsTickerInterval.
	EmitStatusMetrics bool

	// Logger is the logger to be called when the breaker changes states.
	Logger log.Wrapper

	// 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

	// 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

	// Timeout is the duration of the 'Open' state. After an 'Open' timeout duration has passed, the breaker enters 'half-open' state.
	Timeout time.Duration
}

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. Creates a new goroutine to emit breaker state metrics if EmitStatusMetrics is set to true. This goroutine is stopped when metricsbp.M.Ctx() is done().

func (FailureRatioBreaker) ThriftMiddleware

func (cb FailureRatioBreaker) ThriftMiddleware(next thrift.TClient) thrift.TClient

ThriftMiddleware is a thrift.ClientMiddleware that handles circuit breaking.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL