ratelimit

package
v1.16.16 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2022 License: Apache-2.0, Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type QuotaExceededError

type QuotaExceededError struct {
	Available uint
	Requested uint
}

QuotaExceededError provides the SDK error when the retries for a given token bucket have been exhausted.

func (QuotaExceededError) Error

func (e QuotaExceededError) Error() string

type TokenBucket

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

TokenBucket provides a concurrency safe utility for adding and removing tokens from the available token bucket.

func NewTokenBucket

func NewTokenBucket(i uint) *TokenBucket

NewTokenBucket returns an initialized TokenBucket with the capacity specified.

func (*TokenBucket) Capacity

func (t *TokenBucket) Capacity() uint

Capacity returns the maximum capacity of tokens that the bucket could contain.

func (*TokenBucket) Refund

func (t *TokenBucket) Refund(amount uint)

Refund returns the amount of tokens back to the available token bucket, up to the initial capacity.

func (*TokenBucket) Remaining

func (t *TokenBucket) Remaining() uint

Remaining returns the number of tokens that remaining in the bucket.

func (*TokenBucket) Resize

func (t *TokenBucket) Resize(size uint) uint

Resize adjusts the size of the token bucket. Returns the capacity remaining.

func (*TokenBucket) Retrieve

func (t *TokenBucket) Retrieve(amount uint) (available uint, retrieved bool)

Retrieve attempts to reduce the available tokens by the amount requested. If there are tokens available true will be returned along with the number of available tokens remaining. If amount requested is larger than the available capacity, false will be returned along with the available capacity. If the amount is less than the available capacity, the capacity will be reduced by that amount, and the remaining capacity and true will be returned.

type TokenRateLimit

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

TokenRateLimit provides a Token Bucket RateLimiter implementation that limits the overall number of retry attempts that can be made across operation invocations.

func NewTokenRateLimit

func NewTokenRateLimit(tokens uint) *TokenRateLimit

NewTokenRateLimit returns an TokenRateLimit with default values. Functional options can configure the retry rate limiter.

func (*TokenRateLimit) AddTokens

func (l *TokenRateLimit) AddTokens(v uint) error

AddTokens increments the token bucket by a fixed amount.

func (*TokenRateLimit) GetToken

func (l *TokenRateLimit) GetToken(ctx context.Context, cost uint) (func() error, error)

GetToken may cause a available pool of retry quota to be decremented. Will return an error if the decremented value can not be reduced from the retry quota.

func (*TokenRateLimit) Remaining

func (l *TokenRateLimit) Remaining() uint

Remaining returns the number of remaining tokens in the bucket.

Jump to

Keyboard shortcuts

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