limiter

package
v1.20.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2025 License: Apache-2.0 Imports: 14 Imported by: 7

Documentation

Index

Constants

View Source
const ErrResourceLimitReachedStr = "resource limit reached"

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)"
)
View Source
var (
	ErrMaxResponseSizeHit = "the query response size exceeds limit (limit: %d bytes)"
)

Functions

func AddQueryLimiterToContext added in v1.10.0

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

func AddResponseSizeLimiterToContext added in v1.20.0

func AddResponseSizeLimiterToContext(ctx context.Context, responseSizeLimiter *ResponseSizeLimiter) context.Context

Types

type MockMonitor added in v1.20.0

type MockMonitor struct {
	CpuUtilization  float64
	HeapUtilization float64
}

func (*MockMonitor) GetCPUUtilization added in v1.20.0

func (m *MockMonitor) GetCPUUtilization() float64

func (*MockMonitor) GetHeapUtilization added in v1.20.0

func (m *MockMonitor) GetHeapUtilization() float64

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(series ...[]cortexpb.LabelAdapter) error

AddSeries adds the batch of 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.

type ResourceBasedLimiter added in v1.20.0

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

func NewResourceBasedLimiter added in v1.20.0

func NewResourceBasedLimiter(resourceMonitor resource.IMonitor, limits map[resource.Type]float64, registerer prometheus.Registerer, component string) (*ResourceBasedLimiter, error)

func (*ResourceBasedLimiter) AcceptNewRequest added in v1.20.0

func (l *ResourceBasedLimiter) AcceptNewRequest() error

type ResponseSizeLimiter added in v1.20.0

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

func NewResponseSizeLimiter added in v1.20.0

func NewResponseSizeLimiter(maxResponseSize int64) *ResponseSizeLimiter

NewResponseSizeLimiter creates a new limiter to track total response size.

func ResponseSizeLimiterFromContextWithFallback added in v1.20.0

func ResponseSizeLimiterFromContextWithFallback(ctx context.Context) *ResponseSizeLimiter

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

func (*ResponseSizeLimiter) AddResponseBytes added in v1.20.0

func (rl *ResponseSizeLimiter) AddResponseBytes(responseSizeInBytes int) error

AddResponseBytes adds response bytes received at query-frontend to the total query response size and returns an error if the limit is reached.

Jump to

Keyboard shortcuts

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