Documentation
¶
Overview ¶
Package quotas is a generated GoMock package.
Package quotas is a generated GoMock package.
Package quotas is a generated GoMock package.
Index ¶
- Constants
- Variables
- type BurstFn
- type ClusterAwareNamespaceSpecificQuotaCalculator
- type ClusterAwareQuotaCalculator
- type DelayedRequestRateLimiter
- type DynamicRateLimiterImpl
- func (d *DynamicRateLimiterImpl) Allow() bool
- func (d *DynamicRateLimiterImpl) AllowN(now time.Time, numToken int) bool
- func (d *DynamicRateLimiterImpl) Burst() int
- func (d *DynamicRateLimiterImpl) Rate() float64
- func (d *DynamicRateLimiterImpl) Refresh()
- func (d *DynamicRateLimiterImpl) Reserve() Reservation
- func (d *DynamicRateLimiterImpl) ReserveN(now time.Time, numToken int) Reservation
- func (d *DynamicRateLimiterImpl) Wait(ctx context.Context) error
- func (d *DynamicRateLimiterImpl) WaitN(ctx context.Context, numToken int) error
- type MapRequestRateLimiterImpl
- type MemberCounter
- type MockRateLimiter
- func (m *MockRateLimiter) Allow() bool
- func (m *MockRateLimiter) AllowN(now time.Time, numToken int) bool
- func (m *MockRateLimiter) Burst() int
- func (m *MockRateLimiter) EXPECT() *MockRateLimiterMockRecorder
- func (m *MockRateLimiter) Rate() float64
- func (m *MockRateLimiter) Reserve() Reservation
- func (m *MockRateLimiter) ReserveN(now time.Time, numToken int) Reservation
- func (m *MockRateLimiter) Wait(ctx context.Context) error
- func (m *MockRateLimiter) WaitN(ctx context.Context, numToken int) error
- type MockRateLimiterMockRecorder
- func (mr *MockRateLimiterMockRecorder) Allow() *gomock.Call
- func (mr *MockRateLimiterMockRecorder) AllowN(now, numToken interface{}) *gomock.Call
- func (mr *MockRateLimiterMockRecorder) Burst() *gomock.Call
- func (mr *MockRateLimiterMockRecorder) Rate() *gomock.Call
- func (mr *MockRateLimiterMockRecorder) Reserve() *gomock.Call
- func (mr *MockRateLimiterMockRecorder) ReserveN(now, numToken interface{}) *gomock.Call
- func (mr *MockRateLimiterMockRecorder) Wait(ctx interface{}) *gomock.Call
- func (mr *MockRateLimiterMockRecorder) WaitN(ctx, numToken interface{}) *gomock.Call
- type MockRequestRateLimiter
- func (m *MockRequestRateLimiter) Allow(now time.Time, request Request) bool
- func (m *MockRequestRateLimiter) EXPECT() *MockRequestRateLimiterMockRecorder
- func (m *MockRequestRateLimiter) Reserve(now time.Time, request Request) Reservation
- func (m *MockRequestRateLimiter) Wait(ctx context.Context, request Request) error
- type MockRequestRateLimiterMockRecorder
- type MockReservation
- type MockReservationMockRecorder
- func (mr *MockReservationMockRecorder) Cancel() *gomock.Call
- func (mr *MockReservationMockRecorder) CancelAt(now interface{}) *gomock.Call
- func (mr *MockReservationMockRecorder) Delay() *gomock.Call
- func (mr *MockReservationMockRecorder) DelayFrom(now interface{}) *gomock.Call
- func (mr *MockReservationMockRecorder) OK() *gomock.Call
- type MultiRateLimiterImpl
- func (rl *MultiRateLimiterImpl) Allow() bool
- func (rl *MultiRateLimiterImpl) AllowN(now time.Time, numToken int) bool
- func (rl *MultiRateLimiterImpl) Burst() int
- func (rl *MultiRateLimiterImpl) Rate() float64
- func (rl *MultiRateLimiterImpl) Reserve() Reservation
- func (rl *MultiRateLimiterImpl) ReserveN(now time.Time, numToken int) Reservation
- func (rl *MultiRateLimiterImpl) Wait(ctx context.Context) error
- func (rl *MultiRateLimiterImpl) WaitN(ctx context.Context, numToken int) error
- type MultiRequestRateLimiterImpl
- type MultiReservationImpl
- type MutableRateBurst
- type MutableRateBurstImpl
- type NoopRequestRateLimiterImpl
- type NoopReservationImpl
- type PriorityRateLimiterImpl
- type PriorityReservationImpl
- type RateBurst
- type RateBurstImpl
- type RateFn
- type RateLimiter
- type RateLimiterImpl
- func (rl *RateLimiterImpl) Allow() bool
- func (rl *RateLimiterImpl) AllowN(now time.Time, numToken int) bool
- func (rl *RateLimiterImpl) Burst() int
- func (rl *RateLimiterImpl) Rate() float64
- func (rl *RateLimiterImpl) Reserve() Reservation
- func (rl *RateLimiterImpl) ReserveN(now time.Time, numToken int) Reservation
- func (rl *RateLimiterImpl) SetBurst(burst int)
- func (rl *RateLimiterImpl) SetRate(rate float64)
- func (rl *RateLimiterImpl) SetRateBurst(rate float64, burst int)
- func (rl *RateLimiterImpl) Wait(ctx context.Context) error
- func (rl *RateLimiterImpl) WaitN(ctx context.Context, numToken int) error
- type Request
- type RequestPriorityFn
- type RequestRateLimiter
- type RequestRateLimiterAdapterImpl
- type RequestRateLimiterDelegator
- func (d *RequestRateLimiterDelegator) Allow(now time.Time, request Request) bool
- func (d *RequestRateLimiterDelegator) Reserve(now time.Time, request Request) Reservation
- func (d *RequestRateLimiterDelegator) SetRateLimiter(rl RequestRateLimiter)
- func (d *RequestRateLimiterDelegator) Wait(ctx context.Context, request Request) error
- type RequestRateLimiterFn
- type RequestRateLimiterKeyFn
- type Reservation
- type RoutingRateLimiterImpl
Constants ¶
const (
InfDuration = rate.InfDuration
)
Variables ¶
var ErrNegativeDelay = errors.New("delay cannot be negative")
Functions ¶
This section is empty.
Types ¶
type BurstFn ¶ added in v1.5.7
type BurstFn func() int
BurstFn returns an int as the burst / bucket size
type ClusterAwareNamespaceSpecificQuotaCalculator ¶ added in v1.22.0
type ClusterAwareNamespaceSpecificQuotaCalculator quotaCalculator[func(namespace string) int]
ClusterAwareNamespaceSpecificQuotaCalculator is similar to ClusterAwareQuotaCalculator, but it uses quotas that are specific to a namespace.
type ClusterAwareQuotaCalculator ¶ added in v1.22.0
type ClusterAwareQuotaCalculator quotaCalculator[func() int]
ClusterAwareQuotaCalculator calculates the available quota for the current host based on the per instance and per cluster quota. The quota could represent requests per second, total number of active requests, etc. It works by dividing the per cluster quota by the total number of instances running the same service.
type DelayedRequestRateLimiter ¶ added in v1.22.0
type DelayedRequestRateLimiter struct {
// RequestRateLimiter is the delegate that we switch to after the delay expires.
RequestRateLimiter
// contains filtered or unexported fields
}
DelayedRequestRateLimiter is a rate limiter that allows all requests without any delay for a given duration. After the delay expires, it delegates to another rate limiter. This rate limiter is useful for cases where you want to allow all requests for a given duration, e.g. during something volatile like a deployment, and then switch to another rate limiter after the duration expires.
func NewDelayedRequestRateLimiter ¶ added in v1.22.0
func NewDelayedRequestRateLimiter(
rl RequestRateLimiter,
delay time.Duration,
timeSource clock.TimeSource,
) (*DelayedRequestRateLimiter, error)
NewDelayedRequestRateLimiter returns a DelayedRequestRateLimiter that delegates to the given rate limiter after a delay. The timeSource is used to create the timer that triggers the switch. It returns an error if the given delay is negative.
type DynamicRateLimiterImpl ¶ added in v1.5.7
type DynamicRateLimiterImpl struct {
// contains filtered or unexported fields
}
DynamicRateLimiterImpl implements a dynamic config wrapper around the rate limiter
func NewDefaultIncomingRateLimiter ¶ added in v1.14.0
func NewDefaultIncomingRateLimiter(
rateFn RateFn,
) *DynamicRateLimiterImpl
NewDefaultIncomingRateLimiter returns a default rate limiter for incoming traffic
func NewDefaultOutgoingRateLimiter ¶ added in v1.14.0
func NewDefaultOutgoingRateLimiter(
rateFn RateFn,
) *DynamicRateLimiterImpl
NewDefaultOutgoingRateLimiter returns a default rate limiter for outgoing traffic
func NewDynamicRateLimiter ¶ added in v0.7.0
func NewDynamicRateLimiter(
rateBurstFn RateBurst,
refreshInterval time.Duration,
) *DynamicRateLimiterImpl
NewDynamicRateLimiter returns a rate limiter which handles dynamic config
func (*DynamicRateLimiterImpl) Allow ¶ added in v1.5.7
func (d *DynamicRateLimiterImpl) Allow() bool
Allow immediately returns with true or false indicating if a rate limit token is available or not
func (*DynamicRateLimiterImpl) AllowN ¶ added in v1.5.7
func (d *DynamicRateLimiterImpl) AllowN(now time.Time, numToken int) bool
AllowN immediately returns with true or false indicating if n rate limit token is available or not
func (*DynamicRateLimiterImpl) Burst ¶ added in v1.5.7
func (d *DynamicRateLimiterImpl) Burst() int
Burst returns the burst for this rate limiter
func (*DynamicRateLimiterImpl) Rate ¶ added in v1.5.7
func (d *DynamicRateLimiterImpl) Rate() float64
Rate returns the rate per second for this rate limiter
func (*DynamicRateLimiterImpl) Refresh ¶ added in v1.18.0
func (d *DynamicRateLimiterImpl) Refresh()
func (*DynamicRateLimiterImpl) Reserve ¶ added in v1.5.7
func (d *DynamicRateLimiterImpl) Reserve() Reservation
Reserve reserves a rate limit token
func (*DynamicRateLimiterImpl) ReserveN ¶ added in v1.5.7
func (d *DynamicRateLimiterImpl) ReserveN(now time.Time, numToken int) Reservation
ReserveN reserves n rate limit token
type MapRequestRateLimiterImpl ¶ added in v1.21.0
type MapRequestRateLimiterImpl[K comparable] struct {
sync.RWMutex
// contains filtered or unexported fields
}
MapRequestRateLimiterImpl is a generic wrapper rate limiter for a set of rate limiters identified by a key
func NewMapRequestRateLimiter ¶ added in v1.21.0
func NewMapRequestRateLimiter[K comparable](
rateLimiterGenFn RequestRateLimiterFn,
rateLimiterKeyFn RequestRateLimiterKeyFn[K],
) *MapRequestRateLimiterImpl[K]
func NewNamespaceRequestRateLimiter ¶ added in v1.21.0
func NewNamespaceRequestRateLimiter(
rateLimiterGenFn RequestRateLimiterFn,
) *MapRequestRateLimiterImpl[string]
func (*MapRequestRateLimiterImpl[_]) Allow ¶ added in v1.21.0
func (r *MapRequestRateLimiterImpl[_]) Allow(
now time.Time,
request Request,
) bool
Allow attempts to allow a request to go through. The method returns immediately with a true or false indicating if the request can make progress
type MemberCounter ¶ added in v1.22.0
type MemberCounter interface {
MemberCount() int
}
MemberCounter returns the total number of instances there are for a given service.
type MockRateLimiter ¶ added in v1.5.7
type MockRateLimiter struct {
// contains filtered or unexported fields
}
MockRateLimiter is a mock of RateLimiter interface.
func NewMockRateLimiter ¶ added in v1.5.7
func NewMockRateLimiter(ctrl *gomock.Controller) *MockRateLimiter
NewMockRateLimiter creates a new mock instance.
func (*MockRateLimiter) Allow ¶ added in v1.5.7
func (m *MockRateLimiter) Allow() bool
Allow mocks base method.
func (*MockRateLimiter) AllowN ¶ added in v1.5.7
func (m *MockRateLimiter) AllowN(now time.Time, numToken int) bool
AllowN mocks base method.
func (*MockRateLimiter) Burst ¶ added in v1.5.7
func (m *MockRateLimiter) Burst() int
Burst mocks base method.
func (*MockRateLimiter) EXPECT ¶ added in v1.5.7
func (m *MockRateLimiter) EXPECT() *MockRateLimiterMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockRateLimiter) Rate ¶ added in v1.5.7
func (m *MockRateLimiter) Rate() float64
Rate mocks base method.
func (*MockRateLimiter) Reserve ¶ added in v1.5.7
func (m *MockRateLimiter) Reserve() Reservation
Reserve mocks base method.
func (*MockRateLimiter) ReserveN ¶ added in v1.5.7
func (m *MockRateLimiter) ReserveN(now time.Time, numToken int) Reservation
ReserveN mocks base method.
type MockRateLimiterMockRecorder ¶ added in v1.5.7
type MockRateLimiterMockRecorder struct {
// contains filtered or unexported fields
}
MockRateLimiterMockRecorder is the mock recorder for MockRateLimiter.
func (*MockRateLimiterMockRecorder) Allow ¶ added in v1.5.7
func (mr *MockRateLimiterMockRecorder) Allow() *gomock.Call
Allow indicates an expected call of Allow.
func (*MockRateLimiterMockRecorder) AllowN ¶ added in v1.5.7
func (mr *MockRateLimiterMockRecorder) AllowN(now, numToken interface{}) *gomock.Call
AllowN indicates an expected call of AllowN.
func (*MockRateLimiterMockRecorder) Burst ¶ added in v1.5.7
func (mr *MockRateLimiterMockRecorder) Burst() *gomock.Call
Burst indicates an expected call of Burst.
func (*MockRateLimiterMockRecorder) Rate ¶ added in v1.5.7
func (mr *MockRateLimiterMockRecorder) Rate() *gomock.Call
Rate indicates an expected call of Rate.
func (*MockRateLimiterMockRecorder) Reserve ¶ added in v1.5.7
func (mr *MockRateLimiterMockRecorder) Reserve() *gomock.Call
Reserve indicates an expected call of Reserve.
func (*MockRateLimiterMockRecorder) ReserveN ¶ added in v1.5.7
func (mr *MockRateLimiterMockRecorder) ReserveN(now, numToken interface{}) *gomock.Call
ReserveN indicates an expected call of ReserveN.
type MockRequestRateLimiter ¶ added in v1.10.0
type MockRequestRateLimiter struct {
// contains filtered or unexported fields
}
MockRequestRateLimiter is a mock of RequestRateLimiter interface.
func NewMockRequestRateLimiter ¶ added in v1.10.0
func NewMockRequestRateLimiter(ctrl *gomock.Controller) *MockRequestRateLimiter
NewMockRequestRateLimiter creates a new mock instance.
func (*MockRequestRateLimiter) Allow ¶ added in v1.10.0
func (m *MockRequestRateLimiter) Allow(now time.Time, request Request) bool
Allow mocks base method.
func (*MockRequestRateLimiter) EXPECT ¶ added in v1.10.0
func (m *MockRequestRateLimiter) EXPECT() *MockRequestRateLimiterMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
type MockRequestRateLimiterMockRecorder ¶ added in v1.10.0
type MockRequestRateLimiterMockRecorder struct {
// contains filtered or unexported fields
}
MockRequestRateLimiterMockRecorder is the mock recorder for MockRequestRateLimiter.
func (*MockRequestRateLimiterMockRecorder) Allow ¶ added in v1.10.0
func (mr *MockRequestRateLimiterMockRecorder) Allow(now, request interface{}) *gomock.Call
Allow indicates an expected call of Allow.
type MockReservation ¶ added in v1.5.7
type MockReservation struct {
// contains filtered or unexported fields
}
MockReservation is a mock of Reservation interface.
func NewMockReservation ¶ added in v1.5.7
func NewMockReservation(ctrl *gomock.Controller) *MockReservation
NewMockReservation creates a new mock instance.
func (*MockReservation) Cancel ¶ added in v1.5.7
func (m *MockReservation) Cancel()
Cancel mocks base method.
func (*MockReservation) CancelAt ¶ added in v1.5.7
func (m *MockReservation) CancelAt(now time.Time)
CancelAt mocks base method.
func (*MockReservation) Delay ¶ added in v1.5.7
func (m *MockReservation) Delay() time.Duration
Delay mocks base method.
func (*MockReservation) DelayFrom ¶ added in v1.5.7
func (m *MockReservation) DelayFrom(now time.Time) time.Duration
DelayFrom mocks base method.
type MockReservationMockRecorder ¶ added in v1.5.7
type MockReservationMockRecorder struct {
// contains filtered or unexported fields
}
MockReservationMockRecorder is the mock recorder for MockReservation.
func (*MockReservationMockRecorder) Cancel ¶ added in v1.5.7
func (mr *MockReservationMockRecorder) Cancel() *gomock.Call
Cancel indicates an expected call of Cancel.
func (*MockReservationMockRecorder) CancelAt ¶ added in v1.5.7
func (mr *MockReservationMockRecorder) CancelAt(now interface{}) *gomock.Call
CancelAt indicates an expected call of CancelAt.
func (*MockReservationMockRecorder) Delay ¶ added in v1.5.7
func (mr *MockReservationMockRecorder) Delay() *gomock.Call
Delay indicates an expected call of Delay.
type MultiRateLimiterImpl ¶ added in v1.10.0
type MultiRateLimiterImpl struct {
// contains filtered or unexported fields
}
MultiRateLimiterImpl is a wrapper around the limiter interface
func NewMultiRateLimiter ¶ added in v1.10.0
func NewMultiRateLimiter(
rateLimiters []RateLimiter,
) *MultiRateLimiterImpl
NewMultiRateLimiter returns a new rate limiter that have multiple stage
func (*MultiRateLimiterImpl) Allow ¶ added in v1.10.0
func (rl *MultiRateLimiterImpl) Allow() bool
Allow immediately returns with true or false indicating if a rate limit token is available or not
func (*MultiRateLimiterImpl) AllowN ¶ added in v1.10.0
func (rl *MultiRateLimiterImpl) AllowN(now time.Time, numToken int) bool
AllowN immediately returns with true or false indicating if n rate limit token is available or not
func (*MultiRateLimiterImpl) Burst ¶ added in v1.10.0
func (rl *MultiRateLimiterImpl) Burst() int
Burst returns the burst for this rate limiter
func (*MultiRateLimiterImpl) Rate ¶ added in v1.10.0
func (rl *MultiRateLimiterImpl) Rate() float64
Rate returns the rate per second for this rate limiter
func (*MultiRateLimiterImpl) Reserve ¶ added in v1.10.0
func (rl *MultiRateLimiterImpl) Reserve() Reservation
Reserve returns a Reservation that indicates how long the caller must wait before event happen.
func (*MultiRateLimiterImpl) ReserveN ¶ added in v1.10.0
func (rl *MultiRateLimiterImpl) ReserveN(now time.Time, numToken int) Reservation
ReserveN returns a Reservation that indicates how long the caller must wait before event happen.
type MultiRequestRateLimiterImpl ¶ added in v1.17.3
type MultiRequestRateLimiterImpl struct {
// contains filtered or unexported fields
}
func NewMultiRequestRateLimiter ¶ added in v1.17.3
func NewMultiRequestRateLimiter(
requestRateLimiters ...RequestRateLimiter,
) *MultiRequestRateLimiterImpl
func (*MultiRequestRateLimiterImpl) Allow ¶ added in v1.17.3
func (rl *MultiRequestRateLimiterImpl) Allow(now time.Time, request Request) bool
type MultiReservationImpl ¶ added in v1.10.0
type MultiReservationImpl struct {
// contains filtered or unexported fields
}
func NewMultiReservation ¶ added in v1.10.0
func NewMultiReservation(
ok bool,
reservations []Reservation,
) *MultiReservationImpl
func (*MultiReservationImpl) Cancel ¶ added in v1.10.0
func (r *MultiReservationImpl) Cancel()
Cancel indicates that the reservation holder will not perform the reserved action and reverses the effects of this Reservation on the rate limit as much as possible
func (*MultiReservationImpl) CancelAt ¶ added in v1.10.0
func (r *MultiReservationImpl) CancelAt(now time.Time)
CancelAt indicates that the reservation holder will not perform the reserved action and reverses the effects of this Reservation on the rate limit as much as possible
func (*MultiReservationImpl) Delay ¶ added in v1.10.0
func (r *MultiReservationImpl) Delay() time.Duration
Delay returns the duration for which the reservation holder must wait before taking the reserved action. Zero duration means act immediately.
type MutableRateBurst ¶ added in v1.14.0
type MutableRateBurst interface {
SetRate(rate float64)
SetBurst(burst int)
RateBurst
}
type MutableRateBurstImpl ¶ added in v1.14.0
type MutableRateBurstImpl struct {
// contains filtered or unexported fields
}
MutableRateBurstImpl stores the dynamic rate & burst for rate limiter
func NewMutableRateBurst ¶ added in v1.14.0
func NewMutableRateBurst(
rate float64,
burst int,
) *MutableRateBurstImpl
type NoopRequestRateLimiterImpl ¶ added in v1.19.0
type NoopRequestRateLimiterImpl struct{}
NoopRequestRateLimiterImpl is a no-op implementation for RequestRateLimiter
func (*NoopRequestRateLimiterImpl) Allow ¶ added in v1.19.0
func (r *NoopRequestRateLimiterImpl) Allow(
_ time.Time,
_ Request,
) bool
type NoopReservationImpl ¶ added in v1.10.0
type NoopReservationImpl struct{}
func (*NoopReservationImpl) Cancel ¶ added in v1.10.0
func (r *NoopReservationImpl) Cancel()
Cancel indicates that the reservation holder will not perform the reserved action and reverses the effects of this Reservation on the rate limit as much as possible
func (*NoopReservationImpl) CancelAt ¶ added in v1.10.0
func (r *NoopReservationImpl) CancelAt(_ time.Time)
CancelAt indicates that the reservation holder will not perform the reserved action and reverses the effects of this Reservation on the rate limit as much as possible
func (*NoopReservationImpl) Delay ¶ added in v1.10.0
func (r *NoopReservationImpl) Delay() time.Duration
Delay returns the duration for which the reservation holder must wait before taking the reserved action. Zero duration means act immediately.
type PriorityRateLimiterImpl ¶ added in v1.10.0
type PriorityRateLimiterImpl struct {
// contains filtered or unexported fields
}
PriorityRateLimiterImpl is a wrapper around the golang rate limiter
func NewPriorityRateLimiter ¶ added in v1.10.0
func NewPriorityRateLimiter(
requestPriorityFn RequestPriorityFn,
priorityToRateLimiters map[int]RequestRateLimiter,
) *PriorityRateLimiterImpl
NewPriorityRateLimiter returns a new rate limiter that can handle dynamic configuration updates
func (*PriorityRateLimiterImpl) Allow ¶ added in v1.10.0
func (p *PriorityRateLimiterImpl) Allow(
now time.Time,
request Request,
) bool
type PriorityReservationImpl ¶ added in v1.10.0
type PriorityReservationImpl struct {
// contains filtered or unexported fields
}
func NewPriorityReservation ¶ added in v1.10.0
func NewPriorityReservation(
decidingReservation Reservation,
otherReservations []Reservation,
) *PriorityReservationImpl
func (*PriorityReservationImpl) Cancel ¶ added in v1.10.0
func (r *PriorityReservationImpl) Cancel()
Cancel indicates that the reservation holder will not perform the reserved action and reverses the effects of this Reservation on the rate limit as much as possible
func (*PriorityReservationImpl) CancelAt ¶ added in v1.10.0
func (r *PriorityReservationImpl) CancelAt(now time.Time)
CancelAt indicates that the reservation holder will not perform the reserved action and reverses the effects of this Reservation on the rate limit as much as possible
func (*PriorityReservationImpl) Delay ¶ added in v1.10.0
func (r *PriorityReservationImpl) Delay() time.Duration
Delay returns the duration for which the reservation holder must wait before taking the reserved action. Zero duration means act immediately.
type RateBurst ¶ added in v1.14.0
type RateBurst interface {
Rate() float64
Burst() int
}
RateBurst returns rate & burst for rate limiter
type RateBurstImpl ¶ added in v1.14.0
type RateBurstImpl struct {
// contains filtered or unexported fields
}
func NewDefaultIncomingRateBurst ¶ added in v1.14.0
func NewDefaultIncomingRateBurst(
rateFn RateFn,
) *RateBurstImpl
func NewDefaultOutgoingRateBurst ¶ added in v1.14.0
func NewDefaultOutgoingRateBurst(
rateFn RateFn,
) *RateBurstImpl
func NewRateBurst ¶ added in v1.14.0
func NewRateBurst(
rateFn RateFn,
burstFn BurstFn,
) *RateBurstImpl
type RateLimiter ¶ added in v0.7.0
type RateLimiter interface {
// Allow attempts to allow a request to go through. The method returns
// immediately with a true or false indicating if the request can make
// progress
Allow() bool
// AllowN attempts to allow a request to go through. The method returns
// immediately with a true or false indicating if the request can make
// progress
AllowN(now time.Time, numToken int) bool
// Reserve returns a Reservation that indicates how long the caller
// must wait before event happen.
Reserve() Reservation
// ReserveN returns a Reservation that indicates how long the caller
// must wait before event happen.
ReserveN(now time.Time, numToken int) Reservation
// Wait waits till the deadline for a rate limit token to allow the request
// to go through.
Wait(ctx context.Context) error
// WaitN waits till the deadline for n rate limit token to allow the request
// to go through.
WaitN(ctx context.Context, numToken int) error
// Rate returns the rate per second for this rate limiter
Rate() float64
// Burst returns the burst for this rate limiter
Burst() int
}
RateLimiter corresponds to basic rate limiting functionality.
type RateLimiterImpl ¶ added in v1.5.7
type RateLimiterImpl struct {
sync.RWMutex
// contains filtered or unexported fields
}
RateLimiterImpl is a wrapper around the golang rate limiter
func NewRateLimiter ¶ added in v0.7.0
func NewRateLimiter(newRate float64, newBurst int) *RateLimiterImpl
NewRateLimiter returns a new rate limiter that can handle dynamic configuration updates
func (*RateLimiterImpl) Allow ¶ added in v1.5.7
func (rl *RateLimiterImpl) Allow() bool
Allow immediately returns with true or false indicating if a rate limit token is available or not
func (*RateLimiterImpl) AllowN ¶ added in v1.5.7
func (rl *RateLimiterImpl) AllowN(now time.Time, numToken int) bool
AllowN immediately returns with true or false indicating if n rate limit token is available or not
func (*RateLimiterImpl) Burst ¶ added in v1.5.7
func (rl *RateLimiterImpl) Burst() int
Burst returns the burst for this rate limiter
func (*RateLimiterImpl) Rate ¶ added in v1.5.7
func (rl *RateLimiterImpl) Rate() float64
Rate returns the rate per second for this rate limiter
func (*RateLimiterImpl) Reserve ¶ added in v1.5.7
func (rl *RateLimiterImpl) Reserve() Reservation
Reserve reserves a rate limit token
func (*RateLimiterImpl) ReserveN ¶ added in v1.5.7
func (rl *RateLimiterImpl) ReserveN(now time.Time, numToken int) Reservation
ReserveN reserves n rate limit token
func (*RateLimiterImpl) SetBurst ¶ added in v1.5.7
func (rl *RateLimiterImpl) SetBurst(burst int)
SetBurst set the burst of the rate limiter
func (*RateLimiterImpl) SetRate ¶ added in v1.5.7
func (rl *RateLimiterImpl) SetRate(rate float64)
SetRate set the rate of the rate limiter
func (*RateLimiterImpl) SetRateBurst ¶ added in v1.5.7
func (rl *RateLimiterImpl) SetRateBurst(rate float64, burst int)
SetRateBurst set the rate & burst of the rate limiter
type Request ¶ added in v1.10.0
type Request struct {
API string
Token int
Caller string
CallerType string
CallerSegment int32
Initiation string
}
func NewRequest ¶ added in v1.10.0
func NewRequest(
api string,
token int,
caller string,
callerType string,
callerSegment int32,
initiation string,
) Request
type RequestPriorityFn ¶ added in v1.17.2
type RequestPriorityFn func(req Request) int
RequestPriorityFn returns a priority for the given Request
type RequestRateLimiter ¶ added in v1.10.0
type RequestRateLimiter interface {
// Allow attempts to allow a request to go through. The method returns
// immediately with a true or false indicating if the request can make
// progress
Allow(now time.Time, request Request) bool
// Reserve returns a Reservation that indicates how long the caller
// must wait before event happen.
Reserve(now time.Time, request Request) Reservation
// Wait waits till the deadline for a rate limit token to allow the request
// to go through.
Wait(ctx context.Context, request Request) error
}
RequestRateLimiter corresponds to basic rate limiting functionality.
var NoopRequestRateLimiter RequestRateLimiter = &NoopRequestRateLimiterImpl{}
func NewRequestRateLimiterAdapter ¶ added in v1.19.0
func NewRequestRateLimiterAdapter(
rateLimiter RateLimiter,
) RequestRateLimiter
type RequestRateLimiterAdapterImpl ¶ added in v1.19.0
type RequestRateLimiterAdapterImpl struct {
// contains filtered or unexported fields
}
func (*RequestRateLimiterAdapterImpl) Allow ¶ added in v1.19.0
func (r *RequestRateLimiterAdapterImpl) Allow(
now time.Time,
request Request,
) bool
type RequestRateLimiterDelegator ¶ added in v1.22.0
type RequestRateLimiterDelegator struct {
// contains filtered or unexported fields
}
RequestRateLimiterDelegator is a request rate limiter that delegates to another rate limiter. The delegate can be changed at runtime by calling SetRateLimiter. This rate limiter is useful for cases where you want to substitute one rate limiter implementation for another at runtime. All methods of this type are thread-safe.
func (*RequestRateLimiterDelegator) Allow ¶ added in v1.22.0
func (d *RequestRateLimiterDelegator) Allow(now time.Time, request Request) bool
func (*RequestRateLimiterDelegator) Reserve ¶ added in v1.22.0
func (d *RequestRateLimiterDelegator) Reserve(now time.Time, request Request) Reservation
func (*RequestRateLimiterDelegator) SetRateLimiter ¶ added in v1.22.0
func (d *RequestRateLimiterDelegator) SetRateLimiter(rl RequestRateLimiter)
SetRateLimiter sets the rate limiter to delegate to.
type RequestRateLimiterFn ¶ added in v1.10.0
type RequestRateLimiterFn func(req Request) RequestRateLimiter
RequestRateLimiterFn returns generate a namespace specific rate limiter
type RequestRateLimiterKeyFn ¶ added in v1.21.0
type RequestRateLimiterKeyFn[K comparable] func(req Request) K
RequestRateLimiterKeyFn extracts the map key from the request
type Reservation ¶ added in v1.5.7
type Reservation interface {
// OK returns whether the limiter can provide the requested number of tokens
OK() bool
// Cancel indicates that the reservation holder will not perform the reserved action
// and reverses the effects of this Reservation on the rate limit as much as possible
Cancel()
// CancelAt indicates that the reservation holder will not perform the reserved action
// and reverses the effects of this Reservation on the rate limit as much as possible
CancelAt(now time.Time)
// Delay returns the duration for which the reservation holder must wait
// before taking the reserved action. Zero duration means act immediately.
Delay() time.Duration
// DelayFrom returns the duration for which the reservation holder must wait
// before taking the reserved action. Zero duration means act immediately.
DelayFrom(now time.Time) time.Duration
}
Reservation holds information about events that are permitted by a Limiter to happen after a delay
var NoopReservation Reservation = &NoopReservationImpl{}
type RoutingRateLimiterImpl ¶ added in v1.10.0
type RoutingRateLimiterImpl struct {
// contains filtered or unexported fields
}
RoutingRateLimiterImpl is a rate limiter special built for multi-tenancy
func NewRoutingRateLimiter ¶ added in v1.10.0
func NewRoutingRateLimiter(
apiToRateLimiter map[string]RequestRateLimiter,
) *RoutingRateLimiterImpl
func (*RoutingRateLimiterImpl) Allow ¶ added in v1.10.0
func (r *RoutingRateLimiterImpl) Allow(
now time.Time,
request Request,
) bool
Allow attempts to allow a request to go through. The method returns immediately with a true or false indicating if the request can make progress
Source Files
¶
- cluster_aware_quota_calculator.go
- delayed_request_rate_limiter.go
- dynamic.go
- dynamic_rate_limiter_impl.go
- map_request_rate_limiter_impl.go
- multi_rate_limiter_impl.go
- multi_request_rate_limiter_impl.go
- multi_reservation_impl.go
- noop_request_rate_limiter_impl.go
- noop_reservation_impl.go
- priority_rate_limiter_impl.go
- priority_reservation_impl.go
- rate_limiter.go
- rate_limiter_impl.go
- rate_limiter_mock.go
- request.go
- request_rate_limiter.go
- request_rate_limiter_adapter_impl.go
- request_rate_limiter_delegator.go
- request_rate_limiter_mock.go
- reservation.go
- reservation_mock.go
- routing_rate_limiter_impl.go