querylimits

package
v3.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HTTPHeaderQueryLimitsKey        = "X-Loki-Query-Limits"
	HTTPHeaderQueryLimitsContextKey = "X-Loki-Query-Limits-Context"
)

Variables

This section is empty.

Functions

func ClientQueryLimitsInterceptor

func ClientQueryLimitsInterceptor(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error

func InjectQueryLimitsContextHTTP added in v3.7.0

func InjectQueryLimitsContextHTTP(r *http.Request, limitsCtx *Context) error

InjectQueryLimitsContextHTTP adds the query limits context to the request headers.

func InjectQueryLimitsContextHeader added in v3.7.0

func InjectQueryLimitsContextHeader(h *http.Header, limitsCtx *Context) error

InjectQueryLimitsContextHeader adds the query limits context to the headers.

func InjectQueryLimitsContextIntoContext added in v3.7.0

func InjectQueryLimitsContextIntoContext(ctx context.Context, limitsCtx Context) context.Context

InjectQueryLimitsContextIntoContext returns a derived context containing the provided query limits context

func InjectQueryLimitsHTTP

func InjectQueryLimitsHTTP(r *http.Request, limits *QueryLimits) error

InjectQueryLimitsHTTP adds the query limits to the request headers.

func InjectQueryLimitsHeader

func InjectQueryLimitsHeader(h *http.Header, limits *QueryLimits) error

InjectQueryLimitsHeader adds the query limits to the headers.

func InjectQueryLimitsIntoContext added in v3.7.0

func InjectQueryLimitsIntoContext(ctx context.Context, limits QueryLimits) context.Context

InjectQueryLimitsIntoContext returns a derived context containing the provided query limits

func MarshalQueryLimits

func MarshalQueryLimits(limits *QueryLimits) ([]byte, error)

func MarshalQueryLimitsContext added in v3.7.0

func MarshalQueryLimitsContext(limits *Context) ([]byte, error)

func NewQueryLimitsMiddleware

func NewQueryLimitsMiddleware(logger log.Logger) middleware.Interface

NewQueryLimitsMiddleware creates a middleware that extracts the query limits policy from the HTTP header and injects it into the context of the request.

func ServerQueryLimitsInterceptor

func ServerQueryLimitsInterceptor(ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)

func StreamClientQueryLimitsInterceptor

func StreamClientQueryLimitsInterceptor(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (grpc.ClientStream, error)

func StreamServerQueryLimitsInterceptor

func StreamServerQueryLimitsInterceptor(srv interface{}, ss grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler) error

Types

type Context added in v3.7.0

type Context struct {
	Expr string    `json:"expr"`
	From time.Time `json:"from"`
	To   time.Time `json:"to"`
}

func ExtractQueryLimitsContextFromContext added in v3.7.0

func ExtractQueryLimitsContextFromContext(ctx context.Context) *Context

ExtractQueryLimitsContextFromContext gets the embedded query limits context from the context

func ExtractQueryLimitsContextHTTP added in v3.7.0

func ExtractQueryLimitsContextHTTP(r *http.Request) (*Context, error)

ExtractQueryLimitsContextHTTP retrieves the query limits context from the HTTP header and returns it.

func UnmarshalQueryLimitsContext added in v3.7.0

func UnmarshalQueryLimitsContext(data []byte) (*Context, error)

type Limiter

type Limiter struct {
	limiter.CombinedLimits
	// contains filtered or unexported fields
}

func NewLimiter

func NewLimiter(log log.Logger, original limiter.CombinedLimits) *Limiter

func (*Limiter) MaxEntriesLimitPerQuery

func (l *Limiter) MaxEntriesLimitPerQuery(ctx context.Context, userID string) int

MaxEntriesLimitPerQuery returns the limit to number of entries the querier should return per query.

func (*Limiter) MaxQueryBytesRead

func (l *Limiter) MaxQueryBytesRead(ctx context.Context, userID string) int

func (*Limiter) MaxQueryLength

func (l *Limiter) MaxQueryLength(ctx context.Context, userID string) time.Duration

MaxQueryLength returns the limit of the length (in time) of a query.

func (*Limiter) MaxQueryLookback

func (l *Limiter) MaxQueryLookback(ctx context.Context, userID string) time.Duration

MaxQueryLookback returns the max lookback period of queries.

func (*Limiter) MaxQueryRange

func (l *Limiter) MaxQueryRange(ctx context.Context, userID string) time.Duration

MaxQueryRange retruns the max query range/interval of a query.

func (*Limiter) QueryTimeout

func (l *Limiter) QueryTimeout(ctx context.Context, userID string) time.Duration

func (*Limiter) RequiredLabels

func (l *Limiter) RequiredLabels(ctx context.Context, userID string) []string

func (*Limiter) RequiredNumberLabels

func (l *Limiter) RequiredNumberLabels(ctx context.Context, userID string) int

type QueryLimits

type QueryLimits struct {
	MaxQueryLength          model.Duration   `json:"maxQueryLength,omitempty"`
	MaxQueryRange           model.Duration   `json:"maxQueryInterval,omitempty"`
	MaxQueryLookback        model.Duration   `json:"maxQueryLookback,omitempty"`
	MaxEntriesLimitPerQuery int              `json:"maxEntriesLimitPerQuery,omitempty"`
	QueryTimeout            model.Duration   `json:"maxQueryTime,omitempty"`
	RequiredLabels          []string         `json:"requiredLabels,omitempty"`
	RequiredNumberLabels    int              `json:"minimumLabelsNumber,omitempty"`
	MaxQueryBytesRead       flagext.ByteSize `json:"maxQueryBytesRead,omitempty"`
}

NOTE: we use custom `model.Duration` instead of standard `time.Duration` because, to support user-friendly duration format (e.g: "1h30m45s") in JSON value.

func ExtractQueryLimitsFromContext added in v3.7.0

func ExtractQueryLimitsFromContext(ctx context.Context) *QueryLimits

ExtractQueryLimitsFromContext gets the embedded limits from the context

func ExtractQueryLimitsHTTP

func ExtractQueryLimitsHTTP(r *http.Request) (*QueryLimits, error)

ExtractQueryLimitsHTTP retrieves the query limit policy from the HTTP header and returns it.

func UnmarshalQueryLimits

func UnmarshalQueryLimits(data []byte) (*QueryLimits, error)

Jump to

Keyboard shortcuts

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