Help us shape the future of Go! Take the 2026 Go Developer Survey

limiter

package
v1.15.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMaxSeriesHit           = "the query hit the max number of series limit (limit: %d series)"
	ErrMaxChunkBytesHit       = "the query hit the aggregated chunks size limit (limit: %d bytes)"
	ErrMaxDataBytesHit        = "the query hit the aggregated data size limit (limit: %d bytes)"
	ErrMaxChunksPerQueryLimit = "the query hit the max number of chunks limit (limit: %d chunks)"
)

Functions

func AddQueryLimiterToContext added in v1.10.0

func AddQueryLimiterToContext(ctx context.Context, limiter *QueryLimiter) context.Context

Types

type QueryLimiter added in v1.10.0

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

func NewQueryLimiter added in v1.10.0

func NewQueryLimiter(maxSeriesPerQuery, maxChunkBytesPerQuery, maxChunksPerQuery, maxDataBytesPerQuery int) *QueryLimiter

NewQueryLimiter makes a new per-query limiter. Each query limiter is configured using the `maxSeriesPerQuery` limit.

func QueryLimiterFromContextWithFallback added in v1.10.0

func QueryLimiterFromContextWithFallback(ctx context.Context) *QueryLimiter

QueryLimiterFromContextWithFallback returns a QueryLimiter from the current context. If there is not a QueryLimiter on the context it will return a new no-op limiter.

func (*QueryLimiter) AddChunkBytes added in v1.10.0

func (ql *QueryLimiter) AddChunkBytes(chunkSizeInBytes int) error

AddChunkBytes adds the input chunk size in bytes and returns an error if the limit is reached.

func (*QueryLimiter) AddChunks added in v1.11.0

func (ql *QueryLimiter) AddChunks(count int) error

func (*QueryLimiter) AddDataBytes added in v1.14.0

func (ql *QueryLimiter) AddDataBytes(dataSizeInBytes int) error

AddDataBytes adds the queried data bytes and returns an error if the limit is reached.

func (*QueryLimiter) AddSeries added in v1.10.0

func (ql *QueryLimiter) AddSeries(seriesLabels []cortexpb.LabelAdapter) error

AddSeries adds the input series and returns an error if the limit is reached.

type RateLimiter

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

RateLimiter is a multi-tenant local rate limiter based on golang.org/x/time/rate. It requires a custom strategy in input, which is used to get the limit and burst settings for each tenant.

func NewRateLimiter

func NewRateLimiter(strategy RateLimiterStrategy, recheckPeriod time.Duration) *RateLimiter

NewRateLimiter makes a new multi-tenant rate limiter. Each per-tenant limiter is configured using the input strategy and its limit/burst is rechecked (and reconfigured if changed) every recheckPeriod.

func (*RateLimiter) AllowN

func (l *RateLimiter) AllowN(now time.Time, tenantID string, n int) bool

AllowN reports whether n tokens may be consumed happen at time now.

func (*RateLimiter) Burst

func (l *RateLimiter) Burst(now time.Time, tenantID string) int

Burst returns the currently configured maximum burst size.

func (*RateLimiter) Limit

func (l *RateLimiter) Limit(now time.Time, tenantID string) float64

Limit returns the currently configured maximum overall tokens rate.

type RateLimiterStrategy

type RateLimiterStrategy interface {
	Limit(tenantID string) float64
	Burst(tenantID string) int
}

RateLimiterStrategy defines the interface which a pluggable strategy should implement. The returned limit and burst can change over the time, and the local rate limiter will apply them every recheckPeriod.

Jump to

Keyboard shortcuts

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