rolling

package
v4.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: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package rolling contains a MetricsCollector that tracks in memory rolling stats about a circuit.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FallbackStats

type FallbackStats struct {
	Successes                  faststats.RollingCounter
	ErrConcurrencyLimitRejects faststats.RollingCounter
	ErrFailures                faststats.RollingCounter
}

FallbackStats tracks fallback metrics in rolling buckets

func FindFallbackMetrics

func FindFallbackMetrics(c *circuit.Circuit) *FallbackStats

FindFallbackMetrics searches a circuit for the previously stored fallback stats. Returns nil if never set.

func (*FallbackStats) ErrConcurrencyLimitReject

func (r *FallbackStats) ErrConcurrencyLimitReject(_ context.Context, now time.Time)

ErrConcurrencyLimitReject increments the ErrConcurrencyLimitReject bucket

func (*FallbackStats) ErrFailure

func (r *FallbackStats) ErrFailure(_ context.Context, now time.Time, _ time.Duration)

ErrFailure increments the ErrFailure bucket

func (*FallbackStats) SetConfigNotThreadSafe

func (r *FallbackStats) SetConfigNotThreadSafe(config FallbackStatsConfig)

SetConfigNotThreadSafe sets the configuration for fallback stats. Unset (zero) or negative values are replaced with defaults. Like RunStats.SetConfigNotThreadSafe, it is only for use before the stats are shared: calling it while the FallbackStats is in use may corrupt state or crash, not merely race.

func (*FallbackStats) Success

func (r *FallbackStats) Success(_ context.Context, now time.Time, _ time.Duration)

Success increments the Success bucket

func (*FallbackStats) Var

func (r *FallbackStats) Var() expvar.Var

Var allows FallbackStats on expvar

type FallbackStatsConfig

type FallbackStatsConfig struct {
	// Rolling Stats size is https://github.com/Netflix/Hystrix/wiki/Configuration#metricsrollingstatstimeinmilliseconds
	RollingStatsDuration time.Duration
	// Now should simulate time.Now
	Now func() time.Time
	// RollingStatsNumBuckets is https://github.com/Netflix/Hystrix/wiki/Configuration#metricsrollingstatsnumbuckets
	RollingStatsNumBuckets int
}

FallbackStatsConfig configures how to track fallback stats

func (*FallbackStatsConfig) Merge

func (r *FallbackStatsConfig) Merge(other FallbackStatsConfig)

Merge this config with another

type RunStats

type RunStats struct {
	Successes                  faststats.RollingCounter
	ErrConcurrencyLimitRejects faststats.RollingCounter
	ErrFailures                faststats.RollingCounter
	ErrShortCircuits           faststats.RollingCounter
	ErrTimeouts                faststats.RollingCounter
	ErrBadRequests             faststats.RollingCounter
	ErrInterrupts              faststats.RollingCounter

	// It is analogous to https://github.com/Netflix/Hystrix/wiki/Metrics-and-Monitoring#latency-percentiles-hystrixcommandrun-execution-gauge
	Latencies faststats.RollingPercentile
	// contains filtered or unexported fields
}

RunStats tracks rolling windows of callback counts

func FindCommandMetrics

func FindCommandMetrics(c *circuit.Circuit) *RunStats

FindCommandMetrics searches a circuit for the previously stored run stats. Returns nil if never set.

func (*RunStats) Config

func (r *RunStats) Config() RunStatsConfig

Config returns the current configuration

func (*RunStats) ErrBadRequest

func (r *RunStats) ErrBadRequest(_ context.Context, now time.Time, duration time.Duration)

ErrBadRequest increments the ErrBadRequest bucket

func (*RunStats) ErrConcurrencyLimitReject

func (r *RunStats) ErrConcurrencyLimitReject(_ context.Context, now time.Time)

ErrConcurrencyLimitReject increments the ErrConcurrencyLimitReject bucket

func (*RunStats) ErrFailure

func (r *RunStats) ErrFailure(_ context.Context, now time.Time, duration time.Duration)

ErrFailure increments the ErrFailure bucket

func (*RunStats) ErrInterrupt

func (r *RunStats) ErrInterrupt(_ context.Context, now time.Time, duration time.Duration)

ErrInterrupt increments the ErrInterrupts bucket

func (*RunStats) ErrShortCircuit

func (r *RunStats) ErrShortCircuit(_ context.Context, now time.Time)

ErrShortCircuit increments the ErrShortCircuit bucket

func (*RunStats) ErrTimeout

func (r *RunStats) ErrTimeout(_ context.Context, now time.Time, duration time.Duration)

ErrTimeout increments the ErrTimeout bucket

func (*RunStats) ErrorPercentage

func (r *RunStats) ErrorPercentage() float64

ErrorPercentage returns [0.0 - 1.0] what % of request are considered failing in the rolling window, as of the configured clock's now.

func (*RunStats) ErrorPercentageAt

func (r *RunStats) ErrorPercentageAt(now time.Time) float64

ErrorPercentageAt is [0.0 - 1.0] errors/legitimate

func (*RunStats) ErrorsAt

func (r *RunStats) ErrorsAt(now time.Time) int64

ErrorsAt returns the # of errors at a moment in time (errors are timeouts and failures)

func (*RunStats) LegitimateAttemptsAt

func (r *RunStats) LegitimateAttemptsAt(now time.Time) int64

LegitimateAttemptsAt returns the sum of errors and successes

func (*RunStats) SetConfigNotThreadSafe

func (r *RunStats) SetConfigNotThreadSafe(config RunStatsConfig)

SetConfigNotThreadSafe updates the RunStats buckets. Unset (zero) or negative values are replaced with defaults. It is only for use before the stats are shared: it reassigns the rolling counters (including their internal locks) wholesale, so calling it while the RunStats is in use may corrupt state or crash, not merely race.

func (*RunStats) Success

func (r *RunStats) Success(_ context.Context, now time.Time, duration time.Duration)

Success increments the Successes bucket

func (*RunStats) Var

func (r *RunStats) Var() expvar.Var

Var allows exposing RunStats on expvar

type RunStatsConfig

type RunStatsConfig struct {
	// Now should simulate time.Now
	Now func() time.Time
	// Rolling Stats size is https://github.com/Netflix/Hystrix/wiki/Configuration#metricsrollingstatstimeinmilliseconds
	RollingStatsDuration time.Duration
	// RollingStatsNumBuckets is https://github.com/Netflix/Hystrix/wiki/Configuration#metricsrollingstatsnumbuckets
	RollingStatsNumBuckets int
	// RollingPercentileDuration is https://github.com/Netflix/Hystrix/wiki/Configuration#metricsrollingpercentiletimeinmilliseconds
	RollingPercentileDuration time.Duration
	// RollingPercentileNumBuckets is https://github.com/Netflix/Hystrix/wiki/Configuration#metricsrollingpercentilenumbuckets
	RollingPercentileNumBuckets int
	// RollingPercentileBucketSize is https://github.com/Netflix/Hystrix/wiki/Configuration#metricsrollingpercentilebucketsize
	RollingPercentileBucketSize int
}

RunStatsConfig configures a RunStats

func (*RunStatsConfig) Merge

func (r *RunStatsConfig) Merge(other RunStatsConfig)

Merge this config with another

type StatFactory

type StatFactory struct {
	RunConfig      RunStatsConfig
	FallbackConfig FallbackStatsConfig
	// contains filtered or unexported fields
}

StatFactory helps the process of making stat collectors for circuit breakers

func (*StatFactory) CreateConfig

func (s *StatFactory) CreateConfig(circuitName string) circuit.Config

CreateConfig is a config factory that associates stat collection with the circuit

func (*StatFactory) FallbackStats

func (s *StatFactory) FallbackStats(circuitName string) *FallbackStats

FallbackStats returns the fallback stats for a circuit, or nil if there is none

func (*StatFactory) RunStats

func (s *StatFactory) RunStats(circuitName string) *RunStats

RunStats returns the run stats for a circuit, or nil if there is none

Jump to

Keyboard shortcuts

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