Documentation ¶
Index ¶
- func CloserFactory(conf CloserConfig) func() circuit.OpenToClosed
- type Closer
- func (c *Closer) Allow(now time.Time) bool
- func (c *Closer) Closed(now time.Time)
- func (c *Closer) ErrBadRequest(now time.Time, duration time.Duration)
- func (c *Closer) ErrConcurrencyLimitReject(now time.Time)
- func (c *Closer) ErrFailure(now time.Time, duration time.Duration)
- func (c *Closer) ErrInterrupt(now time.Time, duration time.Duration)
- func (c *Closer) ErrShortCircuit(now time.Time)
- func (c *Closer) ErrTimeout(now time.Time, duration time.Duration)
- func (c *Closer) Opened(now time.Time)
- func (c *Closer) ShouldClose(now time.Time) bool
- func (c *Closer) Success(now time.Time, duration time.Duration)
- type CloserConfig
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 ¶
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) ErrBadRequest ¶
ErrBadRequest is ignored and exists only to satisfy the closer interface.
func (*Closer) ErrConcurrencyLimitReject ¶
ErrConcurrencyLimitReject is ignored and exists only to satisfy the closer interface.
func (*Closer) ErrFailure ¶
ErrFailure sends the rater a failure message.
func (*Closer) ErrInterrupt ¶
ErrInterrupt is ignored and exists only to satisfy the closer interface.
func (*Closer) ErrShortCircuit ¶
ErrShortCircuit is ignored and exists only to satisfy the closer interface.
func (*Closer) ErrTimeout ¶
ErrTimeout sends the rater a failure message.
func (*Closer) ShouldClose ¶
ShouldClose returns true if the ratecloser has been successful for CloseOnHappyDuration amount of time.
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.