queryeviction

package
v1.22.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrQueryEvicted

type ErrQueryEvicted struct{}

ErrQueryEvicted is returned when a query is cancelled by the evictor.

func (*ErrQueryEvicted) Error

func (e *ErrQueryEvicted) Error() string

type MetricFunc

type MetricFunc func(s *querier_stats.QueryStats) uint64

MetricFunc extracts a comparable weight value from QueryStats. Higher values mean "heavier" query.

func ResolveMetricFunc

func ResolveMetricFunc(metricName string) (MetricFunc, error)

ResolveMetricFunc returns the MetricFunc for the given metric name. An empty string defaults to "fetched_samples".

type QueryEntry

type QueryEntry struct {
	QueryID      uint64
	Cancel       context.CancelFunc
	Stats        *querier_stats.QueryStats
	QueryExpr    string // PromQL expression for logging
	UserID       string // tenant ID for logging/metrics
	RequestID    string // request ID for correlation
	RegisteredAt time.Time
}

QueryEntry represents a single running query in the registry.

type QueryEvictor

type QueryEvictor struct {
	services.Service
	// contains filtered or unexported fields
}

QueryEvictor monitors system-wide resource utilization and evicts the heaviest running query when thresholds are breached.

func NewQueryEvictor

func NewQueryEvictor(
	monitor resource.IMonitor,
	registry *QueryRegistry,
	cfg configs.EvictionConfig,
	logger log.Logger,
	reg prometheus.Registerer,
	component string,
) *QueryEvictor

NewQueryEvictor creates a new evictor. Returns nil if config is disabled.

type QueryRegistry

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

QueryRegistry tracks all currently running queries.

func NewQueryRegistry

func NewQueryRegistry(metric MetricFunc) *QueryRegistry

NewQueryRegistry creates a registry with the given metric function.

func (*QueryRegistry) Deregister

func (r *QueryRegistry) Deregister(id uint64)

Deregister removes a query from the registry. It is a no-op if the ID is not found.

func (*QueryRegistry) FindHeaviest

func (r *QueryRegistry) FindHeaviest(n int, minAge time.Duration) []*QueryEntry

FindHeaviest returns up to n entries with the highest metric values among queries that have been running for at least minAge, sorted heaviest first. Returns nil if no eligible queries exist.

func (*QueryRegistry) Len

func (r *QueryRegistry) Len() int

Len returns the number of currently registered queries.

func (*QueryRegistry) Register

func (r *QueryRegistry) Register(cancel context.CancelFunc, stats *querier_stats.QueryStats, queryExpr string, userID string, requestID string) uint64

Register adds a running query and returns its unique, monotonically increasing ID.

type ResourceEvictingEngine

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

ResourceEvictingEngine wraps a QueryEngine to register running queries with a QueryRegistry, enabling resource-based eviction.

func NewResourceEvictingEngine

func NewResourceEvictingEngine(inner engine.QueryEngine, registry *QueryRegistry) *ResourceEvictingEngine

NewResourceEvictingEngine wraps the given engine. If registry is nil, the wrapper is a no-op passthrough.

func (*ResourceEvictingEngine) MakeInstantQueryFromPlan

func (e *ResourceEvictingEngine) MakeInstantQueryFromPlan(ctx context.Context, q storage.Queryable, opts promql.QueryOpts, root logicalplan.Node, ts time.Time, qs string) (promql.Query, error)

func (*ResourceEvictingEngine) MakeRangeQueryFromPlan

func (e *ResourceEvictingEngine) MakeRangeQueryFromPlan(ctx context.Context, q storage.Queryable, opts promql.QueryOpts, root logicalplan.Node, start time.Time, end time.Time, interval time.Duration, qs string) (promql.Query, error)

func (*ResourceEvictingEngine) NewInstantQuery

func (e *ResourceEvictingEngine) NewInstantQuery(ctx context.Context, q storage.Queryable, opts promql.QueryOpts, qs string, ts time.Time) (promql.Query, error)

func (*ResourceEvictingEngine) NewRangeQuery

func (e *ResourceEvictingEngine) NewRangeQuery(ctx context.Context, q storage.Queryable, opts promql.QueryOpts, qs string, start, end time.Time, interval time.Duration) (promql.Query, error)

Jump to

Keyboard shortcuts

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