Documentation
¶
Index ¶
- func DetermineLookbackDelta(opts promql.EngineOpts) time.Duration
- func TestMain(m *testing.M)
- type Engine
- func (e *Engine) NewEvaluator(ctx context.Context, queryable storage.Queryable, opts promql.QueryOpts, ...) (*Evaluator, error)
- func (e *Engine) NewInstantQuery(ctx context.Context, q storage.Queryable, opts promql.QueryOpts, qs string, ...) (promql.Query, error)
- func (e *Engine) NewRangeQuery(ctx context.Context, q storage.Queryable, opts promql.QueryOpts, qs string, ...) (promql.Query, error)
- func (e *Engine) RegisterNodeMaterializer(nodeType planning.NodeType, materializer planning.NodeMaterializer) error
- type EngineOpts
- type ErrAnchoredIncompatibleFunction
- type ErrSmoothedIncompatibleFunction
- type EvaluationObserver
- type Evaluator
- type NodeEvaluationRequest
- type NoopPlanningObserver
- func (n NoopPlanningObserver) OnASTStageComplete(string, parser.Expr, time.Duration) error
- func (n NoopPlanningObserver) OnAllASTStagesComplete(parser.Expr) error
- func (n NoopPlanningObserver) OnAllPlanningStagesComplete(*planning.QueryPlan) error
- func (n NoopPlanningObserver) OnPlanningStageComplete(string, *planning.QueryPlan, time.Duration) error
- type NoopQueryTracker
- type PlanningObserver
- type Query
- func (q *Query) Cancel()
- func (q *Query) Close()
- func (q *Query) EvaluationCompleted(_ context.Context, _ *Evaluator, annotations *annotations.Annotations, ...) error
- func (q *Query) Exec(ctx context.Context) (res *promql.Result)
- func (q *Query) InstantVectorSeriesDataEvaluated(_ context.Context, _ *Evaluator, _ planning.Node, seriesIndex int, _ int, ...) error
- func (q *Query) RangeVectorStepSamplesEvaluated(_ context.Context, _ *Evaluator, _ planning.Node, seriesIndex int, ...) error
- func (q *Query) ScalarEvaluated(_ context.Context, _ *Evaluator, _ planning.Node, data types.ScalarData) error
- func (q *Query) SeriesMetadataEvaluated(_ context.Context, _ *Evaluator, _ planning.Node, ...) error
- func (q *Query) Statement() parser.Statement
- func (q *Query) Stats() *promstats.Statistics
- func (q *Query) String() string
- func (q *Query) StringEvaluated(_ context.Context, _ *Evaluator, _ planning.Node, data string) error
- type QueryLimitsProvider
- type QueryPlanVersionProvider
- type QueryPlanner
- func NewQueryPlanner(opts EngineOpts, versionProvider QueryPlanVersionProvider) (*QueryPlanner, error)
- func NewQueryPlannerWithTime(opts EngineOpts, versionProvider QueryPlanVersionProvider, ...) (*QueryPlanner, error)
- func NewQueryPlannerWithoutOptimizationPasses(opts EngineOpts, versionProvider QueryPlanVersionProvider) (*QueryPlanner, error)
- func (p *QueryPlanner) NewQueryPlan(ctx context.Context, qs string, timeRange types.QueryTimeRange, ...) (*planning.QueryPlan, error)
- func (p *QueryPlanner) ParseAndApplyASTOptimizationPasses(ctx context.Context, qs string, timeRange types.QueryTimeRange, ...) (parser.Expr, error)
- func (p *QueryPlanner) RegisterASTOptimizationPass(o optimize.ASTOptimizationPass)
- func (p *QueryPlanner) RegisterQueryPlanOptimizationPass(o optimize.QueryPlanOptimizationPass)
- type QueryTracker
- type RangeVectorSplittingConfig
- type StaticQueryLimitsProvider
- func (p StaticQueryLimitsProvider) GetEnableDelayedNameRemoval(_ context.Context) (bool, error)
- func (p StaticQueryLimitsProvider) GetMaxEstimatedMemoryConsumptionPerQuery(_ context.Context) (uint64, error)
- func (p StaticQueryLimitsProvider) GetMaxOutOfOrderTimeWindow(_ context.Context) (time.Duration, error)
- func (p StaticQueryLimitsProvider) GetMinResultsCacheTTL(_ context.Context) (time.Duration, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DetermineLookbackDelta ¶
func DetermineLookbackDelta(opts promql.EngineOpts) time.Duration
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func NewEngine ¶
func NewEngine(opts EngineOpts, metrics *stats.QueryMetrics, planner *QueryPlanner) (*Engine, error)
func NewEngineWithCache ¶
func NewEngineWithCache(opts EngineOpts, metrics *stats.QueryMetrics, planner *QueryPlanner, intermediateCache *cache.CacheFactory) (*Engine, error)
func (*Engine) NewEvaluator ¶
func (*Engine) NewInstantQuery ¶
func (*Engine) NewRangeQuery ¶
func (*Engine) RegisterNodeMaterializer ¶
type EngineOpts ¶
type EngineOpts struct {
CommonOpts promql.EngineOpts `yaml:"-"`
ActiveQueryTracker QueryTracker `yaml:"-"`
Logger log.Logger `yaml:"-"`
// When operating in pedantic mode, we panic if memory consumption is > 0 after Query.Close()
// (indicating something was not returned to a pool).
// Should only be used in tests.
Pedantic bool `yaml:"-"`
// Prometheus' engine evaluates all selectors (ie. calls Querier.Select()) before evaluating any part of the query.
// We rely on this behavior in query-frontends when evaluating shardable queries so that all selectors are evaluated in parallel.
// When sharding is just another optimization pass, we'll be able to trigger this eager loading from the sharding operator,
// but for now, we use this option to change the behavior of selectors.
EagerLoadSelectors bool `yaml:"-"`
Limits QueryLimitsProvider `yaml:"-"`
EnablePruneToggles bool `yaml:"enable_prune_toggles" category:"experimental"`
EnableCommonSubexpressionElimination bool `yaml:"enable_common_subexpression_elimination" category:"experimental"`
EnableSubsetSelectorElimination bool `yaml:"enable_subset_selector_elimination" category:"experimental"`
EnableNarrowBinarySelectors bool `yaml:"enable_narrow_binary_selectors" category:"experimental"`
EnableEliminateDeduplicateAndMerge bool `yaml:"enable_eliminate_deduplicate_and_merge" category:"experimental"`
EnableReduceMatchers bool `yaml:"enable_reduce_matchers" category:"experimental"`
EnableProjectionPushdown bool `yaml:"enable_projection_pushdown" category:"experimental"`
EnableMultiAggregation bool `yaml:"enable_multi_aggregation" category:"experimental"`
RangeVectorSplitting RangeVectorSplittingConfig `yaml:"range_vector_splitting" category:"experimental"`
}
func NewTestEngineOpts ¶
func NewTestEngineOpts() EngineOpts
func (*EngineOpts) RegisterFlags ¶
func (o *EngineOpts) RegisterFlags(f *flag.FlagSet)
func (*EngineOpts) Validate ¶
func (o *EngineOpts) Validate() error
type ErrAnchoredIncompatibleFunction ¶
type ErrAnchoredIncompatibleFunction struct {
// contains filtered or unexported fields
}
func (ErrAnchoredIncompatibleFunction) Error ¶
func (e ErrAnchoredIncompatibleFunction) Error() string
type ErrSmoothedIncompatibleFunction ¶
type ErrSmoothedIncompatibleFunction struct {
// contains filtered or unexported fields
}
func (ErrSmoothedIncompatibleFunction) Error ¶
func (e ErrSmoothedIncompatibleFunction) Error() string
type EvaluationObserver ¶
type EvaluationObserver interface {
// SeriesMetadataEvaluated notifies this observer when series metadata has been evaluated.
// Implementations of this method are responsible for returning the series slice to the pool when it is no longer needed.
// Implementations of this method may mutate the series slice before returning it to the pool.
SeriesMetadataEvaluated(ctx context.Context, evaluator *Evaluator, node planning.Node, series []types.SeriesMetadata) error
// InstantVectorSeriesDataEvaluated notifies this observer when samples for an instant vector series have been evaluated.
// Implementations of this method are responsible for returning seriesData to the pool when it is no longer needed.
// Implementations of this method may mutate seriesData before returning it to the pool.
InstantVectorSeriesDataEvaluated(ctx context.Context, evaluator *Evaluator, node planning.Node, seriesIndex int, seriesCount int, seriesData types.InstantVectorSeriesData) error
// RangeVectorStepSamplesEvaluated notifies this observer when samples for a range vector step have been evaluated.
// Implementations of this method must not mutate stepData, and should copy any data they wish to retain from stepData before returning.
RangeVectorStepSamplesEvaluated(ctx context.Context, evaluator *Evaluator, node planning.Node, seriesIndex int, stepIndex int, stepData *types.RangeVectorStepData) error
// ScalarEvaluated notifies this observer when a scalar has been evaluated.
// Implementations of this method are responsible for returning data to the pool when it is no longer needed.
// Implementations of this method may mutate data before returning it to the pool.
ScalarEvaluated(ctx context.Context, evaluator *Evaluator, node planning.Node, data types.ScalarData) error
// StringEvaluated notifies this observer when a string has been evaluated.
StringEvaluated(ctx context.Context, evaluator *Evaluator, node planning.Node, data string) error
// EvaluationCompleted notifies this observer when evaluation is complete.
EvaluationCompleted(ctx context.Context, evaluator *Evaluator, annotations *annotations.Annotations, stats *types.QueryStats) error
}
type Evaluator ¶
type Evaluator struct {
MemoryConsumptionTracker *limiter.MemoryConsumptionTracker
// contains filtered or unexported fields
}
func NewEvaluator ¶
func NewEvaluator(nodeRequests []NodeEvaluationRequest, params *planning.OperatorParameters, engine *Engine, originalExpression string) (*Evaluator, error)
func (*Evaluator) Evaluate ¶
func (e *Evaluator) Evaluate(ctx context.Context, observer EvaluationObserver) (err error)
Evaluate evaluates the query.
Evaluate will always call observer.EvaluationCompleted before returning nil. It may return a non-nil error after calling observer.EvaluationCompleted if observer.EvaluationCompleted returned a non-nil error.
type NodeEvaluationRequest ¶
type NodeEvaluationRequest struct {
Node planning.Node
TimeRange types.QueryTimeRange
// contains filtered or unexported fields
}
type NoopPlanningObserver ¶
type NoopPlanningObserver struct{}
func (NoopPlanningObserver) OnASTStageComplete ¶
func (NoopPlanningObserver) OnAllASTStagesComplete ¶
func (n NoopPlanningObserver) OnAllASTStagesComplete(parser.Expr) error
func (NoopPlanningObserver) OnAllPlanningStagesComplete ¶
func (n NoopPlanningObserver) OnAllPlanningStagesComplete(*planning.QueryPlan) error
func (NoopPlanningObserver) OnPlanningStageComplete ¶
type NoopQueryTracker ¶
type NoopQueryTracker struct{}
func (*NoopQueryTracker) Close ¶
func (n *NoopQueryTracker) Close() error
func (*NoopQueryTracker) Delete ¶
func (n *NoopQueryTracker) Delete(_ int)
func (*NoopQueryTracker) GetMaxConcurrent ¶
func (n *NoopQueryTracker) GetMaxConcurrent() int
func (*NoopQueryTracker) InsertWithDetails ¶
func (n *NoopQueryTracker) InsertWithDetails(ctx context.Context, query string, stage string, includeTimeRange bool, timeRange types.QueryTimeRange) (int, error)
type PlanningObserver ¶
type PlanningObserver interface {
OnASTStageComplete(stageName string, updatedExpr parser.Expr, duration time.Duration) error
OnAllASTStagesComplete(finalExpr parser.Expr) error
OnPlanningStageComplete(stageName string, updatedPlan *planning.QueryPlan, duration time.Duration) error
OnAllPlanningStagesComplete(finalPlan *planning.QueryPlan) error
}
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query represents a top-level query. It acts as a bridge from the querying interface Prometheus expects into how MQE operates.
func (*Query) EvaluationCompleted ¶
func (q *Query) EvaluationCompleted(_ context.Context, _ *Evaluator, annotations *annotations.Annotations, stats *types.QueryStats) error
EvaluationCompleted implements the EvaluationObserver interface.
func (*Query) InstantVectorSeriesDataEvaluated ¶
func (q *Query) InstantVectorSeriesDataEvaluated(_ context.Context, _ *Evaluator, _ planning.Node, seriesIndex int, _ int, seriesData types.InstantVectorSeriesData) error
InstantVectorSeriesDataEvaluated implements the EvaluationObserver interface.
func (*Query) RangeVectorStepSamplesEvaluated ¶
func (q *Query) RangeVectorStepSamplesEvaluated(_ context.Context, _ *Evaluator, _ planning.Node, seriesIndex int, stepIndex int, stepData *types.RangeVectorStepData) error
RangeVectorStepSamplesEvaluated implements the EvaluationObserver interface.
func (*Query) ScalarEvaluated ¶
func (q *Query) ScalarEvaluated(_ context.Context, _ *Evaluator, _ planning.Node, data types.ScalarData) error
ScalarEvaluated implements the EvaluationObserver interface.
func (*Query) SeriesMetadataEvaluated ¶
func (q *Query) SeriesMetadataEvaluated(_ context.Context, _ *Evaluator, _ planning.Node, series []types.SeriesMetadata) error
SeriesMetadataEvaluated implements the EvaluationObserver interface.
func (*Query) Stats ¶
func (q *Query) Stats() *promstats.Statistics
type QueryLimitsProvider ¶
type QueryLimitsProvider interface {
// GetMaxEstimatedMemoryConsumptionPerQuery returns the maximum estimated memory allowed to be consumed by a query in bytes, or 0 to disable the limit.
GetMaxEstimatedMemoryConsumptionPerQuery(ctx context.Context) (uint64, error)
// GetEnableDelayedNameRemoval indicates if the experimental feature for delayed name removal should be enabled.
GetEnableDelayedNameRemoval(ctx context.Context) (bool, error)
// GetMaxOutOfOrderTimeWindow returns the out-of-order time window for the tenant(s) in the context.
GetMaxOutOfOrderTimeWindow(ctx context.Context) (time.Duration, error)
// GetMinResultsCacheTTL returns the TTL for cached results for the tenant(s) in the context.
GetMinResultsCacheTTL(ctx context.Context) (time.Duration, error)
}
type QueryPlanVersionProvider ¶
type QueryPlanVersionProvider interface {
GetMaximumSupportedQueryPlanVersion(ctx context.Context) (planning.QueryPlanVersion, error)
}
func NewMaximumSupportedVersionQueryPlanVersionProvider ¶
func NewMaximumSupportedVersionQueryPlanVersionProvider() QueryPlanVersionProvider
NewMaximumSupportedVersionQueryPlanVersionProvider returns a QueryPlanVersionProvider that always returns the maximum supported query plan version. This is intended to be used only in tests.
func NewStaticQueryPlanVersionProvider ¶
func NewStaticQueryPlanVersionProvider(version planning.QueryPlanVersion) QueryPlanVersionProvider
NewStaticQueryPlanVersionProvider returns a QueryPlanVersionProvider that always returns the given version. This is intended to be used only in tests.
type QueryPlanner ¶
type QueryPlanner struct {
// Replaced during testing to ensure timing produces consistent results.
TimeSince func(time.Time) time.Duration
// contains filtered or unexported fields
}
func NewQueryPlanner ¶
func NewQueryPlanner(opts EngineOpts, versionProvider QueryPlanVersionProvider) (*QueryPlanner, error)
func NewQueryPlannerWithTime ¶
func NewQueryPlannerWithTime(opts EngineOpts, versionProvider QueryPlanVersionProvider, timeNow func() time.Time) (*QueryPlanner, error)
NewQueryPlannerWithTime is like NewQueryPlanner but uses the given time function. Useful for tests that need a fixed "now" for OOO window calculations).
func NewQueryPlannerWithoutOptimizationPasses ¶
func NewQueryPlannerWithoutOptimizationPasses(opts EngineOpts, versionProvider QueryPlanVersionProvider) (*QueryPlanner, error)
NewQueryPlannerWithoutOptimizationPasses creates a new query planner without any optimization passes registered.
This is intended for use in tests only.
func (*QueryPlanner) NewQueryPlan ¶
func (p *QueryPlanner) NewQueryPlan(ctx context.Context, qs string, timeRange types.QueryTimeRange, enableDelayedNameRemoval bool, observer PlanningObserver) (*planning.QueryPlan, error)
func (*QueryPlanner) ParseAndApplyASTOptimizationPasses ¶
func (p *QueryPlanner) ParseAndApplyASTOptimizationPasses(ctx context.Context, qs string, timeRange types.QueryTimeRange, observer PlanningObserver) (parser.Expr, error)
ParseAndApplyASTOptimizationPasses runs the AST optimization passes on the input string and outputs an expression and any error encountered. This is separated into its own method to allow testing of AST optimization passes.
func (*QueryPlanner) RegisterASTOptimizationPass ¶
func (p *QueryPlanner) RegisterASTOptimizationPass(o optimize.ASTOptimizationPass)
RegisterASTOptimizationPass registers an AST optimization pass used with this engine.
This method is not thread-safe and must not be called concurrently with any other method on this type.
func (*QueryPlanner) RegisterQueryPlanOptimizationPass ¶
func (p *QueryPlanner) RegisterQueryPlanOptimizationPass(o optimize.QueryPlanOptimizationPass)
RegisterQueryPlanOptimizationPass registers a query plan optimization pass used with this engine.
This method is not thread-safe and must not be called concurrently with any other method on this type.
type QueryTracker ¶
type QueryTracker interface {
InsertWithDetails(ctx context.Context, query string, stage string, includeTimeRange bool, timeRange types.QueryTimeRange) (int, error)
Delete(insertIndex int)
}
QueryTracker is like promql.QueryTracker, but includes more information about the query.
type RangeVectorSplittingConfig ¶
type RangeVectorSplittingConfig struct {
Enabled bool `yaml:"enabled" category:"experimental"`
// SplitInterval is the time interval used for splitting.
// Must be greater than 0. Defaults to 2 hours if not specified.
SplitInterval time.Duration `yaml:"split_interval" category:"experimental"`
// IntermediateResultsCache configures caching of intermediate results from split queries.
// TODO: consider making the cache an optional part of query splitting. We might want to just do query splitting
// without caching (e.g. possibly if splitting is extended to range queries in the future, or if we add
// parallelisation and just want to use query splitting for that and not cache).
IntermediateResultsCache cache.Config `yaml:"intermediate_results_cache" category:"experimental"`
}
RangeVectorSplittingConfig configures the splitting of functions over range vectors queries.
func (*RangeVectorSplittingConfig) RegisterFlags ¶
func (c *RangeVectorSplittingConfig) RegisterFlags(f *flag.FlagSet)
func (*RangeVectorSplittingConfig) Validate ¶
func (c *RangeVectorSplittingConfig) Validate() error
type StaticQueryLimitsProvider ¶
type StaticQueryLimitsProvider struct {
MaxEstimatedMemoryConsumptionPerQuery uint64
EnableDelayedNameRemoval bool
MaxOutOfOrderTimeWindow time.Duration
MinResultsCacheTTL time.Duration
}
func NewStaticQueryLimitsProvider ¶
func NewStaticQueryLimitsProvider() StaticQueryLimitsProvider
NewStaticQueryLimitsProvider returns a QueryLimitsProvider that always returns the provided limits. This should generally only be used in tests.
func (StaticQueryLimitsProvider) GetEnableDelayedNameRemoval ¶
func (p StaticQueryLimitsProvider) GetEnableDelayedNameRemoval(_ context.Context) (bool, error)
func (StaticQueryLimitsProvider) GetMaxEstimatedMemoryConsumptionPerQuery ¶
func (p StaticQueryLimitsProvider) GetMaxEstimatedMemoryConsumptionPerQuery(_ context.Context) (uint64, error)