querylimits

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2023 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

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

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 InjectQueryLimitsContext

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

InjectQueryLimitsContext returns a derived context containing the provided query limits

func InjectQueryLimitsHTTP

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

InjectQueryLimitsHTTP adds the query limits to the request headers.

func MarshalQueryLimits

func MarshalQueryLimits(limits *QueryLimits) ([]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

func WrapTripperware

func WrapTripperware(existing queryrangebase.Tripperware) queryrangebase.Tripperware

WrapTripperware wraps the existing tripperware to make sure the query limit policy headers are propagated

Types

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 ExtractQueryLimitsContext

func ExtractQueryLimitsContext(ctx context.Context) *QueryLimits

ExtractQueryLimitsContext 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