Documentation ¶
Index ¶
- Constants
- Variables
- func IsConstantExpr(expr Node) bool
- func IsConstantScalarExpr(expr Node) bool
- func Marshal(node Node) ([]byte, error)
- func Traverse(expr *Node, transform func(*Node))
- func TraverseBottomUp(parent *Node, current *Node, transform func(parent *Node, node *Node) bool) bool
- func TraverseWithParents(parents []*Node, current *Node, transform func(parents []*Node, node *Node))
- func UnsafeUnwrapString(expr Node) string
- func UnwrapFloat(expr Node) (float64, error)
- func UnwrapParens(expr parser.Expr) parser.Expr
- func UnwrapString(expr Node) (string, error)
- type Aggregation
- func (f *Aggregation) Children() []*Node
- func (f *Aggregation) Clone() Node
- func (f *Aggregation) MarshalJSON() ([]byte, error)
- func (f *Aggregation) ReturnType() parser.ValueType
- func (f *Aggregation) String() string
- func (f *Aggregation) Type() NodeType
- func (f *Aggregation) UnmarshalJSON(data []byte) error
- type Binary
- type CheckDuplicateLabels
- type Cloneable
- type Deduplicate
- type DetectHistogramStatsOptimizer
- type DistributedExecutionOptimizer
- type FunctionCall
- type LeafNode
- type MatrixSelector
- type MergeSelectsOptimizer
- type Node
- type NodeType
- type Nodes
- type Noop
- type NumberLiteral
- type Optimizer
- type Parens
- type PassthroughOptimizer
- type Plan
- type PlanOptions
- type Projection
- type PropagateMatchersOptimizer
- type RemoteExecution
- type RemoteExecutions
- type SelectorBatchSize
- type SortMatchers
- type StepInvariantExpr
- type StringLiteral
- type Subquery
- type Traversable
- type Unary
- type UserDefinedExpr
- type VectorSelector
Constants ¶
const ( VectorSelectorNode = "vector_selector" MatrixSelectorNode = "matrix_selector" AggregationNode = "aggregation" BinaryNode = "binary" FunctionNode = "function" NumberLiteralNode = "number_literal" StringLiteralNode = "string_literal" SubqueryNode = "subquery" CheckDuplicateNode = "check_duplicate" StepInvariantNode = "step_invariant" ParensNode = "parens" UnaryNode = "unary" RemoteExecutionNode = "remote_exec" DeduplicateNode = "dedup" NoopNode = "noop" )
Variables ¶
var ( NoOptimizers = []Optimizer{} AllOptimizers = append(DefaultOptimizers, PropagateMatchersOptimizer{}) )
var DefaultOptimizers = []Optimizer{ SortMatchers{}, MergeSelectsOptimizer{}, DetectHistogramStatsOptimizer{}, }
var (
RewrittenExternalLabelWarning = errors.Newf("%s: rewriting an external label with label_replace can disable distributed query execution", annotations.PromQLWarning.Error())
)
Functions ¶
func IsConstantExpr ¶
IsConstantExpr reports if the expression evaluates to a constant.
func IsConstantScalarExpr ¶
IsConstantScalarExpr reports if the expression evaluates to a scalar.
func TraverseBottomUp ¶
func TraverseWithParents ¶
func UnsafeUnwrapString ¶
UnsafeUnwrapString is like UnwrapString but should only be used in cases where the parser guarantees success by already only allowing strings wrapped in parentheses.
func UnwrapFloat ¶
UnwrapFloat recursively unwraps a parser.Expr until it reaches an NumberLiteral.
func UnwrapParens ¶
UnwrapParens recursively unwraps a parser.ParenExpr.
func UnwrapString ¶
UnwrapString recursively unwraps a parser.Expr until it reaches an StringLiteral.
Types ¶
type Aggregation ¶
type Aggregation struct { Op parser.ItemType Expr Node `json:"-"` Param Node `json:"-"` Grouping []string Without bool }
Aggregation represents a PromQL aggregation.
func (*Aggregation) Children ¶
func (f *Aggregation) Children() []*Node
func (*Aggregation) Clone ¶
func (f *Aggregation) Clone() Node
func (*Aggregation) MarshalJSON ¶
func (f *Aggregation) MarshalJSON() ([]byte, error)
func (*Aggregation) ReturnType ¶
func (f *Aggregation) ReturnType() parser.ValueType
func (*Aggregation) String ¶
func (f *Aggregation) String() string
func (*Aggregation) Type ¶
func (f *Aggregation) Type() NodeType
func (*Aggregation) UnmarshalJSON ¶
func (f *Aggregation) UnmarshalJSON(data []byte) error
type Binary ¶
type Binary struct { Op parser.ItemType // The operation of the expression. LHS, RHS Node `json:"-"` // The operands on the respective sides of the operator. // The matching behavior for the operation if both operands are Vectors. // If they are not this field is nil. VectorMatching *parser.VectorMatching // If a comparison operator, return 0/1 rather than filtering. ReturnBool bool ValueType parser.ValueType }
func (*Binary) MarshalJSON ¶
func (*Binary) ReturnType ¶
func (*Binary) UnmarshalJSON ¶
type CheckDuplicateLabels ¶
type CheckDuplicateLabels struct {
Expr Node `json:"-"`
}
CheckDuplicateLabels is a logical node that checks for duplicate labels in the same timestamp.
func (*CheckDuplicateLabels) Children ¶
func (c *CheckDuplicateLabels) Children() []*Node
func (*CheckDuplicateLabels) Clone ¶
func (c *CheckDuplicateLabels) Clone() Node
func (*CheckDuplicateLabels) ReturnType ¶
func (c *CheckDuplicateLabels) ReturnType() parser.ValueType
func (*CheckDuplicateLabels) String ¶
func (c *CheckDuplicateLabels) String() string
func (*CheckDuplicateLabels) Type ¶
func (c *CheckDuplicateLabels) Type() NodeType
type Deduplicate ¶
type Deduplicate struct { LeafNode Expressions RemoteExecutions }
Deduplicate is a logical plan which deduplicates samples from multiple RemoteExecutions.
func (Deduplicate) Clone ¶
func (r Deduplicate) Clone() Node
func (Deduplicate) ReturnType ¶
func (r Deduplicate) ReturnType() parser.ValueType
func (Deduplicate) String ¶
func (r Deduplicate) String() string
func (Deduplicate) Type ¶
func (r Deduplicate) Type() NodeType
type DetectHistogramStatsOptimizer ¶
type DetectHistogramStatsOptimizer struct{}
func (DetectHistogramStatsOptimizer) Optimize ¶
func (d DetectHistogramStatsOptimizer) Optimize(plan Node, _ *query.Options) (Node, annotations.Annotations)
type DistributedExecutionOptimizer ¶
type DistributedExecutionOptimizer struct { Endpoints api.RemoteEndpoints SkipBinaryPushdown bool }
DistributedExecutionOptimizer produces a logical plan suitable for distributed Query execution.
func (DistributedExecutionOptimizer) Optimize ¶
func (m DistributedExecutionOptimizer) Optimize(plan Node, opts *query.Options) (Node, annotations.Annotations)
type FunctionCall ¶
type FunctionCall struct { // The function that was called. Func parser.Function // Arguments passed into the function. Args []Node `json:"-"` }
FunctionCall represents a PromQL function.
func (*FunctionCall) Children ¶
func (f *FunctionCall) Children() []*Node
func (*FunctionCall) Clone ¶
func (f *FunctionCall) Clone() Node
func (*FunctionCall) ReturnType ¶
func (f *FunctionCall) ReturnType() parser.ValueType
func (*FunctionCall) String ¶
func (f *FunctionCall) String() string
func (*FunctionCall) Type ¶
func (f *FunctionCall) Type() NodeType
type MatrixSelector ¶
type MatrixSelector struct { VectorSelector *VectorSelector `json:"-"` Range time.Duration // Needed because this operator is used in the distributed mode OriginalString string }
MatrixSelector is matrix selector with additional configuration set by optimizers. It is used so we can get rid of VectorSelector in distributed mode too.
func (*MatrixSelector) Children ¶
func (f *MatrixSelector) Children() []*Node
func (*MatrixSelector) Clone ¶
func (f *MatrixSelector) Clone() Node
func (*MatrixSelector) ReturnType ¶
func (f *MatrixSelector) ReturnType() parser.ValueType
func (*MatrixSelector) String ¶
func (f *MatrixSelector) String() string
func (*MatrixSelector) Type ¶
func (f *MatrixSelector) Type() NodeType
type MergeSelectsOptimizer ¶
type MergeSelectsOptimizer struct{}
MergeSelectsOptimizer optimizes a binary expression where one select is a superset of the other select. For example, the expression:
metric{a="b", c="d"} / scalar(metric{a="b"}) becomes: Filter(c="d", metric{a="b"}) / scalar(metric{a="b"}).
The engine can then cache the result of `metric{a="b"}` and apply an additional filter for {c="d"}.
func (MergeSelectsOptimizer) Optimize ¶
func (m MergeSelectsOptimizer) Optimize(plan Node, _ *query.Options) (Node, annotations.Annotations)
type Node ¶
type NumberLiteral ¶
NumberLiteral is a logical node representing a literal number.
func (*NumberLiteral) Clone ¶
func (c *NumberLiteral) Clone() Node
func (*NumberLiteral) ReturnType ¶
func (c *NumberLiteral) ReturnType() parser.ValueType
func (*NumberLiteral) String ¶
func (c *NumberLiteral) String() string
func (*NumberLiteral) Type ¶
func (c *NumberLiteral) Type() NodeType
type Optimizer ¶
type Optimizer interface {
Optimize(plan Node, opts *query.Options) (Node, annotations.Annotations)
}
type PassthroughOptimizer ¶
type PassthroughOptimizer struct {
Endpoints api.RemoteEndpoints
}
PassthroughOptimizer optimizes queries which can be simply passed through to a RemoteEngine.
func (PassthroughOptimizer) Optimize ¶
func (m PassthroughOptimizer) Optimize(plan Node, opts *query.Options) (Node, annotations.Annotations)
type Plan ¶
type Plan interface { Optimize([]Optimizer) (Plan, annotations.Annotations) Root() Node MinMaxTime(*query.Options) (int64, int64) }
func New ¶
func New(root Node, queryOpts *query.Options, planOpts PlanOptions) Plan
New creates a new logical plan from logical node.
func NewFromAST ¶
func NewFromBytes ¶
NewFromBytes creates a new logical plan from a byte slice created with Marshal. This method is used to deserialize a logical plan which has been sent over the wire.
type PlanOptions ¶
type PlanOptions struct {
DisableDuplicateLabelCheck bool
}
type Projection ¶
type Projection struct { // Labels is a list of labels to be included or excluded from the selection result, depending on the value of Include. Labels []string // Include is true if only the provided list of labels should be retrieved from storage. // When set to false, the provided list of labels should be excluded from selection. Include bool }
Projection has information on which series labels should be selected from storage.
type PropagateMatchersOptimizer ¶
type PropagateMatchersOptimizer struct{}
PropagateMatchersOptimizer implements matcher propagation between two vector selectors in a binary expression.
func (PropagateMatchersOptimizer) Optimize ¶
func (m PropagateMatchersOptimizer) Optimize(plan Node, _ *query.Options) (Node, annotations.Annotations)
type RemoteExecution ¶
type RemoteExecution struct { LeafNode Engine api.RemoteEngine Query Node QueryRangeStart time.Time }
RemoteExecution is a logical plan that describes a remote execution of a Query against the given PromQL Engine.
func (RemoteExecution) Clone ¶
func (r RemoteExecution) Clone() Node
func (RemoteExecution) ReturnType ¶
func (r RemoteExecution) ReturnType() parser.ValueType
func (RemoteExecution) String ¶
func (r RemoteExecution) String() string
func (RemoteExecution) Type ¶
func (r RemoteExecution) Type() NodeType
type RemoteExecutions ¶
type RemoteExecutions []RemoteExecution
func (RemoteExecutions) String ¶
func (rs RemoteExecutions) String() string
type SelectorBatchSize ¶
type SelectorBatchSize struct {
Size int64
}
SelectorBatchSize configures the batch size of selector based on aggregates present in the plan.
func (SelectorBatchSize) Optimize ¶
func (m SelectorBatchSize) Optimize(plan Node, _ *query.Options) (Node, annotations.Annotations)
Optimize configures the batch size of selector based on the query plan. If any aggregate is present in the plan, the batch size is set to the configured value. The two exceptions where this cannot be done is if the aggregate is quantile, or when a binary expression precedes the aggregate.
type SortMatchers ¶
type SortMatchers struct{}
SortMatchers sorts all matchers in a selector so that all subsequent optimizers, both in the logical and physical plan, can rely on this property.
func (SortMatchers) Optimize ¶
func (m SortMatchers) Optimize(plan Node, _ *query.Options) (Node, annotations.Annotations)
type StepInvariantExpr ¶
type StepInvariantExpr struct {
Expr Node `json:"-"`
}
StepInvariantExpr is a logical node that expresses that the child expression returns the same value at every step in the evaluation.
func (*StepInvariantExpr) Children ¶
func (c *StepInvariantExpr) Children() []*Node
func (*StepInvariantExpr) Clone ¶
func (c *StepInvariantExpr) Clone() Node
func (*StepInvariantExpr) ReturnType ¶
func (c *StepInvariantExpr) ReturnType() parser.ValueType
func (*StepInvariantExpr) String ¶
func (c *StepInvariantExpr) String() string
func (*StepInvariantExpr) Type ¶
func (c *StepInvariantExpr) Type() NodeType
type StringLiteral ¶
StringLiteral is a logical node representing a literal string.
func (*StringLiteral) Clone ¶
func (c *StringLiteral) Clone() Node
func (*StringLiteral) ReturnType ¶
func (c *StringLiteral) ReturnType() parser.ValueType
func (*StringLiteral) String ¶
func (c *StringLiteral) String() string
func (*StringLiteral) Type ¶
func (c *StringLiteral) Type() NodeType
type Subquery ¶
type Subquery struct { Expr Node `json:"-"` Range time.Duration // OriginalOffset is the actual offset that was set in the query. // This never changes. OriginalOffset time.Duration // Offset is the offset used during the query execution // which is calculated using the original offset, at modifier time, // eval time, and subquery offsets in the AST tree. Offset time.Duration Timestamp *int64 Step time.Duration StartOrEnd parser.ItemType }
func (*Subquery) MarshalJSON ¶
func (*Subquery) ReturnType ¶
func (*Subquery) UnmarshalJSON ¶
type Traversable ¶
type Traversable interface {
Children() []*Node
}
type UserDefinedExpr ¶
type UserDefinedExpr interface { Node MakeExecutionOperator( ctx context.Context, vectors *model.VectorPool, opts *query.Options, hints storage.SelectHints, ) (model.VectorOperator, error) }
UserDefinedExpr is an extension point which allows users to define their execution operators.
type VectorSelector ¶
type VectorSelector struct { *parser.VectorSelector LeafNode Filters []*labels.Matcher BatchSize int64 SelectTimestamp bool Projection Projection // When set, histogram iterators can return objects which only have their // CounterResetHint, Count and Sum values populated. Histogram buckets and spans // will not be used during query evaluation. DecodeNativeHistogramStats bool }
VectorSelector is vector selector with additional configuration set by optimizers.
func (*VectorSelector) Clone ¶
func (f *VectorSelector) Clone() Node
func (*VectorSelector) ReturnType ¶
func (f *VectorSelector) ReturnType() parser.ValueType
func (*VectorSelector) String ¶
func (f *VectorSelector) String() string
func (*VectorSelector) Type ¶
func (f *VectorSelector) Type() NodeType