Documentation
¶
Overview ¶
Package promql implements a PromQL subset: selectors, range functions, aggregations and binary operators.
Index ¶
- Constants
- Variables
- func Fingerprint(l Labels) string
- func IsStale(v float64) bool
- func MatchesAll(lbls Labels, ms []*Matcher) bool
- func ParseDuration(s string) (time.Duration, error)
- func ResultType(v Value) string
- func Selectors(expr Expr) [][]*Matcher
- func StaleNaN() float64
- type Aggregation
- type Binary
- type Call
- type Cardinality
- type Engine
- type Expr
- type FloatHistogram
- type HBucket
- type Labels
- type MatchType
- type Matcher
- type Matrix
- type MatrixSelector
- type NumberLit
- type Sample
- type Scalar
- type Series
- type Span
- type Storage
- type StringLit
- type StringValue
- type Subquery
- type Unary
- type Value
- type Vector
- type VectorSample
- type VectorSelector
Constants ¶
const ( MinSchema = -4 MaxSchema = 8 )
Schema bounds accepted for exponential native histograms.
const DefaultLookback = 5 * time.Minute
DefaultLookback is how far back an instant selector looks for a sample.
const DefaultSubqueryStep = time.Minute
DefaultSubqueryStep is the resolution of a subquery without an explicit step.
const MaxRangeSteps = 11000
MaxRangeSteps bounds a range query's resolution like Prometheus.
const NameLabel = "__name__"
NameLabel is the label that carries the metric name.
Variables ¶
var ErrEval = errors.New("execution error")
ErrEval marks an evaluation failure.
var ErrSyntax = errors.New("parse error")
ErrSyntax marks a parse failure.
var ErrTimeout = errors.New("query timed out in expression evaluation")
ErrTimeout marks a query that outlived its context.
Functions ¶
func Fingerprint ¶
Fingerprint is a canonical string for a label set.
func MatchesAll ¶
MatchesAll reports whether lbls satisfies every matcher.
func ParseDuration ¶
ParseDuration parses a PromQL duration such as 5m or 1h30m.
Types ¶
type Aggregation ¶
Aggregation reduces a vector across series.
type Binary ¶
type Binary struct {
L, R Expr
Op string
MatchLabels []string
Include []string
Card Cardinality
On bool
ReturnBool bool
}
Binary combines two operands.
type Cardinality ¶
type Cardinality int
Cardinality is the vector matching cardinality of a binary operation.
const ( CardOneToOne Cardinality = iota CardManyToOne CardOneToMany )
Matching cardinalities; group_left is many-to-one, group_right one-to-many.
type Engine ¶
type Engine struct {
Ctx context.Context //nolint:containedctx // bounds one query's evaluation
Store Storage
Lookback time.Duration
// contains filtered or unexported fields
}
Engine evaluates expressions against a Storage.
func (*Engine) InstantExpr ¶
InstantExpr evaluates a parsed expression at ts.
type Expr ¶
type Expr interface {
// contains filtered or unexported methods
}
Expr is a parsed PromQL expression.
type FloatHistogram ¶
type FloatHistogram struct {
PositiveSpans []Span `json:"ps,omitempty"`
NegativeSpans []Span `json:"ns,omitempty"`
PositiveBuckets []float64 `json:"pb,omitempty"`
NegativeBuckets []float64 `json:"nb,omitempty"`
ZeroThreshold float64 `json:"zt,omitempty"`
ZeroCount float64 `json:"zc,omitempty"`
Count float64 `json:"c"`
Sum float64 `json:"s"`
Schema int32 `json:"schema"`
}
FloatHistogram is a native histogram with absolute (not delta-encoded) bucket counts.
func (*FloatHistogram) Buckets ¶
func (h *FloatHistogram) Buckets() []HBucket
Buckets lists every bucket in increasing value order, the zero bucket included.
func (*FloatHistogram) Fraction ¶
func (h *FloatHistogram) Fraction(lower, upper float64) float64
Fraction is the share of observations in [lower, upper].
func (*FloatHistogram) Quantile ¶
func (h *FloatHistogram) Quantile(q float64) float64
Quantile estimates the q-quantile like Prometheus' histogram_quantile on a native histogram.
func (*FloatHistogram) Valid ¶
func (h *FloatHistogram) Valid() bool
Valid reports whether the span and bucket arrays agree and the schema is supported.
type HBucket ¶
HBucket is one materialised bucket; Lower is exclusive for positive buckets and Upper for negative ones.
type Matcher ¶
type Matcher struct {
Name string
Value string
Type MatchType
// contains filtered or unexported fields
}
Matcher filters series by one label.
func NewMatcher ¶
NewMatcher builds a matcher; regular expressions are fully anchored like Prometheus.
type MatrixSelector ¶
type MatrixSelector struct {
VS *VectorSelector
Range time.Duration
}
MatrixSelector selects a window of samples per series.
type Sample ¶
type Sample struct {
H *FloatHistogram `json:"h,omitempty"`
T int64 `json:"t"`
V float64 `json:"v"`
}
Sample is one timestamped value; T is Unix milliseconds.
type Span ¶
Span is a run of consecutive populated buckets starting Offset buckets after the previous span.
type Storage ¶
type Storage interface {
// Select returns series matching ms with at least the samples in [minT, maxT] (Unix ms).
Select(ms []*Matcher, minT, maxT int64) []Series
}
Storage supplies series to the engine.
type Subquery ¶
type Subquery struct {
Expr Expr
At *int64
AtMarker string
Range time.Duration
Step time.Duration
Offset time.Duration
}
Subquery evaluates Expr over Range at Step resolution; a zero Step uses DefaultSubqueryStep.
type Value ¶
type Value interface {
// contains filtered or unexported methods
}
Value is the result of evaluating an expression.
type VectorSample ¶
type VectorSample struct {
Metric Labels
H *FloatHistogram
T int64
V float64
}
VectorSample is one instant sample of a labelled series.