Documentation
¶
Overview ¶
Package quotas is a generated GoMock package.
Package quotas is a generated GoMock package.
Package quotas is a generated GoMock package.
Package quotas is a generated GoMock package.
Index ¶
- type CallerBypass
- type Collection
- type DynamicRateLimiter
- type DynamicRateLimiterOpts
- type ICollection
- type Info
- type Limiter
- type LimiterFactory
- type MockICollection
- type MockICollectionMockRecorder
- type MockLimiter
- type MockLimiterFactory
- type MockLimiterFactoryMockRecorder
- type MockLimiterMockRecorder
- type MockPolicy
- type MockPolicyMockRecorder
- type MultiStageRateLimiter
- type Policy
- type RPSFunc
- type RPSKeyFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CallerBypass ¶ added in v1.4.0
type CallerBypass struct {
// contains filtered or unexported fields
}
CallerBypass encapsulates the logic for bypassing rate limits based on caller type
func NewCallerBypass ¶ added in v1.4.0
func NewCallerBypass(bypassCallerTypes dynamicproperties.ListPropertyFn) CallerBypass
NewCallerBypass creates a new CallerBypass with the given bypass caller types configuration
func (CallerBypass) AllowLimiter ¶ added in v1.4.0
func (c CallerBypass) AllowLimiter(ctx context.Context, limiter Limiter) bool
AllowLimiter checks if a request should be allowed through a Limiter. It first checks the limiter's Allow() method, and if that returns false, it checks if the caller type should bypass rate limiting.
func (CallerBypass) AllowPolicy ¶ added in v1.4.0
AllowPolicy checks if a request should be allowed through a Policy. It first checks the policy's Allow() method, and if that returns false, it checks if the caller type should bypass rate limiting.
func (CallerBypass) ShouldBypass ¶ added in v1.4.0
func (c CallerBypass) ShouldBypass(ctx context.Context) bool
ShouldBypass checks if the caller type from the context should bypass rate limiting based on the configured bypass caller 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 (*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
type DynamicRateLimiterOpts ¶ added in v1.3.0
type DynamicRateLimiterOpts struct {
TTL time.Duration
MinBurst int
TimeSource clock.TimeSource
}
type ICollection ¶ added in v1.2.12
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.
func NewDynamicRateLimiter ¶ added in v0.7.0
NewDynamicRateLimiter returns a rate limiter which handles dynamic config
func NewDynamicRateLimiterWithOpts ¶ added in v1.3.0
func NewDynamicRateLimiterWithOpts(rps RPSFunc, opts DynamicRateLimiterOpts) 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
type MockICollection ¶ added in v1.2.18
type MockICollection struct {
// contains filtered or unexported fields
}
MockICollection is a mock of ICollection interface.
func NewMockICollection ¶ added in v1.2.18
func NewMockICollection(ctrl *gomock.Controller) *MockICollection
NewMockICollection creates a new mock instance.
func (*MockICollection) EXPECT ¶ added in v1.2.18
func (m *MockICollection) EXPECT() *MockICollectionMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockICollection) For ¶ added in v1.2.18
func (m *MockICollection) For(key string) Limiter
For mocks base method.
type MockICollectionMockRecorder ¶ added in v1.2.18
type MockICollectionMockRecorder struct {
// contains filtered or unexported fields
}
MockICollectionMockRecorder is the mock recorder for MockICollection.
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.
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
func (m *MockLimiterFactory) EXPECT() *MockLimiterFactoryMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockLimiterFactory) GetLimiter ¶ added in v1.2.7
func (m *MockLimiterFactory) GetLimiter(domain 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(domain any) *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.
type MockPolicy ¶ added in v1.4.0
type MockPolicy struct {
// contains filtered or unexported fields
}
MockPolicy is a mock of Policy interface.
func NewMockPolicy ¶ added in v1.4.0
func NewMockPolicy(ctrl *gomock.Controller) *MockPolicy
NewMockPolicy creates a new mock instance.
func (*MockPolicy) Allow ¶ added in v1.4.0
func (m *MockPolicy) Allow(info Info) bool
Allow mocks base method.
func (*MockPolicy) EXPECT ¶ added in v1.4.0
func (m *MockPolicy) EXPECT() *MockPolicyMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
type MockPolicyMockRecorder ¶ added in v1.4.0
type MockPolicyMockRecorder struct {
// contains filtered or unexported fields
}
MockPolicyMockRecorder is the mock recorder for MockPolicy.
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
// Wait waits up till the context deadline for a rate limit token to allow
// the request to go through. Returns nil if request is allowed.
Wait(ctx context.Context, info Info) error
}
Policy corresponds to a quota policy. A policy allows implementing layered and more complex rate limiting functionality.
type RPSKeyFunc ¶ added in v0.7.0
RPSKeyFunc returns a float64 as the RPS for the given key
Source Files
¶
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. |