Help us shape the future of Go! Take the 2026 Go Developer Survey

circuitbreaker

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultFlushInterval = defaultFlushInterval
)

Functions

This section is empty.

Types

type CircuitBreaker

type CircuitBreaker interface {
	// Name returns CircuitBreaker name
	Name() string

	// State returns CircuitBreaker State
	State() State

	// Metric returns CircuitBreaker metric
	Metric() TimeBucketMetric
}

type Manager

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

func NewManager

func NewManager(opts ...Option) *Manager

func (*Manager) Flush

func (m *Manager) Flush(ctx context.Context) error

func (*Manager) GetCircuitBreaker

func (m *Manager) GetCircuitBreaker(ctx context.Context, id string) (CircuitBreaker, error)

func (*Manager) Record

func (m *Manager) Record(time time.Time, id string, event metrics.Event)

func (*Manager) Start

func (m *Manager) Start()

func (*Manager) Stop

func (m *Manager) Stop(ctx context.Context) error

type Option

type Option func(m *Manager)

func WithEnabled

func WithEnabled(enabled bool) Option

func WithFailureRateThreshold

func WithFailureRateThreshold(failureRateThreshold int) Option

func WithFlushInterval

func WithFlushInterval(flushInterval time.Duration) Option

func WithMinimumRequestThreshold

func WithMinimumRequestThreshold(minimumRequestThreshold int) Option

func WithNowFunc

func WithNowFunc(now func() time.Time) Option

func WithRedisClient

func WithRedisClient(client *redis.Client) Option

func WithTimeWindowSize

func WithTimeWindowSize(seconds int) Option

type Recorder

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

func NewRecorder

func NewRecorder(size int64) *Recorder

func (*Recorder) Aggregate

func (r *Recorder) Aggregate(unit Unit, from, to int64) []TimeBucketMetric

func (*Recorder) LastSync

func (r *Recorder) LastSync() int64

func (*Recorder) Record

func (r *Recorder) Record(timestamp int64, event metrics.Event)

func (*Recorder) SetLastSync

func (r *Recorder) SetLastSync(ts int64)

type State

type State string
const (
	StateClosed   State = "CLOSED"
	StateHalfOpen State = "HALF_OPEN"
	StateOpen     State = "OPEN"
)

type TimeBucketMetric

type TimeBucketMetric struct {
	Start   int64 `json:"start"`
	Until   int64 `json:"until"`
	Success int64 `json:"success"`
	Error   int64 `json:"error"`
}

TimeBucketMetric represents aggregated metrics over the time interval [Start, Until).

func (TimeBucketMetric) FailureRate

func (m TimeBucketMetric) FailureRate() float64

func (TimeBucketMetric) TotalRequest

func (m TimeBucketMetric) TotalRequest() int64

type Unit

type Unit int64
const (
	Minute Unit = 60
	Hour        = 60 * Minute
)

func (Unit) Seconds

func (u Unit) Seconds() int64

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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