quotas

package
v1.9.3 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: MIT Imports: 9 Imported by: 2

Documentation

Overview

Package quotas is a generated GoMock package.

Index

Constants

View Source
const (
	InfDuration = rate.InfDuration
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BurstFn added in v1.5.7

type BurstFn func() int

BurstFn returns a int as the RPS

type DynamicBurst added in v1.5.7

type DynamicBurst interface {
	Load() int
	Store(burst int)
	BurstFn() BurstFn
}

type DynamicBurstImpl added in v1.5.7

type DynamicBurstImpl struct {
	// contains filtered or unexported fields
}

DynamicBurstImpl stores the dynamic burst for rate limiter

func NewDynamicBurst added in v1.5.7

func NewDynamicBurst(burst int) *DynamicBurstImpl

func (*DynamicBurstImpl) BurstFn added in v1.5.7

func (d *DynamicBurstImpl) BurstFn() BurstFn

func (*DynamicBurstImpl) Load added in v1.5.7

func (d *DynamicBurstImpl) Load() int

func (*DynamicBurstImpl) Store added in v1.5.7

func (d *DynamicBurstImpl) Store(burst int)

type DynamicRate added in v1.5.7

type DynamicRate interface {
	Load() float64
	Store(rate float64)
	RateFn() RateFn
}

type DynamicRateImpl added in v1.5.7

type DynamicRateImpl struct {
	// contains filtered or unexported fields
}

DynamicRateImpl stores the dynamic rate per second for rate limiter

func NewDynamicRate added in v1.5.7

func NewDynamicRate(rate float64) *DynamicRateImpl

func (*DynamicRateImpl) Load added in v1.5.7

func (d *DynamicRateImpl) Load() float64

func (*DynamicRateImpl) RateFn added in v1.5.7

func (d *DynamicRateImpl) RateFn() RateFn

func (*DynamicRateImpl) Store added in v1.5.7

func (d *DynamicRateImpl) Store(rate float64)

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 NewDefaultIncomingDynamicRateLimiter added in v1.5.7

func NewDefaultIncomingDynamicRateLimiter(
	rateFn RateFn,
) *DynamicRateLimiterImpl

NewDefaultIncomingDynamicRateLimiter returns a default rate limiter for incoming traffic

func NewDefaultOutgoingDynamicRateLimiter added in v1.5.7

func NewDefaultOutgoingDynamicRateLimiter(
	rateFn RateFn,
) *DynamicRateLimiterImpl

NewDefaultOutgoingDynamicRateLimiter returns a default rate limiter for outgoing traffic

func NewDynamicRateLimiter added in v0.7.0

func NewDynamicRateLimiter(
	rateFn RateFn,
	burstFn BurstFn,
	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) 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

func (*DynamicRateLimiterImpl) Wait added in v1.5.7

Wait waits up till deadline for a rate limit token

func (*DynamicRateLimiterImpl) WaitN added in v1.5.7

func (d *DynamicRateLimiterImpl) WaitN(ctx context.Context, numToken int) error

WaitN waits up till deadline for n rate limit token

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

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.

func (*MockRateLimiter) Wait added in v1.5.7

func (m *MockRateLimiter) Wait(ctx context.Context) error

Wait mocks base method.

func (*MockRateLimiter) WaitN added in v1.5.7

func (m *MockRateLimiter) WaitN(ctx context.Context, numToken int) error

WaitN 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

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

Burst indicates an expected call of Burst.

func (*MockRateLimiterMockRecorder) Rate added in v1.5.7

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.

func (*MockRateLimiterMockRecorder) Wait added in v1.5.7

func (mr *MockRateLimiterMockRecorder) Wait(ctx interface{}) *gomock.Call

Wait indicates an expected call of Wait.

func (*MockRateLimiterMockRecorder) WaitN added in v1.5.7

func (mr *MockRateLimiterMockRecorder) WaitN(ctx, numToken interface{}) *gomock.Call

WaitN indicates an expected call of WaitN.

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.

func (*MockReservation) EXPECT added in v1.5.7

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockReservation) OK added in v1.5.7

func (m *MockReservation) OK() bool

OK 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

Delay indicates an expected call of Delay.

func (*MockReservationMockRecorder) DelayFrom added in v1.5.7

func (mr *MockReservationMockRecorder) DelayFrom(now interface{}) *gomock.Call

DelayFrom indicates an expected call of DelayFrom.

func (*MockReservationMockRecorder) OK added in v1.5.7

OK indicates an expected call of OK.

type MultiStageRateLimiterImpl added in v1.5.7

type MultiStageRateLimiterImpl struct {
	// contains filtered or unexported fields
}

MultiStageRateLimiterImpl is a wrapper around the limiter interface

func NewMultiStageRateLimiter added in v0.7.0

func NewMultiStageRateLimiter(
	rateLimiters []RateLimiter,
) *MultiStageRateLimiterImpl

NewMultiStageRateLimiter returns a new rate limiter that have multiple stage

func (*MultiStageRateLimiterImpl) Allow added in v1.5.7

func (rl *MultiStageRateLimiterImpl) Allow() bool

Allow immediately returns with true or false indicating if a rate limit token is available or not

func (*MultiStageRateLimiterImpl) AllowN added in v1.5.7

func (rl *MultiStageRateLimiterImpl) 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 (*MultiStageRateLimiterImpl) Burst added in v1.5.7

func (rl *MultiStageRateLimiterImpl) Burst() int

Burst returns the burst for this rate limiter

func (*MultiStageRateLimiterImpl) Rate added in v1.5.7

Rate returns the rate per second for this rate limiter

func (*MultiStageRateLimiterImpl) Reserve added in v1.5.7

func (rl *MultiStageRateLimiterImpl) Reserve() Reservation

Reserve returns a Reservation that indicates how long the caller must wait before event happen.

func (*MultiStageRateLimiterImpl) ReserveN added in v1.5.7

func (rl *MultiStageRateLimiterImpl) ReserveN(now time.Time, numToken int) Reservation

ReserveN returns a Reservation that indicates how long the caller must wait before event happen.

func (*MultiStageRateLimiterImpl) Wait added in v1.5.7

Wait waits up till deadline for a rate limit token

func (*MultiStageRateLimiterImpl) WaitN added in v1.5.7

func (rl *MultiStageRateLimiterImpl) WaitN(ctx context.Context, numToken int) error

WaitN waits up till deadline for n rate limit token

type MultiStageReservationImpl added in v1.5.7

type MultiStageReservationImpl struct {
	// contains filtered or unexported fields
}

func NewMultiStageReservation added in v1.5.7

func NewMultiStageReservation(
	ok bool,
	reservations []Reservation,
) *MultiStageReservationImpl

func (*MultiStageReservationImpl) Cancel added in v1.5.7

func (r *MultiStageReservationImpl) 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 (*MultiStageReservationImpl) CancelAt added in v1.5.7

func (r *MultiStageReservationImpl) CancelAt(now time.Time)

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 (*MultiStageReservationImpl) Delay added in v1.5.7

Delay returns the duration for which the reservation holder must wait before taking the reserved action. Zero duration means act immediately.

func (*MultiStageReservationImpl) DelayFrom added in v1.5.7

func (r *MultiStageReservationImpl) DelayFrom(now time.Time) time.Duration

Delay returns the duration for which the reservation holder must wait before taking the reserved action. Zero duration means act immediately.

func (*MultiStageReservationImpl) OK added in v1.5.7

OK returns whether the limiter can provide the requested number of tokens

type NamespaceMultiStageRateLimiterImpl added in v1.5.7

type NamespaceMultiStageRateLimiterImpl struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

NamespaceMultiStageRateLimiterImpl is a multi stage rate limiter special built for multi-tenancy

func NewNamespaceMultiStageRateLimiter added in v1.5.7

func NewNamespaceMultiStageRateLimiter(
	namespaceRateLimiterFn NamespaceRateLimiterFn,
	sharedRateLimiters []RateLimiter,
) *NamespaceMultiStageRateLimiterImpl

func (*NamespaceMultiStageRateLimiterImpl) Allow added in v1.5.7

func (r *NamespaceMultiStageRateLimiterImpl) Allow(
	namespaceID string,
) 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

func (*NamespaceMultiStageRateLimiterImpl) AllowN added in v1.5.7

func (r *NamespaceMultiStageRateLimiterImpl) AllowN(
	namespaceID string,
	now time.Time,
	numToken int,
) 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

func (*NamespaceMultiStageRateLimiterImpl) Reserve added in v1.5.7

func (r *NamespaceMultiStageRateLimiterImpl) Reserve(
	namespaceID string,
) Reservation

Reserve returns a Reservation that indicates how long the caller must wait before event happen.

func (*NamespaceMultiStageRateLimiterImpl) ReserveN added in v1.5.7

func (r *NamespaceMultiStageRateLimiterImpl) ReserveN(
	namespaceID string,
	now time.Time,
	numToken int,
) Reservation

ReserveN returns a Reservation that indicates how long the caller must wait before event happen.

func (*NamespaceMultiStageRateLimiterImpl) Wait added in v1.5.7

func (r *NamespaceMultiStageRateLimiterImpl) Wait(
	ctx context.Context,
	namespaceID string,
) error

Wait waits till the deadline for a rate limit token to allow the request to go through.

func (*NamespaceMultiStageRateLimiterImpl) WaitN added in v1.5.7

func (r *NamespaceMultiStageRateLimiterImpl) WaitN(
	ctx context.Context,
	namespaceID string,
	numToken int,
) error

WaitN waits till the deadline for a rate limit token to allow the request to go through.

type NamespaceRateLimiter added in v1.5.7

type NamespaceRateLimiter 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(namespaceID string) bool

	// AllowN attempts to allow a requests to go through. The method returns
	// immediately with a true or false indicating if the request can make
	// progress
	AllowN(namespaceID string, now time.Time, numToken int) bool

	// Reserve returns a Reservation that indicates how long the caller
	// must wait before event happen.
	Reserve(namespaceID string) Reservation

	// ReserveN returns a Reservation that indicates how long the caller
	// must wait before event happen.
	ReserveN(namespaceID string, 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, namespaceID string) error

	// WaitN waits till the deadline for a rate limit token to allow the request
	// to go through.
	WaitN(ctx context.Context, namespaceID string, numToken int) error
}

NamespaceRateLimiter corresponds to basic rate limiting functionality.

type NamespaceRateLimiterFn added in v1.5.7

type NamespaceRateLimiterFn func(namespaceID string) RateLimiter

NamespaceRateLimiterFn returns generate a namespace specific rate limiter

type NamespaceRateLimiterImpl added in v1.5.7

type NamespaceRateLimiterImpl struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

NamespaceRateLimiterImpl is a rate limiter special built for multi-tenancy

func NewNamespaceRateLimiter added in v1.5.7

func NewNamespaceRateLimiter(
	namespaceRateLimiterFn NamespaceRateLimiterFn,
) *NamespaceRateLimiterImpl

func (*NamespaceRateLimiterImpl) Allow added in v1.5.7

func (r *NamespaceRateLimiterImpl) Allow(
	namespaceID string,
) 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

func (*NamespaceRateLimiterImpl) AllowN added in v1.5.7

func (r *NamespaceRateLimiterImpl) AllowN(
	namespaceID string,
	now time.Time,
	numToken int,
) 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

func (*NamespaceRateLimiterImpl) Reserve added in v1.5.7

func (r *NamespaceRateLimiterImpl) Reserve(
	namespaceID string,
) Reservation

Reserve returns a Reservation that indicates how long the caller must wait before event happen.

func (*NamespaceRateLimiterImpl) ReserveN added in v1.5.7

func (r *NamespaceRateLimiterImpl) ReserveN(
	namespaceID string,
	now time.Time,
	numToken int,
) Reservation

ReserveN returns a Reservation that indicates how long the caller must wait before event happen.

func (*NamespaceRateLimiterImpl) Wait added in v1.5.7

func (r *NamespaceRateLimiterImpl) Wait(
	ctx context.Context,
	namespaceID string,
) error

Wait waits till the deadline for a rate limit token to allow the request to go through.

func (*NamespaceRateLimiterImpl) WaitN added in v1.5.7

func (r *NamespaceRateLimiterImpl) WaitN(
	ctx context.Context,
	namespaceID string,
	numToken int,
) error

WaitN waits till the deadline for a rate limit token to allow the request to go through.

type RateFn added in v1.5.7

type RateFn func() float64

RateFn returns a float64 as the RPS

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

	// Wait 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)

Burst 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

func (*RateLimiterImpl) Wait added in v1.5.7

func (rl *RateLimiterImpl) Wait(ctx context.Context) error

Wait waits up till deadline for a rate limit token

func (*RateLimiterImpl) WaitN added in v1.5.7

func (rl *RateLimiterImpl) WaitN(ctx context.Context, numToken int) error

WaitN waits up till deadline for n rate limit token

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

Jump to

Keyboard shortcuts

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