ratetracker

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicRateLimitChecker

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

BasicRateLimitChecker implements LimitCheck.

func NewBasicRateLimitChecker

func NewBasicRateLimitChecker() *BasicRateLimitChecker

NewBasicRateLimitChecker creates a new instance of BasicLimitCheck.

func (*BasicRateLimitChecker) CheckRateLimit

func (l *BasicRateLimitChecker) CheckRateLimit(label string, count int) (bool, int)

CheckRateLimit checks the limit for a specific label and the remaining limit. If limit is exceeded then we return false and 0 as remaining limit.

func (*BasicRateLimitChecker) GetLabelRateLimit

func (l *BasicRateLimitChecker) GetLabelRateLimit(label string) int

GetLabelRateLimit returns the limit for a specific label.

func (*BasicRateLimitChecker) GetRateLimit

func (l *BasicRateLimitChecker) GetRateLimit() int

GetRateLimit returns the limit.

func (*BasicRateLimitChecker) SetOverrides

func (l *BasicRateLimitChecker) SetOverrides(overrides Overrides)

SetOverrides applies the overrides to the limit.

func (*BasicRateLimitChecker) SetRateLimit

func (l *BasicRateLimitChecker) SetRateLimit(limit int)

SetRateLimit sets the limit.

type DistCacheRateTracker

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

DistCacheRateTracker implements Limiter.

func (*DistCacheRateTracker) Close

func (ol *DistCacheRateTracker) Close() error

Close cleans up DMap held within the DistCacheRateTracker.

func (*DistCacheRateTracker) GetRateLimitChecker

func (ol *DistCacheRateTracker) GetRateLimitChecker() RateLimitChecker

GetRateLimitChecker returns the RateLimitCheck of the DistCacheRateTracker.

func (*DistCacheRateTracker) Name

func (ol *DistCacheRateTracker) Name() string

Name returns the name of the DistCacheRateTracker.

func (*DistCacheRateTracker) Take

func (ol *DistCacheRateTracker) Take(label string) (bool, int, int)

Take is a wrapper for TakeN(label, 1).

func (*DistCacheRateTracker) TakeN

func (ol *DistCacheRateTracker) TakeN(label string, n int) (bool, int, int)

TakeN increments value in label by n and returns whether n events should be allowed along with the remaining value (limit - new n) after increment and the current count for the label. If an error occurred it returns true, 0 and 0 (fail open).

type LazySyncRateTracker

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

LazySyncRateTracker is a limiter that syncs its state lazily with another limiter.

func (*LazySyncRateTracker) Close

func (lsl *LazySyncRateTracker) Close() error

Close closes the limiter.

func (*LazySyncRateTracker) GetRateLimitChecker

func (lsl *LazySyncRateTracker) GetRateLimitChecker() RateLimitChecker

GetRateLimitChecker returns the limit checker of the limiter.

func (*LazySyncRateTracker) Name

func (lsl *LazySyncRateTracker) Name() string

Name returns the name of the limiter.

func (*LazySyncRateTracker) Take

func (lsl *LazySyncRateTracker) Take(label string) (bool, int, int)

Take is a wrapper for TakeN(label, 1).

func (*LazySyncRateTracker) TakeN

func (lsl *LazySyncRateTracker) TakeN(label string, n int) (bool, int, int)

TakeN takes n tokens from the limiter.

type Overrides

type Overrides map[string]float64

Overrides is a map of label to limit scale factor.

type RateLimitChecker

type RateLimitChecker interface {
	CheckRateLimit(label string, count int) (ok bool, remaining int)
	SetRateLimit(limit int)
	GetRateLimit() int
}

RateLimitChecker is a generic limit checker interface.

type RateTracker

type RateTracker interface {
	Name() string
	Take(label string) (ok bool, remaining int, current int)
	TakeN(label string, count int) (ok bool, remaining int, current int)
	GetRateLimitChecker() RateLimitChecker
	Close() error
}

RateTracker is a generic limiter interface.

func NewDistCacheRateTracker

func NewDistCacheRateTracker(limitCheck RateLimitChecker, dc *distcache.DistCache, name string, ttl time.Duration) (RateTracker, error)

NewDistCacheRateTracker creates a new instance of DistCacheRateTracker.

func NewLazySyncRateTracker

func NewLazySyncRateTracker(limiter RateTracker,
	syncDuration time.Duration,
	jobGroup *jobs.JobGroup,
) (RateTracker, error)

NewLazySyncRateTracker creates a new LazySyncLimiter.

Jump to

Keyboard shortcuts

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