Documentation
¶
Index ¶
- Constants
- Variables
- func AddQueryLimiterToContext(ctx context.Context, limiter *QueryLimiter) context.Context
- func AddResponseSizeLimiterToContext(ctx context.Context, responseSizeLimiter *ResponseSizeLimiter) context.Context
- type MockMonitor
- type QueryLimiter
- type RateLimiter
- type RateLimiterStrategy
- type ResourceBasedLimiter
- type ResponseSizeLimiter
Constants ¶
const ErrResourceLimitReachedStr = "resource limit reached"
Variables ¶
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)" )
var (
ErrMaxResponseSizeHit = "the query response size exceeds limit (limit: %d bytes)"
)
var ErrResourceLimitReached = status.Error(codes.ResourceExhausted, ErrResourceLimitReachedStr)
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
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.
type RateLimiterStrategy ¶
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.