circuitbreaker

package
v0.1.17 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StateOpen rejects requests according to the calculated drop ratio.
	StateOpen int32 = iota
	// StateClosed allows requests while the rolling failure ratio is healthy.
	StateClosed
)

Variables

View Source
var ErrNotAllowed = errors.New("circuitbreaker: not allowed for circuit open")

ErrNotAllowed is returned when the circuit breaker is open.

Functions

This section is empty.

Types

type Breaker

type Breaker struct {
	// contains filtered or unexported fields
}

Breaker is an SRE-style circuit breaker.

func (*Breaker) Allow

func (b *Breaker) Allow() error

Allow reports whether the request can pass the breaker.

func (*Breaker) MarkFailed

func (b *Breaker) MarkFailed()

MarkFailed records a failed request.

func (*Breaker) MarkSuccess

func (b *Breaker) MarkSuccess()

MarkSuccess records a successful request.

type CircuitBreaker

type CircuitBreaker interface {
	Allow() error
	MarkSuccess()
	MarkFailed()
}

CircuitBreaker is a circuit breaker.

func NewBreaker

func NewBreaker(opts ...Option) CircuitBreaker

NewBreaker returns an SRE circuit breaker.

type Option

type Option func(*options)

Option configures the SRE circuit breaker.

func WithBucket

func WithBucket(b int) Option

WithBucket sets the number of buckets in the rolling window.

func WithFailureRatio

func WithFailureRatio(ratio float64) Option

WithFailureRatio sets the failure ratio threshold that starts rejection.

func WithRequest

func WithRequest(r int64) Option

WithRequest sets the minimum request count before rejection starts.

func WithWindow

func WithWindow(d time.Duration) Option

WithWindow sets the rolling statistical window.

Jump to

Keyboard shortcuts

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