Documentation ¶
Index ¶
- Constants
- Variables
- func DocumentedType(t ValueType) string
- func Inspect(node Node, f inspector)
- func MustLabelMatcher(mt labels.MatchType, name, val string) *labels.Matcher
- func ParseMetric(input string) (m labels.Labels, err error)
- func ParseMetricSelector(input string) (m []*labels.Matcher, err error)
- func Tree(node Node) string
- func Walk(v Visitor, node Node, path []Node) error
- type AggregateExpr
- type BinaryExpr
- type Call
- type EvalStmt
- type Expr
- type Expressions
- type Function
- type Item
- type ItemType
- type Lexer
- type MatrixSelector
- type Node
- type NumberLiteral
- type ParenExpr
- type ParseErr
- type ParseErrors
- type Pos
- type PositionRange
- type SequenceValue
- type Statement
- type StepInvariantExpr
- type StringLiteral
- type SubqueryExpr
- type TestStmt
- type UnaryExpr
- type Value
- type ValueType
- type VectorMatchCardinality
- type VectorMatching
- type VectorSelector
- type Visitor
Constants ¶
const ADD = 57368
const AT = 57385
const AVG = 57388
const BLANK = 57347
const BOOL = 57402
const BOTTOMK = 57389
const BY = 57403
const COLON = 57348
const COMMA = 57349
const COMMENT = 57350
const COUNT = 57390
const COUNT_VALUES = 57391
const DIV = 57369
const DURATION = 57351
const END = 57413
const EOF = 57352
const EQL = 57346
const EQLC = 57370
const EQL_REGEX = 57371
const ERROR = 57353
const GROUP = 57392
const GROUP_LEFT = 57404
const GROUP_RIGHT = 57405
const GTE = 57372
const GTR = 57373
const IDENTIFIER = 57354
const IGNORING = 57406
const LAND = 57374
const LEFT_BRACE = 57355
const LEFT_BRACKET = 57356
const LEFT_PAREN = 57357
const LOR = 57375
const LSS = 57376
const LTE = 57377
const LUNLESS = 57378
const MAX = 57393
const METRIC_IDENTIFIER = 57358
const MIN = 57394
const MOD = 57379
const MUL = 57380
const NEQ = 57381
const NEQ_REGEX = 57382
const NUMBER = 57359
const OFFSET = 57407
const ON = 57408
const POW = 57383
const QUANTILE = 57395
const RIGHT_BRACE = 57360
const RIGHT_BRACKET = 57361
const RIGHT_PAREN = 57362
const SEMICOLON = 57363
const SPACE = 57364
const START = 57412
const START_EXPRESSION = 57418
const START_METRIC = 57416
const START_METRIC_SELECTOR = 57419
const START_SERIES_DESCRIPTION = 57417
const STDDEV = 57396
const STDVAR = 57397
const STRING = 57365
const SUB = 57384
const SUM = 57398
const TIMES = 57366
const TOPK = 57399
const WITHOUT = 57409
Variables ¶
var Functions = map[string]*Function{ "abs": { Name: "abs", ArgTypes: []ValueType{ValueTypeVector}, ReturnType: ValueTypeVector, }, "absent": { Name: "absent", ArgTypes: []ValueType{ValueTypeVector}, ReturnType: ValueTypeVector, }, "absent_over_time": { Name: "absent_over_time", ArgTypes: []ValueType{ValueTypeMatrix}, ReturnType: ValueTypeVector, }, "avg_over_time": { Name: "avg_over_time", ArgTypes: []ValueType{ValueTypeMatrix}, ReturnType: ValueTypeVector, }, "ceil": { Name: "ceil", ArgTypes: []ValueType{ValueTypeVector}, ReturnType: ValueTypeVector, }, "changes": { Name: "changes", ArgTypes: []ValueType{ValueTypeMatrix}, ReturnType: ValueTypeVector, }, "clamp_max": { Name: "clamp_max", ArgTypes: []ValueType{ValueTypeVector, ValueTypeScalar}, ReturnType: ValueTypeVector, }, "clamp_min": { Name: "clamp_min", ArgTypes: []ValueType{ValueTypeVector, ValueTypeScalar}, ReturnType: ValueTypeVector, }, "count_over_time": { Name: "count_over_time", ArgTypes: []ValueType{ValueTypeMatrix}, ReturnType: ValueTypeVector, }, "days_in_month": { Name: "days_in_month", ArgTypes: []ValueType{ValueTypeVector}, Variadic: 1, ReturnType: ValueTypeVector, }, "day_of_month": { Name: "day_of_month", ArgTypes: []ValueType{ValueTypeVector}, Variadic: 1, ReturnType: ValueTypeVector, }, "day_of_week": { Name: "day_of_week", ArgTypes: []ValueType{ValueTypeVector}, Variadic: 1, ReturnType: ValueTypeVector, }, "delta": { Name: "delta", ArgTypes: []ValueType{ValueTypeMatrix}, ReturnType: ValueTypeVector, }, "deriv": { Name: "deriv", ArgTypes: []ValueType{ValueTypeMatrix}, ReturnType: ValueTypeVector, }, "exp": { Name: "exp", ArgTypes: []ValueType{ValueTypeVector}, ReturnType: ValueTypeVector, }, "floor": { Name: "floor", ArgTypes: []ValueType{ValueTypeVector}, ReturnType: ValueTypeVector, }, "histogram_quantile": { Name: "histogram_quantile", ArgTypes: []ValueType{ValueTypeScalar, ValueTypeVector}, ReturnType: ValueTypeVector, }, "holt_winters": { Name: "holt_winters", ArgTypes: []ValueType{ValueTypeMatrix, ValueTypeScalar, ValueTypeScalar}, ReturnType: ValueTypeVector, }, "hour": { Name: "hour", ArgTypes: []ValueType{ValueTypeVector}, Variadic: 1, ReturnType: ValueTypeVector, }, "idelta": { Name: "idelta", ArgTypes: []ValueType{ValueTypeMatrix}, ReturnType: ValueTypeVector, }, "increase": { Name: "increase", ArgTypes: []ValueType{ValueTypeMatrix}, ReturnType: ValueTypeVector, }, "irate": { Name: "irate", ArgTypes: []ValueType{ValueTypeMatrix}, ReturnType: ValueTypeVector, }, "label_replace": { Name: "label_replace", ArgTypes: []ValueType{ValueTypeVector, ValueTypeString, ValueTypeString, ValueTypeString, ValueTypeString}, ReturnType: ValueTypeVector, }, "label_join": { Name: "label_join", ArgTypes: []ValueType{ValueTypeVector, ValueTypeString, ValueTypeString, ValueTypeString}, Variadic: -1, ReturnType: ValueTypeVector, }, "ln": { Name: "ln", ArgTypes: []ValueType{ValueTypeVector}, ReturnType: ValueTypeVector, }, "log10": { Name: "log10", ArgTypes: []ValueType{ValueTypeVector}, ReturnType: ValueTypeVector, }, "log2": { Name: "log2", ArgTypes: []ValueType{ValueTypeVector}, ReturnType: ValueTypeVector, }, "max_over_time": { Name: "max_over_time", ArgTypes: []ValueType{ValueTypeMatrix}, ReturnType: ValueTypeVector, }, "min_over_time": { Name: "min_over_time", ArgTypes: []ValueType{ValueTypeMatrix}, ReturnType: ValueTypeVector, }, "minute": { Name: "minute", ArgTypes: []ValueType{ValueTypeVector}, Variadic: 1, ReturnType: ValueTypeVector, }, "month": { Name: "month", ArgTypes: []ValueType{ValueTypeVector}, Variadic: 1, ReturnType: ValueTypeVector, }, "predict_linear": { Name: "predict_linear", ArgTypes: []ValueType{ValueTypeMatrix, ValueTypeScalar}, ReturnType: ValueTypeVector, }, "quantile_over_time": { Name: "quantile_over_time", ArgTypes: []ValueType{ValueTypeScalar, ValueTypeMatrix}, ReturnType: ValueTypeVector, }, "rate": { Name: "rate", ArgTypes: []ValueType{ValueTypeMatrix}, ReturnType: ValueTypeVector, }, "resets": { Name: "resets", ArgTypes: []ValueType{ValueTypeMatrix}, ReturnType: ValueTypeVector, }, "round": { Name: "round", ArgTypes: []ValueType{ValueTypeVector, ValueTypeScalar}, Variadic: 1, ReturnType: ValueTypeVector, }, "scalar": { Name: "scalar", ArgTypes: []ValueType{ValueTypeVector}, ReturnType: ValueTypeScalar, }, "sort": { Name: "sort", ArgTypes: []ValueType{ValueTypeVector}, ReturnType: ValueTypeVector, }, "sort_desc": { Name: "sort_desc", ArgTypes: []ValueType{ValueTypeVector}, ReturnType: ValueTypeVector, }, "sqrt": { Name: "sqrt", ArgTypes: []ValueType{ValueTypeVector}, ReturnType: ValueTypeVector, }, "stddev_over_time": { Name: "stddev_over_time", ArgTypes: []ValueType{ValueTypeMatrix}, ReturnType: ValueTypeVector, }, "stdvar_over_time": { Name: "stdvar_over_time", ArgTypes: []ValueType{ValueTypeMatrix}, ReturnType: ValueTypeVector, }, "sum_over_time": { Name: "sum_over_time", ArgTypes: []ValueType{ValueTypeMatrix}, ReturnType: ValueTypeVector, }, "time": { Name: "time", ArgTypes: []ValueType{}, ReturnType: ValueTypeScalar, }, "timestamp": { Name: "timestamp", ArgTypes: []ValueType{ValueTypeVector}, ReturnType: ValueTypeVector, }, "vector": { Name: "vector", ArgTypes: []ValueType{ValueTypeScalar}, ReturnType: ValueTypeVector, }, "year": { Name: "year", ArgTypes: []ValueType{ValueTypeVector}, Variadic: 1, ReturnType: ValueTypeVector, }, }
Functions is a list of all functions supported by PromQL, including their types.
var ItemTypeStr = map[ItemType]string{
LEFT_PAREN: "(",
RIGHT_PAREN: ")",
LEFT_BRACE: "{",
RIGHT_BRACE: "}",
LEFT_BRACKET: "[",
RIGHT_BRACKET: "]",
COMMA: ",",
EQL: "=",
COLON: ":",
SEMICOLON: ";",
BLANK: "_",
TIMES: "x",
SPACE: "<space>",
SUB: "-",
ADD: "+",
MUL: "*",
MOD: "%",
DIV: "/",
EQLC: "==",
NEQ: "!=",
LTE: "<=",
LSS: "<",
GTE: ">=",
GTR: ">",
EQL_REGEX: "=~",
NEQ_REGEX: "!~",
POW: "^",
}
ItemTypeStr is the default string representations for common Items. It does not imply that those are the only character sequences that can be lexed to such an Item.
Functions ¶
func DocumentedType ¶
DocumentedType returns the internal type to the equivalent user facing terminology as defined in the documentation.
func Inspect ¶
func Inspect(node Node, f inspector)
Inspect traverses an AST in depth-first order: It starts by calling f(node, path); node must not be nil. If f returns a nil error, Inspect invokes f for all the non-nil children of node, recursively.
func MustLabelMatcher ¶
func ParseMetric ¶
ParseMetric parses the input into a metric
func ParseMetricSelector ¶
ParseMetricSelector parses the provided textual metric selector into a list of label matchers.
func Walk ¶
Walk traverses an AST in depth-first order: It starts by calling v.Visit(node, path); node must not be nil. If the visitor w returned by v.Visit(node, path) is not nil and the visitor returns no error, Walk is invoked recursively with visitor w for each of the non-nil children of node, followed by a call of w.Visit(nil), returning an error As the tree is descended the path of previous nodes is provided.
Types ¶
type AggregateExpr ¶
type AggregateExpr struct { Op ItemType // The used aggregation operation. Expr Expr // The Vector expression over which is aggregated. Param Expr // Parameter used by some aggregators. Grouping []string // The labels by which to group the Vector. Without bool // Whether to drop the given labels rather than keep them. PosRange PositionRange }
AggregateExpr represents an aggregation operation on a Vector.
func (*AggregateExpr) PositionRange ¶
func (e *AggregateExpr) PositionRange() PositionRange
func (*AggregateExpr) PromQLExpr ¶
func (*AggregateExpr) PromQLExpr()
func (*AggregateExpr) String ¶
func (node *AggregateExpr) String() string
func (*AggregateExpr) Type ¶
func (e *AggregateExpr) Type() ValueType
type BinaryExpr ¶
type BinaryExpr struct { Op ItemType // The operation of the expression. LHS, RHS Expr // 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 *VectorMatching // If a comparison operator, return 0/1 rather than filtering. ReturnBool bool }
BinaryExpr represents a binary expression between two child expressions.
func (*BinaryExpr) PositionRange ¶
func (e *BinaryExpr) PositionRange() PositionRange
func (*BinaryExpr) PromQLExpr ¶
func (*BinaryExpr) PromQLExpr()
func (*BinaryExpr) String ¶
func (node *BinaryExpr) String() string
func (*BinaryExpr) Type ¶
func (e *BinaryExpr) Type() ValueType
type Call ¶
type Call struct { Func *Function // The function that was called. Args Expressions // Arguments used in the call. PosRange PositionRange }
Call represents a function call.
func (*Call) PositionRange ¶
func (e *Call) PositionRange() PositionRange
func (*Call) PromQLExpr ¶
func (*Call) PromQLExpr()
type EvalStmt ¶
type EvalStmt struct { Expr Expr // Expression to be evaluated. // The time boundaries for the evaluation. If Start equals End an instant // is evaluated. Start, End time.Time // Time between two evaluated instants for the range [Start:End]. Interval time.Duration }
EvalStmt holds an expression and information on the range it should be evaluated on.
func (*EvalStmt) PositionRange ¶
func (e *EvalStmt) PositionRange() PositionRange
func (*EvalStmt) PromQLStmt ¶
func (*EvalStmt) PromQLStmt()
type Expr ¶
type Expr interface { Node // Type returns the type the expression evaluates to. It does not perform // in-depth checks as this is done at parsing-time. Type() ValueType // PromQLExpr ensures that no other types accidentally implement the interface. PromQLExpr() }
Expr is a generic interface for all expression types.
type Expressions ¶
type Expressions []Expr
Expressions is a list of expression nodes that implements Node.
func (Expressions) PositionRange ¶
func (e Expressions) PositionRange() PositionRange
func (Expressions) String ¶
func (es Expressions) String() (s string)
type Function ¶
Function represents a function of the expression language and is used by function nodes.
func MustGetFunction ¶
type Item ¶
type Item struct { Typ ItemType // The type of this Item. Pos Pos // The starting position, in bytes, of this Item in the input string. Val string // The value of this Item. }
Item represents a token or text string returned from the scanner.
func (*Item) PositionRange ¶
func (i *Item) PositionRange() PositionRange
Item implements the Node interface. This makes it possible to call mergeRanges on them.
type ItemType ¶
type ItemType int
func (ItemType) IsAggregator ¶
IsAggregator returns true if the Item belongs to the aggregator functions. Returns false otherwise
func (ItemType) IsAggregatorWithParam ¶
IsAggregatorWithParam returns true if the Item is an aggregator that takes a parameter. Returns false otherwise
func (ItemType) IsComparisonOperator ¶
IsComparisonOperator returns true if the Item corresponds to a comparison operator. Returns false otherwise.
func (ItemType) IsKeyword ¶
IsKeyword returns true if the Item corresponds to a keyword. Returns false otherwise.
func (ItemType) IsOperator ¶
IsOperator returns true if the Item corresponds to a arithmetic or set operator. Returns false otherwise.
func (ItemType) IsSetOperator ¶
IsSetOperator returns whether the Item corresponds to a set operator.
type Lexer ¶
type Lexer struct {
// contains filtered or unexported fields
}
Lexer holds the state of the scanner.
type MatrixSelector ¶
type MatrixSelector struct { // It is safe to assume that this is an VectorSelector // if the parser hasn't returned an error. VectorSelector Expr Range time.Duration EndPos Pos }
MatrixSelector represents a Matrix selection.
func (*MatrixSelector) PositionRange ¶
func (e *MatrixSelector) PositionRange() PositionRange
func (*MatrixSelector) PromQLExpr ¶
func (*MatrixSelector) PromQLExpr()
func (*MatrixSelector) String ¶
func (node *MatrixSelector) String() string
func (*MatrixSelector) Type ¶
func (e *MatrixSelector) Type() ValueType
type Node ¶
type Node interface { // String representation of the node that returns the given node when parsed // as part of a valid query. String() string // PositionRange returns the position of the AST Node in the query string. PositionRange() PositionRange }
Node is a generic interface for all nodes in an AST.
Whenever numerous nodes are listed such as in a switch-case statement or a chain of function definitions (e.g. String(), PromQLExpr(), etc.) convention is to list them as follows:
- Statements
- statement types (alphabetical)
- ...
- Expressions
- expression types (alphabetical)
- ...
type NumberLiteral ¶
type NumberLiteral struct { Val float64 PosRange PositionRange }
NumberLiteral represents a number.
func (*NumberLiteral) PositionRange ¶
func (e *NumberLiteral) PositionRange() PositionRange
func (*NumberLiteral) PromQLExpr ¶
func (*NumberLiteral) PromQLExpr()
func (*NumberLiteral) String ¶
func (node *NumberLiteral) String() string
func (*NumberLiteral) Type ¶
func (e *NumberLiteral) Type() ValueType
type ParenExpr ¶
type ParenExpr struct { Expr Expr PosRange PositionRange }
ParenExpr wraps an expression so it cannot be disassembled as a consequence of operator precedence.
func (*ParenExpr) PositionRange ¶
func (e *ParenExpr) PositionRange() PositionRange
func (*ParenExpr) PromQLExpr ¶
func (*ParenExpr) PromQLExpr()
type ParseErr ¶
type ParseErr struct { PositionRange PositionRange Err error Query string // LineOffset is an additional line offset to be added. Only used inside unit tests. LineOffset int }
ParseErr wraps a parsing error with line and position context.
type ParseErrors ¶
type ParseErrors []ParseErr
func (ParseErrors) Error ¶
func (errs ParseErrors) Error() string
Since producing multiple error messages might look weird when combined with error wrapping, only the first error produced by the parser is included in the error string. If getting the full error list is desired, it is recommended to typecast the error returned by the parser to ParseErrors and work with the underlying slice.
type Pos ¶
type Pos int
Pos is the position in a string. Negative numbers indicate undefined positions.
type PositionRange ¶
PositionRange describes a position in the input string of the parser.
type SequenceValue ¶
SequenceValue is an omittable value in a sequence of time series values.
func ParseSeriesDesc ¶
func ParseSeriesDesc(input string) (labels labels.Labels, values []SequenceValue, err error)
ParseSeriesDesc parses the description of a time series.
func (SequenceValue) String ¶
func (v SequenceValue) String() string
type Statement ¶
type Statement interface { Node // PromQLStmt ensures that no other type accidentally implements the interface // nolint:unused PromQLStmt() }
Statement is a generic interface for all statements.
type StepInvariantExpr ¶
type StepInvariantExpr struct {
Expr Expr
}
StepInvariantExpr represents a query which evaluates to the same result irrespective of the evaluation time given the raw samples from TSDB remain unchanged. Currently this is only used for engine optimisations and the parser does not produce this.
func (*StepInvariantExpr) PositionRange ¶
func (e *StepInvariantExpr) PositionRange() PositionRange
func (*StepInvariantExpr) PromQLExpr ¶
func (*StepInvariantExpr) PromQLExpr()
func (*StepInvariantExpr) String ¶
func (e *StepInvariantExpr) String() string
func (*StepInvariantExpr) Type ¶
func (e *StepInvariantExpr) Type() ValueType
type StringLiteral ¶
type StringLiteral struct { Val string PosRange PositionRange }
StringLiteral represents a string.
func (*StringLiteral) PositionRange ¶
func (e *StringLiteral) PositionRange() PositionRange
func (*StringLiteral) PromQLExpr ¶
func (*StringLiteral) PromQLExpr()
func (*StringLiteral) String ¶
func (node *StringLiteral) String() string
func (*StringLiteral) Type ¶
func (e *StringLiteral) Type() ValueType
type SubqueryExpr ¶
type SubqueryExpr struct { Expr Expr 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 StartOrEnd ItemType // Set when @ is used with start() or end() Step time.Duration EndPos Pos }
SubqueryExpr represents a subquery.
func (*SubqueryExpr) PositionRange ¶
func (e *SubqueryExpr) PositionRange() PositionRange
func (*SubqueryExpr) PromQLExpr ¶
func (*SubqueryExpr) PromQLExpr()
func (*SubqueryExpr) String ¶
func (node *SubqueryExpr) String() string
func (*SubqueryExpr) Type ¶
func (e *SubqueryExpr) Type() ValueType
type TestStmt ¶
TestStmt is an internal helper statement that allows execution of an arbitrary function during handling. It is used to test the Engine.
func (TestStmt) PositionRange ¶
func (TestStmt) PositionRange() PositionRange
func (TestStmt) PromQLStmt ¶
func (TestStmt) PromQLStmt()
type UnaryExpr ¶
UnaryExpr represents a unary operation on another expression. Currently unary operations are only supported for Scalars.
func (*UnaryExpr) PositionRange ¶
func (e *UnaryExpr) PositionRange() PositionRange
func (*UnaryExpr) PromQLExpr ¶
func (*UnaryExpr) PromQLExpr()
type VectorMatchCardinality ¶
type VectorMatchCardinality int
VectorMatchCardinality describes the cardinality relationship of two Vectors in a binary operation.
const ( CardOneToOne VectorMatchCardinality = iota CardManyToOne CardOneToMany CardManyToMany )
func (VectorMatchCardinality) String ¶
func (vmc VectorMatchCardinality) String() string
type VectorMatching ¶
type VectorMatching struct { // The cardinality of the two Vectors. Card VectorMatchCardinality // MatchingLabels contains the labels which define equality of a pair of // elements from the Vectors. MatchingLabels []string // On includes the given label names from matching, // rather than excluding them. On bool // Include contains additional labels that should be included in // the result from the side with the lower cardinality. Include []string }
VectorMatching describes how elements from two Vectors in a binary operation are supposed to be matched.
type VectorSelector ¶
type VectorSelector struct { Name string // 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 StartOrEnd ItemType // Set when @ is used with start() or end() LabelMatchers []*labels.Matcher // The unexpanded seriesSet populated at query preparation time. UnexpandedSeriesSet storage.SeriesSet Series []storage.Series PosRange PositionRange }
VectorSelector represents a Vector selection.
func (*VectorSelector) PositionRange ¶
func (e *VectorSelector) PositionRange() PositionRange
func (*VectorSelector) PromQLExpr ¶
func (*VectorSelector) PromQLExpr()
func (*VectorSelector) String ¶
func (node *VectorSelector) String() string
func (*VectorSelector) Type ¶
func (e *VectorSelector) Type() ValueType
type Visitor ¶
Visitor allows visiting a Node and its child nodes. The Visit method is invoked for each node with the path leading to the node provided additionally. If the result visitor w is not nil and no error, Walk visits each of the children of node with the visitor w, followed by a call of w.Visit(nil, nil).