promql

package
v1.0.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2016 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const LowestPrec = 0 // Non-operators.

LowestPrec is a constant for operator precedence in expressions.

Variables

View Source
var DefaultEngineOptions = &EngineOptions{
	MaxConcurrentQueries: 20,
	Timeout:              2 * time.Minute,
}

DefaultEngineOptions are the default engine options.

View Source
var StalenessDelta = 5 * time.Minute

StalenessDelta determines the time since the last sample after which a time series is considered stale.

Functions

func Inspect added in v1.0.0

func Inspect(node Node, f func(Node) bool)

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.

func ParseMetric added in v1.0.0

func ParseMetric(input string) (m model.Metric, err error)

ParseMetric parses the input into a metric

func ParseMetricSelector added in v1.0.0

func ParseMetricSelector(input string) (m metric.LabelMatchers, err error)

ParseMetricSelector parses the provided textual metric selector into a list of label matchers.

func Tree added in v1.0.0

func Tree(node Node) string

Tree returns a string of the tree structure of the given node.

func Walk added in v1.0.0

func Walk(v Visitor, node Node)

Walk traverses an AST in depth-first order: It starts by calling v.Visit(node); node must not be nil. If the visitor w returned by v.Visit(node) is not nil, Walk is invoked recursively with visitor w for each of the non-nil children of node, followed by a call of w.Visit(nil).

Types

type AggregateExpr added in v1.0.0

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         model.LabelNames // The labels by which to group the vector.
	Without          bool             // Whether to drop the given labels rather than keep them.
	KeepCommonLabels bool             // Whether to keep common labels among result elements.
}

AggregateExpr represents an aggregation operation on a vector.

func (*AggregateExpr) String added in v1.0.0

func (node *AggregateExpr) String() string

func (*AggregateExpr) Type added in v1.0.0

func (e *AggregateExpr) Type() model.ValueType

type AlertStmt added in v1.0.0

type AlertStmt struct {
	Name        string
	Expr        Expr
	Duration    time.Duration
	Labels      model.LabelSet
	Annotations model.LabelSet
}

AlertStmt represents an added alert rule.

func (*AlertStmt) String added in v1.0.0

func (node *AlertStmt) String() string

type Analyzer added in v1.0.0

type Analyzer struct {
	// The storage from which to query data.
	Storage local.Querier
	// The expression being analyzed.
	Expr Expr
	// The time range for evaluation of Expr.
	Start, End model.Time
	// 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.

func (*Analyzer) Analyze added in v1.0.0

func (a *Analyzer) Analyze(ctx context.Context) error

Analyze the provided expression and attach metrics and fingerprints to data-selecting AST nodes that are later used to preload the data from the storage.

func (*Analyzer) Prepare added in v1.0.0

func (a *Analyzer) Prepare(ctx context.Context) (local.Preloader, error)

Prepare the expression evaluation by preloading all required chunks from the storage and setting the respective storage iterators in the AST nodes.

type Benchmark added in v1.0.0

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

A Benchmark holds context for running a unit test as a benchmark.

func NewBenchmark added in v1.0.0

func NewBenchmark(b *testing.B, input string) *Benchmark

NewBenchmark returns an initialized empty Benchmark.

func (*Benchmark) Run added in v1.0.0

func (b *Benchmark) Run()

Run runs the benchmark.

type BinaryExpr added in v1.0.0

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) String added in v1.0.0

func (node *BinaryExpr) String() string

func (*BinaryExpr) Type added in v1.0.0

func (e *BinaryExpr) Type() model.ValueType

type Call added in v1.0.0

type Call struct {
	Func *Function   // The function that was called.
	Args Expressions // Arguments used in the call.
}

Call represents a function call.

func (*Call) String added in v1.0.0

func (node *Call) String() string

func (*Call) Type added in v1.0.0

func (e *Call) Type() model.ValueType

type Engine

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

Engine handles the lifetime of queries from beginning to end. It is connected to a storage.

func NewEngine

func NewEngine(storage local.Querier, o *EngineOptions) *Engine

NewEngine returns a new engine.

func (*Engine) NewInstantQuery

func (ng *Engine) NewInstantQuery(qs string, ts model.Time) (Query, error)

NewInstantQuery returns an evaluation query for the given expression at the given time.

func (*Engine) NewRangeQuery

func (ng *Engine) NewRangeQuery(qs string, start, end model.Time, interval time.Duration) (Query, error)

NewRangeQuery returns an evaluation query for the given time range and with the resolution set by the interval.

func (*Engine) Stop added in v1.0.0

func (ng *Engine) Stop()

Stop the engine and cancel all running queries.

type EngineOptions added in v1.0.0

type EngineOptions struct {
	MaxConcurrentQueries int
	Timeout              time.Duration
}

EngineOptions contains configuration parameters for an Engine.

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 added in v1.0.0

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 model.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) String added in v1.0.0

func (node *EvalStmt) String() string

type Expr added in v1.0.0

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() model.ValueType
	// contains filtered or unexported methods
}

Expr is a generic interface for all expression types.

func ParseExpr added in v1.0.0

func ParseExpr(input string) (Expr, error)

ParseExpr returns the expression parsed from the input.

type Expressions added in v1.0.0

type Expressions []Expr

Expressions is a list of expression nodes that implements Node.

func (Expressions) String added in v1.0.0

func (es Expressions) String() (s string)

type Function added in v1.0.0

type Function struct {
	Name         string
	ArgTypes     []model.ValueType
	OptionalArgs int
	ReturnType   model.ValueType
	Call         func(ev *evaluator, args Expressions) model.Value
}

Function represents a function of the expression language and is used by function nodes.

type MatrixSelector added in v1.0.0

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) String added in v1.0.0

func (node *MatrixSelector) String() string

func (*MatrixSelector) Type added in v1.0.0

func (e *MatrixSelector) Type() model.ValueType

type Node added in v1.0.0

type Node interface {
	// String representation of the node that returns the given node when parsed
	// as part of a valid query.
	String() 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 added in v1.0.0

type NumberLiteral struct {
	Val model.SampleValue
}

NumberLiteral represents a number.

func (*NumberLiteral) String added in v1.0.0

func (node *NumberLiteral) String() string

func (*NumberLiteral) Type added in v1.0.0

func (e *NumberLiteral) Type() model.ValueType

type ParenExpr added in v1.0.0

type ParenExpr struct {
	Expr Expr
}

ParenExpr wraps an expression so it cannot be disassembled as a consequence of operator precedence.

func (*ParenExpr) String added in v1.0.0

func (node *ParenExpr) String() string

func (*ParenExpr) Type added in v1.0.0

func (e *ParenExpr) Type() model.ValueType

type ParseErr added in v1.0.0

type ParseErr struct {
	Line, Pos int
	Err       error
}

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.

func (*ParseErr) Error added in v1.0.0

func (e *ParseErr) Error() string

type Pos added in v1.0.0

type Pos int

Pos is the position in a string.

type Query

type Query interface {
	// Exec processes the query and
	Exec() *Result
	// Statement returns the parsed statement of the query.
	Statement() Statement
	// 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 added in v1.0.0

type RecordStmt struct {
	Name   string
	Expr   Expr
	Labels model.LabelSet
}

RecordStmt represents an added recording rule.

func (*RecordStmt) String added in v1.0.0

func (node *RecordStmt) String() string

type Result

type Result struct {
	Err   error
	Value model.Value
}

Result holds the resulting value of an execution or an error if any occurred.

func (*Result) Matrix

func (r *Result) Matrix() (model.Matrix, error)

Matrix returns a matrix. An error is returned if the result was an error or the result value is not a matrix.

func (*Result) Scalar

func (r *Result) Scalar() (*model.Scalar, error)

Scalar returns a scalar value. An error is returned if the result was an error or the result value is not a scalar.

func (*Result) String

func (r *Result) String() string

func (*Result) Vector

func (r *Result) Vector() (model.Vector, error)

Vector returns a vector if the result value is one. An error is returned if the result was an error or the result value is not a vector.

type Statement added in v1.0.0

type Statement interface {
	Node
	// contains filtered or unexported methods
}

Statement is a generic interface for all statements.

type Statements added in v1.0.0

type Statements []Statement

Statements is a list of statement nodes that implements Node.

func ParseStmts added in v1.0.0

func ParseStmts(input string) (Statements, error)

ParseStmts parses the input and returns the resulting statements or any occuring error.

func (Statements) String added in v1.0.0

func (stmts Statements) String() (s string)

type StringLiteral added in v1.0.0

type StringLiteral struct {
	Val string
}

StringLiteral represents a string.

func (*StringLiteral) String added in v1.0.0

func (node *StringLiteral) String() string

func (*StringLiteral) Type added in v1.0.0

func (e *StringLiteral) Type() model.ValueType

type Test

type Test struct {
	testutil.T
	// contains filtered or unexported fields
}

Test is a sequence of read and write commands that are run against a test storage.

func NewTest

func NewTest(t testutil.T, input string) (*Test, error)

NewTest returns an initialized empty Test.

func (*Test) Close

func (t *Test) Close()

Close closes resources associated with the Test.

func (*Test) QueryEngine

func (t *Test) QueryEngine() *Engine

QueryEngine returns the test's query engine.

func (*Test) Run

func (t *Test) Run() error

Run executes the command sequence of the test. Until the maximum error number is reached, evaluation errors do not terminate execution.

func (*Test) RunAsBenchmark added in v1.0.0

func (t *Test) RunAsBenchmark(b *Benchmark) error

RunAsBenchmark runs the test in benchmark mode. This will not count any loads or non eval functions.

func (*Test) Storage

func (t *Test) Storage() local.Storage

Storage returns the test's storage.

type UnaryExpr added in v1.0.0

type UnaryExpr struct {
	Op   itemType
	Expr Expr
}

UnaryExpr represents a unary operation on another expression. Currently unary operations are only supported for scalars.

func (*UnaryExpr) String added in v1.0.0

func (node *UnaryExpr) String() string

func (*UnaryExpr) Type added in v1.0.0

func (e *UnaryExpr) Type() model.ValueType

type VectorMatchCardinality added in v1.0.0

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 added in v1.0.0

func (vmc VectorMatchCardinality) String() string

type VectorMatching added in v1.0.0

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 model.LabelNames
	// 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 model.LabelNames
}

VectorMatching describes how elements from two vectors in a binary operation are supposed to be matched.

type VectorSelector added in v1.0.0

type VectorSelector struct {
	Name          string
	Offset        time.Duration
	LabelMatchers metric.LabelMatchers
	// contains filtered or unexported fields
}

VectorSelector represents a vector selection.

func (*VectorSelector) String added in v1.0.0

func (node *VectorSelector) String() string

func (*VectorSelector) Type added in v1.0.0

func (e *VectorSelector) Type() model.ValueType

type Visitor added in v1.0.0

type Visitor interface {
	Visit(node Node) (w Visitor)
}

Visitor allows visiting a Node and its child nodes. The Visit method is invoked for each node encountered by Walk. If the result visitor w is not nil, Walk visits each of the children of node with the visitor w, followed by a call of w.Visit(nil).

Jump to

Keyboard shortcuts

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