ratecloser

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloserFactory

func CloserFactory(conf CloserConfig) func() circuit.OpenToClosed

CloserFactory is injectable into a ratecloser's configuration to create a factory of rate limit closers for a ratecloser.

Example
// Tell your circuit manager to use the rate limited closer
m := circuit.Manager{
	DefaultCircuitProperties: []circuit.CommandPropertiesConstructor{
		func(_ string) circuit.Config {
			return circuit.Config{
				General: circuit.GeneralConfig{
					OpenToClosedFactory: CloserFactory(CloserConfig{
						CloseOnHappyDuration: time.Second * 10,
					}),
				},
			}
		},
	},
}
// Make circuit from manager
c := m.MustCreateCircuit("example_circuit")
// The closer should be a closer of this type
_ = c.OpenToClose.(*Closer)
Output:

Types

type Closer

type Closer struct {
	// Rater is the rate limiter of this closer
	Rater aimdcloser.RateLimiter
	// CloseOnHappyDuration is how long we should see zero failing requests before we close the ratecloser.
	CloseOnHappyDuration time.Duration
	// contains filtered or unexported fields
}

Closer is a circuit closer that allows requests according to a rate limiter.

func (*Closer) Allow

func (c *Closer) Allow(now time.Time) bool

Allow attempts to get a reservation from the rater. If we are unable to reserve a value, we count this as a failure for the rater.

func (*Closer) Closed

func (c *Closer) Closed(now time.Time)

Closed resets the rater

func (*Closer) ErrBadRequest

func (c *Closer) ErrBadRequest(now time.Time, duration time.Duration)

ErrBadRequest is ignored and exists only to satisfy the closer interface.

func (*Closer) ErrConcurrencyLimitReject

func (c *Closer) ErrConcurrencyLimitReject(now time.Time)

ErrConcurrencyLimitReject is ignored and exists only to satisfy the closer interface.

func (*Closer) ErrFailure

func (c *Closer) ErrFailure(now time.Time, duration time.Duration)

ErrFailure sends the rater a failure message.

func (*Closer) ErrInterrupt

func (c *Closer) ErrInterrupt(now time.Time, duration time.Duration)

ErrInterrupt is ignored and exists only to satisfy the closer interface.

func (*Closer) ErrShortCircuit

func (c *Closer) ErrShortCircuit(now time.Time)

ErrShortCircuit is ignored and exists only to satisfy the closer interface.

func (*Closer) ErrTimeout

func (c *Closer) ErrTimeout(now time.Time, duration time.Duration)

ErrTimeout sends the rater a failure message.

func (*Closer) Opened

func (c *Closer) Opened(now time.Time)

Opened resets the rater

func (*Closer) ShouldClose

func (c *Closer) ShouldClose(now time.Time) bool

ShouldClose returns true if the ratecloser has been successful for CloseOnHappyDuration amount of time.

func (*Closer) Success

func (c *Closer) Success(now time.Time, duration time.Duration)

Success sends the rater a success message.

type CloserConfig

type CloserConfig struct {
	// RateLimiter constructs new rate limiters for circuits.  We default to a reasonable AIMD configuration.
	// That configuration happens to be AIMDConstructor(.1, .5, float64(time.Microsecond/time.Second), 10) right now.
	RateLimiter func() aimdcloser.RateLimiter
	// CloseOnHappyDuration gives a duration that passing requests cause the ratecloser to close.
	// We default to a reasonable short value.  It happens to be 10 seconds right now.
	CloseOnHappyDuration time.Duration
}

OpenerConfig configures defaults for Closer.

Jump to

Keyboard shortcuts

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