Documentation ¶
Index ¶
- Constants
- func Inspect(node Node, f func(Node) bool)
- func Tree(node Node) string
- func Walk(v Visitor, node Node)
- type AggregateExpr
- type AlertStmt
- type Analyzer
- type BinaryExpr
- type Call
- type Engine
- type ErrQueryCanceled
- type ErrQueryTimeout
- type EvalStmt
- type Expr
- type ExprType
- type Expressions
- type Function
- type Matrix
- type MatrixSelector
- type Node
- type NumberLiteral
- type ParenExpr
- type ParseErr
- type Pos
- type Query
- type RecordStmt
- type Result
- type Sample
- type SampleStream
- type Scalar
- type Statement
- type Statements
- type String
- type StringLiteral
- type Test
- type UnaryExpr
- type Value
- type Vector
- type VectorMatchCardinality
- type VectorMatching
- type VectorSelector
- type Visitor
Constants ¶
const LowestPrec = 0 // Non-operators.
Constants for operator precedence in expressions.
Variables ¶
This section is empty.
Functions ¶
func Inspect ¶
Inspect traverses an AST in depth-first order: It starts by calling f(node); node must not be nil. If f returns true, Inspect invokes f for all the non-nil children of node, recursively.
Types ¶
type AggregateExpr ¶
type AggregateExpr struct { Op itemType // The used aggregation operation. Expr Expr // The vector expression over which is aggregated. Grouping clientmodel.LabelNames // The labels by which to group the vector. KeepExtraLabels bool // Whether to keep extra labels common among result elements. }
AggregateExpr represents an aggregation operation on a vector.
func (*AggregateExpr) DotGraph ¶
func (node *AggregateExpr) DotGraph() string
DotGraph returns a DOT representation of the vector aggregation.
func (*AggregateExpr) String ¶
func (node *AggregateExpr) String() string
func (*AggregateExpr) Type ¶
func (e *AggregateExpr) Type() ExprType
type AlertStmt ¶
type AlertStmt struct { Name string Expr Expr Duration time.Duration Labels clientmodel.LabelSet Summary string Description string }
AlertStmt represents an added alert rule.
type Analyzer ¶
type Analyzer struct { // The storage from which to query data. Storage local.Storage // The expression being analyzed. Expr Expr // The time range for evaluation of Expr. Start, End clientmodel.Timestamp // contains filtered or unexported fields }
An Analyzer traverses an expression and determines which data has to be requested from the storage. It is bound to a context that allows cancellation and timing out.
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 }
BinaryExpr represents a binary expression between two child expressions.
func (*BinaryExpr) DotGraph ¶
func (node *BinaryExpr) DotGraph() string
DotGraph returns a DOT representation of the expression.
func (*BinaryExpr) String ¶
func (node *BinaryExpr) String() string
func (*BinaryExpr) Type ¶
func (e *BinaryExpr) Type() ExprType
type Call ¶
type Call struct { Func *Function // The function that was called. Args Expressions // Arguments used in the call. }
Call represents a function call.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine handles the liftetime of queries from beginning to end. It is connected to a storage.
func (*Engine) NewInstantQuery ¶
NewInstantQuery returns an evaluation query for the given expression at the given time.
func (*Engine) NewRangeQuery ¶
func (ng *Engine) NewRangeQuery(qs string, start, end clientmodel.Timestamp, interval time.Duration) (Query, error)
NewRangeQuery returns an evaluation query for the given time range and with the resolution set by the interval.
type ErrQueryCanceled ¶
type ErrQueryCanceled string
ErrQueryCanceled is returned if a query was canceled during processing.
func (ErrQueryCanceled) Error ¶
func (e ErrQueryCanceled) Error() string
type ErrQueryTimeout ¶
type ErrQueryTimeout string
ErrQueryTimeout is returned if a query timed out during processing.
func (ErrQueryTimeout) Error ¶
func (e ErrQueryTimeout) Error() string
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 clientmodel.Timestamp // 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.
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() ExprType // contains filtered or unexported methods }
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) DotGraph ¶
func (es Expressions) DotGraph() string
DotGraph returns a DOT representation of // DotGraph returns a DOT representation of the record statement. DotGraph returns a DOT representation of a statement list.
func (Expressions) String ¶
func (es Expressions) String() (s string)
type Function ¶
type Function struct { Name string ArgTypes []ExprType OptionalArgs int ReturnType ExprType Call func(ev *evaluator, args Expressions) Value }
Function represents a function of the expression language and is used by function nodes.
type Matrix ¶
type Matrix []*SampleStream
Matrix is a slice of SampleStreams that implements sort.Interface and has a String method.
type MatrixSelector ¶
type MatrixSelector struct { Name string Range time.Duration Offset time.Duration LabelMatchers metric.LabelMatchers // contains filtered or unexported fields }
MatrixSelector represents a matrix selection.
func (*MatrixSelector) DotGraph ¶
func (node *MatrixSelector) DotGraph() string
DotGraph returns a DOT representation of the matrix selector.
func (*MatrixSelector) String ¶
func (node *MatrixSelector) String() string
func (*MatrixSelector) Type ¶
func (e *MatrixSelector) Type() ExprType
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 // DotGraph returns a dot graph representation of the node. DotGraph() string }
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(), expr(), etc.) convention is to list them as follows:
- Statements
- statement types (alphabetical)
- ...
- Expressions
- expression types (alphabetical)
- ...
type NumberLiteral ¶
type NumberLiteral struct {
Val clientmodel.SampleValue
}
NumberLiteral represents a number.
func (*NumberLiteral) DotGraph ¶
func (node *NumberLiteral) DotGraph() string
DotGraph returns a DOT representation of the number literal.
func (*NumberLiteral) String ¶
func (node *NumberLiteral) String() string
func (*NumberLiteral) Type ¶
func (e *NumberLiteral) Type() ExprType
type ParenExpr ¶
type ParenExpr struct {
Expr Expr
}
ParenExpr wraps an expression so it cannot be disassembled as a consequence of operator precendence.
type ParseErr ¶
ParseErr wraps a parsing error with line and position context. If the parsing input was a single line, line will be 0 and omitted from the error string.
type Query ¶
type Query interface { // Exec processes the query and Exec() *Result // Statements returns the parsed statements of the query. Statements() Statements // Stats returns statistics about the lifetime of the query. Stats() *stats.TimerGroup // Cancel signals that a running query execution should be aborted. Cancel() }
A Query is derived from an a raw query string and can be run against an engine it is associated with.
type RecordStmt ¶
type RecordStmt struct { Name string Expr Expr Labels clientmodel.LabelSet }
RecordStmt represents an added recording rule.
func (*RecordStmt) DotGraph ¶
func (node *RecordStmt) DotGraph() string
DotGraph returns a DOT representation of the record statement.
func (*RecordStmt) String ¶
func (node *RecordStmt) String() string
type Result ¶
Result holds the resulting value of an execution or an error if any occurred.
func (*Result) Matrix ¶
Matrix returns a matrix. An error is returned if the result was an error or the result value is not a matrix.
type Sample ¶
type Sample struct { Metric clientmodel.COWMetric `json:"metric"` Value clientmodel.SampleValue `json:"value"` Timestamp clientmodel.Timestamp `json:"timestamp"` }
Sample is a single sample belonging to a COWMetric.
type SampleStream ¶
type SampleStream struct { Metric clientmodel.COWMetric `json:"metric"` Values metric.Values `json:"values"` }
SampleStream is a stream of Values belonging to an attached COWMetric.
type Scalar ¶
type Scalar struct { Value clientmodel.SampleValue Timestamp clientmodel.Timestamp }
Scalar is a scalar value evaluated at the set timestamp.
type Statement ¶
type Statement interface { Node // contains filtered or unexported methods }
Statement is a generic interface for all statements.
type Statements ¶
type Statements []Statement
Statements is a list of statement nodes that implements Node.
func ParseStmts ¶
func ParseStmts(input string) (Statements, error)
ParseStmts parses the input and returns the resulting statements or any ocurring error.
func (Statements) DotGraph ¶
func (ss Statements) DotGraph() string
DotGraph returns a DOT representation of a statement list.
func (Statements) String ¶
func (stmts Statements) String() (s string)
type String ¶
type String struct { Value string Timestamp clientmodel.Timestamp }
String is a string value evaluated at the set timestamp.
type StringLiteral ¶
type StringLiteral struct {
Val string
}
StringLiteral represents a string.
func (*StringLiteral) DotGraph ¶
func (node *StringLiteral) DotGraph() string
DotGraph returns a DOT representation of the string literal.
func (*StringLiteral) String ¶
func (node *StringLiteral) String() string
func (*StringLiteral) Type ¶
func (e *StringLiteral) Type() ExprType
type Test ¶
Test is a sequence of read and write commands that are run against a test storage.
type UnaryExpr ¶
type UnaryExpr struct { Op itemType Expr Expr }
UnaryExpr represents a unary operation on another expression. Currently unary operations are only supported for scalars.
type Vector ¶
type Vector []*Sample
Vector is basically only an alias for clientmodel.Samples, but the contract is that in a Vector, all Samples have the same timestamp.
type VectorMatchCardinality ¶
type VectorMatchCardinality int
VectorMatchCardinaly 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 // On contains the labels which define equality of a pair // of elements from the vectors. On clientmodel.LabelNames // Include contains additional labels that should be included in // the result from the side with the higher cardinality. Include clientmodel.LabelNames }
VectorMatching describes how elements from two vectors in a binary operation are supposed to be matched.
type VectorSelector ¶
type VectorSelector struct { Name string Offset time.Duration LabelMatchers metric.LabelMatchers // contains filtered or unexported fields }
VectorSelector represents a vector selection.
func (*VectorSelector) DotGraph ¶
func (node *VectorSelector) DotGraph() string
DotGraph returns a DOT representation of the vector selector.
func (*VectorSelector) String ¶
func (node *VectorSelector) String() string
func (*VectorSelector) Type ¶
func (e *VectorSelector) Type() ExprType