responsetimeslo

package
v4.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package responsetimeslo contains a MetricsCollector that tracks a SLO metric for circuits.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

type Collector interface {
	// Failed the SLO
	Failed()
	// Passed the SLO (responded correctly fast enough)
	Passed()
}

Collector can collect metrics about the happy SLO of a request.

type Config

type Config struct {
	// MaximumHealthyTime is the maximum amount of time a request can take and still be considered healthy
	MaximumHealthyTime time.Duration
}

Config controls how SLO is tracked by default for a Tracker

func (*Config) Merge

func (c *Config) Merge(other Config)

Merge this configuration with another, changing any values that are non zero into other's value

type Factory

type Factory struct {
	Config                Config
	ConfigConstructor     []func(circuitName string) Config
	CollectorConstructors []func(circuitName string) Collector
}

Factory creates SLO monitors for a circuit

Example

This example creates a SLO tracker that counts failures at less than 20 ms. You will need to provide your own Collectors.

sloTrackerFactory := responsetimeslo.Factory{
	Config: responsetimeslo.Config{
		// Consider requests faster than 20 ms as passing
		MaximumHealthyTime: time.Millisecond * 20,
	},
	// Pass in your collector here: for example, statsd
	CollectorConstructors: nil,
}
h := circuit.Manager{
	DefaultCircuitProperties: []circuit.CommandPropertiesConstructor{sloTrackerFactory.CommandProperties},
}
h.MustCreateCircuit("circuit-with-slo")
Output:

func (*Factory) CommandProperties

func (r *Factory) CommandProperties(circuitName string) circuit.Config

CommandProperties appends SLO tracking to a circuit

type Tracker

type Tracker struct {
	MaximumHealthyTime faststats.AtomicInt64
	MeetsSLOCount      faststats.AtomicInt64
	FailsSLOCount      faststats.AtomicInt64
	Collectors         []Collector
	// contains filtered or unexported fields
}

Tracker sets up a response time SLO that has a reasonable meaning for hystrix. Use it for an SLO like "99% of requests should respond correctly within 300 ms".

Define a maximum time that a healthy request is allowed to take. This should be less than the maximum "break" point of the circuit. Only Successful requests <= that time are counted as healthy.

Requests that are interrupted, or have bad input, are not considered healthy or unhealthy. It's like they don't happen. All other types of errors are blamed on the down stream service, or the Run method's request time. They will count as failing the SLA.

func (*Tracker) Config

func (r *Tracker) Config() Config

Config returns the tracker's config

func (*Tracker) ErrBadRequest

func (r *Tracker) ErrBadRequest(_ context.Context, _ time.Time, _ time.Duration)

ErrBadRequest is ignored

func (*Tracker) ErrConcurrencyLimitReject

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

ErrConcurrencyLimitReject is always a failure

func (*Tracker) ErrFailure

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

ErrFailure is always a failure

func (*Tracker) ErrInterrupt

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

ErrInterrupt is only a failure if healthy time has passed

func (*Tracker) ErrShortCircuit

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

ErrShortCircuit is always a failure

func (*Tracker) ErrTimeout

func (r *Tracker) ErrTimeout(_ context.Context, _ time.Time, _ time.Duration)

ErrTimeout is always a failure

func (*Tracker) SetConfigThreadSafe

func (r *Tracker) SetConfigThreadSafe(config Config)

SetConfigThreadSafe updates the configuration stored in the tracker

func (*Tracker) Success

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

Success adds a healthy check if duration <= maximum healthy time

func (*Tracker) Var

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

Var returns something to pass to expvar

Jump to

Keyboard shortcuts

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