breaker

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package breaker implements the shard-level circuit breaker: a rolling count-based window of request outcomes, the CLOSED → OPEN → HALF-OPEN state machine, and half-open probe accounting. Network and hard errors count toward opening the breaker; OK and soft outcomes do not.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Breaker

type Breaker interface {
	// Allow reports whether a request may be dispatched. In half-open
	// state the first GetBreakerProbes() requests become the probes;
	// everything else is fast-failed, like in the open state.
	Allow() bool
	// Record feeds a dispatched request's outcome into the window.
	// Fast-failed requests must not be recorded.
	Record(o Outcome)
	State() State
	// OnTransition registers a callback invoked (outside the lock) on
	// every state change, for logging and transition counters.
	OnTransition(func(from, to State))
}

Breaker is one shard's circuit breaker.

func NewShardBreaker

func NewShardBreaker(cfg Config) Breaker

NewShardBreaker returns a breaker with an empty window in the closed state.

type Config

type Config interface {
	GetBreakerErrorThreshold() float64
	GetBreakerWindow() int
	GetBreakerOpenDuration() time.Duration
	GetBreakerProbes() int
}

Config is the layer-A interface the breaker consumes, read on the fly.

type Outcome

type Outcome uint8

Outcome classifies a completed request.

const (
	OutcomeOK Outcome = iota
	OutcomeSoft
	OutcomeHard
	OutcomeNetwork
)

func (Outcome) IsError

func (o Outcome) IsError() bool

IsError reports whether the outcome counts toward the breaker (network and hard errors do; OK and soft do not).

type State

type State int32

State is the breaker state, exported as a gauge (0/1/2).

const (
	Closed State = iota
	Open
	HalfOpen
)

func (State) String

func (s State) String() string

Jump to

Keyboard shortcuts

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