multilimiter

package
v1.16.3 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2023 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ReconcileCheckLimit    time.Duration
	ReconcileCheckInterval time.Duration
}

Config is a MultiLimiter configuration

type KeyType

type KeyType = []byte

func Key

func Key(keys ...[]byte) KeyType

type LimitedEntity

type LimitedEntity interface {
	Key() KeyType
}

LimitedEntity is an interface used by MultiLimiter.Allow to determine which rate limiter to use to allow the request

type Limiter

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

Limiter define a limiter to be part of the MultiLimiter structure

type LimiterConfig

type LimiterConfig struct {
	Rate  rate.Limit
	Burst int
}

LimiterConfig is a Limiter configuration

type MockRateLimiter

type MockRateLimiter struct {
	mock.Mock
}

MockRateLimiter is an autogenerated mock type for the RateLimiter type

func NewMockRateLimiter

func NewMockRateLimiter(t mockConstructorTestingTNewMockRateLimiter) *MockRateLimiter

NewMockRateLimiter creates a new instance of MockRateLimiter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.

func (*MockRateLimiter) Allow

func (_m *MockRateLimiter) Allow(entity LimitedEntity) bool

Allow provides a mock function with given fields: entity

func (*MockRateLimiter) DeleteConfig added in v1.16.0

func (_m *MockRateLimiter) DeleteConfig(prefix []byte)

DeleteConfig provides a mock function with given fields: prefix

func (*MockRateLimiter) Run

func (_m *MockRateLimiter) Run(ctx context.Context)

Run provides a mock function with given fields: ctx

func (*MockRateLimiter) UpdateConfig

func (_m *MockRateLimiter) UpdateConfig(c LimiterConfig, prefix []byte)

UpdateConfig provides a mock function with given fields: c, prefix

type MultiLimiter

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

MultiLimiter implement RateLimiter interface and represent a set of rate limiters specific to different LimitedEntities and queried by a LimitedEntities.Key()

func NewMultiLimiter

func NewMultiLimiter(c Config) *MultiLimiter

NewMultiLimiter create a new MultiLimiter

func (*MultiLimiter) Allow

func (m *MultiLimiter) Allow(e LimitedEntity) bool

Allow should be called by a request processor to check if the current request is Limited The request processor should provide a LimitedEntity that implement the right Key()

func (*MultiLimiter) DeleteConfig added in v1.16.0

func (m *MultiLimiter) DeleteConfig(prefix []byte)

DeleteConfig will delete the MultiLimiter Config which will cascade to all the Limiter(s) LimiterConfig

func (*MultiLimiter) Run

func (m *MultiLimiter) Run(ctx context.Context)

Run the cleanup routine to remove old entries of Limiters based on ReconcileCheckLimit and ReconcileCheckInterval.

func (*MultiLimiter) UpdateConfig

func (m *MultiLimiter) UpdateConfig(c LimiterConfig, prefix []byte)

UpdateConfig will update the MultiLimiter Config which will cascade to all the Limiter(s) LimiterConfig

type RateLimiter

type RateLimiter interface {
	Run(ctx context.Context)
	Allow(entity LimitedEntity) bool
	UpdateConfig(c LimiterConfig, prefix []byte)
	DeleteConfig(prefix []byte)
}

RateLimiter is the interface implemented by MultiLimiter

Jump to

Keyboard shortcuts

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