quotas

package
v1.2.14 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2024 License: MIT Imports: 10 Imported by: 8

Documentation

Overview

Package quotas is a generated GoMock package.

Package quotas is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collection added in v0.24.0

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

Collection stores a map of limiters by key

func NewCollection added in v0.24.0

func NewCollection(factory LimiterFactory) *Collection

NewCollection create a new limiter collection. Given factory is called to create new individual limiter.

func (*Collection) For added in v0.24.0

func (c *Collection) For(key string) Limiter

For retrieves limiter by a given key. If limiter for such key does not exists, it creates new one with via factory.

type DynamicRateLimiter added in v0.7.0

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

DynamicRateLimiter implements a dynamic config wrapper around the rate limiter, checks for updates to the dynamic config and updates the rate limiter accordingly

func NewDynamicRateLimiter added in v0.7.0

func NewDynamicRateLimiter(rps RPSFunc) *DynamicRateLimiter

NewDynamicRateLimiter returns a rate limiter which handles dynamic config

func (*DynamicRateLimiter) Allow added in v0.7.0

func (d *DynamicRateLimiter) Allow() bool

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

func (*DynamicRateLimiter) Limit added in v1.2.13

func (d *DynamicRateLimiter) Limit() rate.Limit

func (*DynamicRateLimiter) Reserve added in v0.7.0

func (d *DynamicRateLimiter) Reserve() clock.Reservation

Reserve reserves a rate limit token

func (*DynamicRateLimiter) Wait added in v0.7.0

func (d *DynamicRateLimiter) Wait(ctx context.Context) error

Wait waits up till deadline for a rate limit token

type ICollection added in v1.2.12

type ICollection interface {
	For(key string) Limiter
}

type Info added in v0.7.0

type Info struct {
	Domain string
}

Info corresponds to information required to determine rate limits

type Limiter added in v0.7.0

type Limiter 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

	// Wait waits till the deadline for a rate limit token to allow the request
	// to go through.
	Wait(ctx context.Context) error

	// Reserve reserves a rate limit token
	Reserve() clock.Reservation

	// Limit returns the current configured ratelimit.
	//
	// If this Limiter wraps multiple values, this is generally the "most relevant" one,
	// i.e. the one that is most likely to apply to the next request
	Limit() rate.Limit
}

Limiter corresponds to basic rate limiting functionality.

TODO: This can likely be replaced with clock.Ratelimiter, now that it exists, but it is being left as a read-only mirror for now as only these methods are currently needed in areas that currently use this Limiter.

type LimiterFactory added in v1.2.6

type LimiterFactory interface {
	// GetLimiter returns a new Limiter for the given domain
	GetLimiter(domain string) Limiter
}

LimiterFactory is used to create a Limiter for a given domain

func NewFallbackDynamicRateLimiterFactory added in v1.2.6

func NewFallbackDynamicRateLimiterFactory(
	primary dynamicconfig.IntPropertyFnWithDomainFilter,
	secondary dynamicconfig.IntPropertyFn,
) LimiterFactory

LimiterFactory is used to create a Limiter for a given domain the created Limiter will use the primary dynamic config if it is set otherwise it will use the secondary dynamic config

func NewSimpleDynamicRateLimiterFactory added in v1.2.6

func NewSimpleDynamicRateLimiterFactory(rps dynamicconfig.IntPropertyFnWithDomainFilter) LimiterFactory

NewSimpleDynamicRateLimiterFactory creates a new LimiterFactory which creates a new DynamicRateLimiter for each domain, the RPS for the DynamicRateLimiter is given by the dynamic config

type MockLimiter added in v1.2.7

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

MockLimiter is a mock of Limiter interface.

func NewMockLimiter added in v1.2.7

func NewMockLimiter(ctrl *gomock.Controller) *MockLimiter

NewMockLimiter creates a new mock instance.

func (*MockLimiter) Allow added in v1.2.7

func (m *MockLimiter) Allow() bool

Allow mocks base method.

func (*MockLimiter) EXPECT added in v1.2.7

func (m *MockLimiter) EXPECT() *MockLimiterMockRecorder

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

func (*MockLimiter) Limit added in v1.2.13

func (m *MockLimiter) Limit() rate.Limit

Limit mocks base method.

func (*MockLimiter) Reserve added in v1.2.7

func (m *MockLimiter) Reserve() clock.Reservation

Reserve mocks base method.

func (*MockLimiter) Wait added in v1.2.7

func (m *MockLimiter) Wait(arg0 context.Context) error

Wait mocks base method.

type MockLimiterFactory added in v1.2.7

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

MockLimiterFactory is a mock of LimiterFactory interface.

func NewMockLimiterFactory added in v1.2.7

func NewMockLimiterFactory(ctrl *gomock.Controller) *MockLimiterFactory

NewMockLimiterFactory creates a new mock instance.

func (*MockLimiterFactory) EXPECT added in v1.2.7

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

func (*MockLimiterFactory) GetLimiter added in v1.2.7

func (m *MockLimiterFactory) GetLimiter(arg0 string) Limiter

GetLimiter mocks base method.

type MockLimiterFactoryMockRecorder added in v1.2.7

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

MockLimiterFactoryMockRecorder is the mock recorder for MockLimiterFactory.

func (*MockLimiterFactoryMockRecorder) GetLimiter added in v1.2.7

func (mr *MockLimiterFactoryMockRecorder) GetLimiter(arg0 interface{}) *gomock.Call

GetLimiter indicates an expected call of GetLimiter.

type MockLimiterMockRecorder added in v1.2.7

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

MockLimiterMockRecorder is the mock recorder for MockLimiter.

func (*MockLimiterMockRecorder) Allow added in v1.2.7

func (mr *MockLimiterMockRecorder) Allow() *gomock.Call

Allow indicates an expected call of Allow.

func (*MockLimiterMockRecorder) Limit added in v1.2.13

func (mr *MockLimiterMockRecorder) Limit() *gomock.Call

Limit indicates an expected call of Limit.

func (*MockLimiterMockRecorder) Reserve added in v1.2.7

func (mr *MockLimiterMockRecorder) Reserve() *gomock.Call

Reserve indicates an expected call of Reserve.

func (*MockLimiterMockRecorder) Wait added in v1.2.7

func (mr *MockLimiterMockRecorder) Wait(arg0 interface{}) *gomock.Call

Wait indicates an expected call of Wait.

type MultiStageRateLimiter added in v0.7.0

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

MultiStageRateLimiter indicates a domain specific rate limit policy

func NewMultiStageRateLimiter added in v0.7.0

func NewMultiStageRateLimiter(global Limiter, domainLimiters ICollection) *MultiStageRateLimiter

NewMultiStageRateLimiter returns a new domain quota rate limiter. This is about an order of magnitude slower than

func (*MultiStageRateLimiter) Allow added in v0.7.0

func (d *MultiStageRateLimiter) Allow(info Info) (allowed 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 Policy

type Policy 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(info Info) bool
}

Policy corresponds to a quota policy. A policy allows implementing layered and more complex rate limiting functionality.

type RPSFunc added in v0.7.0

type RPSFunc func() float64

RPSFunc returns a float64 as the RPS

type RPSKeyFunc added in v0.7.0

type RPSKeyFunc func(key string) float64

RPSKeyFunc returns a float64 as the RPS for the given key

type RateLimiter added in v0.7.0

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

RateLimiter is a wrapper around the golang rate limiter handling dynamic configuration updates of the max dispatch per second. This has comparable performance to the token bucket rate limiter. BenchmarkSimpleRateLimiter-4 10000000 114 ns/op (tokenbucket) BenchmarkRateLimiter-4 10000000 148 ns/op (this)

func NewRateLimiter added in v0.7.0

func NewRateLimiter(maxDispatchPerSecond *float64, ttl time.Duration, minBurst int) *RateLimiter

NewRateLimiter returns a new rate limiter that can handle dynamic configuration updates

func NewSimpleRateLimiter

func NewSimpleRateLimiter(t *testing.T, rps int) *RateLimiter

NewSimpleRateLimiter returns a new rate limiter backed by the golang rate limiter. This is currently only used in tests.

func (*RateLimiter) Allow added in v0.7.0

func (rl *RateLimiter) Allow() bool

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

func (*RateLimiter) Limit added in v0.7.0

func (rl *RateLimiter) Limit() rate.Limit

Limit returns the current rate per second limit for this ratelimiter

func (*RateLimiter) Reserve added in v0.7.0

func (rl *RateLimiter) Reserve() clock.Reservation

Reserve reserves a rate limit token

func (*RateLimiter) UpdateMaxDispatch added in v0.7.0

func (rl *RateLimiter) UpdateMaxDispatch(maxDispatchPerSecond *float64)

UpdateMaxDispatch updates the max dispatch rate of the rate limiter

func (*RateLimiter) Wait added in v0.7.0

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

Wait waits up till deadline for a rate limit token

Directories

Path Synopsis
Package global contains a global-load-balance-aware ratelimiter (when complete).
Package global contains a global-load-balance-aware ratelimiter (when complete).
algorithm
Package algorithm contains a running-weighted-average calculator for ratelimits, and some associated types to prevent accidental confusion between the various floats/ints/etc involved.
Package algorithm contains a running-weighted-average calculator for ratelimits, and some associated types to prevent accidental confusion between the various floats/ints/etc involved.
collection
Package collection contains the limiting-host ratelimit usage tracking and enforcing logic, which acts as a quotas.Collection.
Package collection contains the limiting-host ratelimit usage tracking and enforcing logic, which acts as a quotas.Collection.
collection/internal
Package internal protects these types' concurrency primitives and other internals from accidental misuse.
Package internal protects these types' concurrency primitives and other internals from accidental misuse.
rpc
Package rpc contains a concurrent RPC client, and handles mapping to/from the Any-typed request details so other packages do not have to concern themselves with those details.
Package rpc contains a concurrent RPC client, and handles mapping to/from the Any-typed request details so other packages do not have to concern themselves with those details.
shared
Package shared holds some types that are used between multiple global-ratelimiter packages, and need to be broken out to prevent import cycles.
Package shared holds some types that are used between multiple global-ratelimiter packages, and need to be broken out to prevent import cycles.

Jump to

Keyboard shortcuts

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