mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Fix usages of more things that have moved the package
Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
This commit is contained in:
parent
4a4817a444
commit
228967a507
100
promql/engine.go
100
promql/engine.go
|
@ -388,9 +388,9 @@ func (ng *Engine) NewRangeQuery(q storage.Queryable, qs string, start, end time.
|
||||||
return qry, nil
|
return qry, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ng *Engine) newQuery(q storage.Queryable, expr Expr, start, end time.Time, interval time.Duration) *query {
|
func (ng *Engine) newQuery(q storage.Queryable, expr parser.Expr, start, end time.Time, interval time.Duration) *query {
|
||||||
es := &EvalStmt{
|
es := &parser.EvalStmt{
|
||||||
Expr: expr,
|
parser.Expr: expr,
|
||||||
Start: start,
|
Start: start,
|
||||||
End: end,
|
End: end,
|
||||||
Interval: interval,
|
Interval: interval,
|
||||||
|
@ -430,7 +430,7 @@ func (ng *Engine) newTestQuery(f func(context.Context) error) Query {
|
||||||
|
|
||||||
// exec executes the query.
|
// exec executes the query.
|
||||||
//
|
//
|
||||||
// At this point per query only one EvalStmt is evaluated. Alert and record
|
// At this point per query only one parser.EvalStmt is evaluated. Alert and record
|
||||||
// statements are not handled by the Engine.
|
// statements are not handled by the Engine.
|
||||||
func (ng *Engine) exec(ctx context.Context, q *query) (v parser.Value, w storage.Warnings, err error) {
|
func (ng *Engine) exec(ctx context.Context, q *query) (v parser.Value, w storage.Warnings, err error) {
|
||||||
ng.metrics.currentQueries.Inc()
|
ng.metrics.currentQueries.Inc()
|
||||||
|
@ -444,7 +444,7 @@ func (ng *Engine) exec(ctx context.Context, q *query) (v parser.Value, w storage
|
||||||
if l := ng.queryLogger; l != nil {
|
if l := ng.queryLogger; l != nil {
|
||||||
params := make(map[string]interface{}, 4)
|
params := make(map[string]interface{}, 4)
|
||||||
params["query"] = q.q
|
params["query"] = q.q
|
||||||
if eq, ok := q.parser.Statement().(*EvalStmt); ok {
|
if eq, ok := q.parser.Statement().(*parser.EvalStmt); ok {
|
||||||
params["start"] = formatDate(eq.Start)
|
params["start"] = formatDate(eq.Start)
|
||||||
params["end"] = formatDate(eq.End)
|
params["end"] = formatDate(eq.End)
|
||||||
// The step provided by the user is in seconds.
|
// The step provided by the user is in seconds.
|
||||||
|
@ -498,7 +498,7 @@ func (ng *Engine) exec(ctx context.Context, q *query) (v parser.Value, w storage
|
||||||
}
|
}
|
||||||
|
|
||||||
switch s := q.parser.Statement().(type) {
|
switch s := q.parser.Statement().(type) {
|
||||||
case *EvalStmt:
|
case *parser.EvalStmt:
|
||||||
return ng.execEvalStmt(ctx, q, s)
|
return ng.execEvalStmt(ctx, q, s)
|
||||||
case testStmt:
|
case testStmt:
|
||||||
return nil, nil, s(ctx)
|
return nil, nil, s(ctx)
|
||||||
|
@ -516,7 +516,7 @@ func durationMilliseconds(d time.Duration) int64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
// execEvalStmt evaluates the expression of an evaluation statement for the given time range.
|
// execEvalStmt evaluates the expression of an evaluation statement for the given time range.
|
||||||
func (ng *Engine) execEvalStmt(ctx context.Context, query *query, s *EvalStmt) (parser.Value, storage.Warnings, error) {
|
func (ng *Engine) execEvalStmt(ctx context.Context, query *query, s *parser.EvalStmt) (parser.Value, storage.Warnings, error) {
|
||||||
prepareSpanTimer, ctxPrepare := query.stats.GetSpanTimer(ctx, stats.QueryPreparationTime, ng.metrics.queryPrepareTime)
|
prepareSpanTimer, ctxPrepare := query.stats.GetSpanTimer(ctx, stats.QueryPreparationTime, ng.metrics.queryPrepareTime)
|
||||||
querier, warnings, err := ng.populateSeries(ctxPrepare, query.queryable, s)
|
querier, warnings, err := ng.populateSeries(ctxPrepare, query.queryable, s)
|
||||||
prepareSpanTimer.Finish()
|
prepareSpanTimer.Finish()
|
||||||
|
@ -547,7 +547,7 @@ func (ng *Engine) execEvalStmt(ctx context.Context, query *query, s *EvalStmt) (
|
||||||
lookbackDelta: ng.lookbackDelta,
|
lookbackDelta: ng.lookbackDelta,
|
||||||
}
|
}
|
||||||
|
|
||||||
val, err := evaluator.Eval(s.Expr)
|
val, err := evaluator.Eval(s.parser.Expr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, warnings, err
|
return nil, warnings, err
|
||||||
}
|
}
|
||||||
|
@ -566,7 +566,7 @@ func (ng *Engine) execEvalStmt(ctx context.Context, query *query, s *EvalStmt) (
|
||||||
}
|
}
|
||||||
|
|
||||||
query.matrix = mat
|
query.matrix = mat
|
||||||
switch s.Expr.Type() {
|
switch s.parser.Expr.Type() {
|
||||||
case parser.ValueTypeVector:
|
case parser.ValueTypeVector:
|
||||||
// Convert matrix with one value per series into vector.
|
// Convert matrix with one value per series into vector.
|
||||||
vector := make(Vector, len(mat))
|
vector := make(Vector, len(mat))
|
||||||
|
@ -581,7 +581,7 @@ func (ng *Engine) execEvalStmt(ctx context.Context, query *query, s *EvalStmt) (
|
||||||
case parser.ValueTypeMatrix:
|
case parser.ValueTypeMatrix:
|
||||||
return mat, warnings, nil
|
return mat, warnings, nil
|
||||||
default:
|
default:
|
||||||
panic(errors.Errorf("promql.Engine.exec: unexpected expression type %q", s.Expr.Type()))
|
panic(errors.Errorf("promql.Engine.exec: unexpected expression type %q", s.parser.Expr.Type()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -596,7 +596,7 @@ func (ng *Engine) execEvalStmt(ctx context.Context, query *query, s *EvalStmt) (
|
||||||
logger: ng.logger,
|
logger: ng.logger,
|
||||||
lookbackDelta: ng.lookbackDelta,
|
lookbackDelta: ng.lookbackDelta,
|
||||||
}
|
}
|
||||||
val, err := evaluator.Eval(s.Expr)
|
val, err := evaluator.Eval(s.parser.Expr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, warnings, err
|
return nil, warnings, err
|
||||||
}
|
}
|
||||||
|
@ -621,23 +621,23 @@ func (ng *Engine) execEvalStmt(ctx context.Context, query *query, s *EvalStmt) (
|
||||||
}
|
}
|
||||||
|
|
||||||
// cumulativeSubqueryOffset returns the sum of range and offset of all subqueries in the path.
|
// cumulativeSubqueryOffset returns the sum of range and offset of all subqueries in the path.
|
||||||
func (ng *Engine) cumulativeSubqueryOffset(path []Node) time.Duration {
|
func (ng *Engine) cumulativeSubqueryOffset(path []parser.Node) time.Duration {
|
||||||
var subqOffset time.Duration
|
var subqOffset time.Duration
|
||||||
for _, node := range path {
|
for _, node := range path {
|
||||||
switch n := node.(type) {
|
switch n := node.(type) {
|
||||||
case *SubqueryExpr:
|
case *parser.SubqueryExpr:
|
||||||
subqOffset += n.Range + n.Offset
|
subqOffset += n.Range + n.Offset
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return subqOffset
|
return subqOffset
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ng *Engine) populateSeries(ctx context.Context, q storage.Queryable, s *EvalStmt) (storage.Querier, storage.Warnings, error) {
|
func (ng *Engine) populateSeries(ctx context.Context, q storage.Queryable, s *parser.EvalStmt) (storage.Querier, storage.Warnings, error) {
|
||||||
var maxOffset time.Duration
|
var maxOffset time.Duration
|
||||||
Inspect(s.Expr, func(node Node, path []Node) error {
|
Inspect(s.parser.Expr, func(node parser.Node, path []parser.Node) error {
|
||||||
subqOffset := ng.cumulativeSubqueryOffset(path)
|
subqOffset := ng.cumulativeSubqueryOffset(path)
|
||||||
switch n := node.(type) {
|
switch n := node.(type) {
|
||||||
case *VectorSelector:
|
case *parser.VectorSelector:
|
||||||
if maxOffset < ng.lookbackDelta+subqOffset {
|
if maxOffset < ng.lookbackDelta+subqOffset {
|
||||||
maxOffset = ng.lookbackDelta + subqOffset
|
maxOffset = ng.lookbackDelta + subqOffset
|
||||||
}
|
}
|
||||||
|
@ -648,7 +648,7 @@ func (ng *Engine) populateSeries(ctx context.Context, q storage.Queryable, s *Ev
|
||||||
if maxOffset < n.Range+subqOffset {
|
if maxOffset < n.Range+subqOffset {
|
||||||
maxOffset = n.Range + subqOffset
|
maxOffset = n.Range + subqOffset
|
||||||
}
|
}
|
||||||
if m := n.VectorSelector.(*VectorSelector).Offset + n.Range + subqOffset; m > maxOffset {
|
if m := n.parser.VectorSelector.(*parser.VectorSelector).Offset + n.Range + subqOffset; m > maxOffset {
|
||||||
maxOffset = m
|
maxOffset = m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -665,11 +665,11 @@ func (ng *Engine) populateSeries(ctx context.Context, q storage.Queryable, s *Ev
|
||||||
var warnings storage.Warnings
|
var warnings storage.Warnings
|
||||||
|
|
||||||
// Whenever a MatrixSelector is evaluated this variable is set to the corresponding range.
|
// Whenever a MatrixSelector is evaluated this variable is set to the corresponding range.
|
||||||
// The evaluation of the VectorSelector inside then evaluates the given range and unsets
|
// The evaluation of the parser.VectorSelector inside then evaluates the given range and unsets
|
||||||
// the variable.
|
// the variable.
|
||||||
var evalRange time.Duration
|
var evalRange time.Duration
|
||||||
|
|
||||||
Inspect(s.Expr, func(node Node, path []Node) error {
|
Inspect(s.parser.Expr, func(node parser.Node, path []parser.Node) error {
|
||||||
var set storage.SeriesSet
|
var set storage.SeriesSet
|
||||||
var wrn storage.Warnings
|
var wrn storage.Warnings
|
||||||
params := &storage.SelectParams{
|
params := &storage.SelectParams{
|
||||||
|
@ -687,7 +687,7 @@ func (ng *Engine) populateSeries(ctx context.Context, q storage.Queryable, s *Ev
|
||||||
params.Start = params.Start - offsetMilliseconds
|
params.Start = params.Start - offsetMilliseconds
|
||||||
|
|
||||||
switch n := node.(type) {
|
switch n := node.(type) {
|
||||||
case *VectorSelector:
|
case *parser.VectorSelector:
|
||||||
if evalRange == 0 {
|
if evalRange == 0 {
|
||||||
params.Start = params.Start - durationMilliseconds(ng.lookbackDelta)
|
params.Start = params.Start - durationMilliseconds(ng.lookbackDelta)
|
||||||
} else {
|
} else {
|
||||||
|
@ -724,7 +724,7 @@ func (ng *Engine) populateSeries(ctx context.Context, q storage.Queryable, s *Ev
|
||||||
|
|
||||||
// extractFuncFromPath walks up the path and searches for the first instance of
|
// extractFuncFromPath walks up the path and searches for the first instance of
|
||||||
// a function or aggregation.
|
// a function or aggregation.
|
||||||
func extractFuncFromPath(p []Node) string {
|
func extractFuncFromPath(p []parser.Node) string {
|
||||||
if len(p) == 0 {
|
if len(p) == 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
@ -742,7 +742,7 @@ func extractFuncFromPath(p []Node) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// extractGroupsFromPath parses vector outer function and extracts grouping information if by or without was used.
|
// extractGroupsFromPath parses vector outer function and extracts grouping information if by or without was used.
|
||||||
func extractGroupsFromPath(p []Node) (bool, []string) {
|
func extractGroupsFromPath(p []parser.Node) (bool, []string) {
|
||||||
if len(p) == 0 {
|
if len(p) == 0 {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
@ -753,11 +753,11 @@ func extractGroupsFromPath(p []Node) (bool, []string) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkForSeriesSetExpansion(ctx context.Context, expr Expr) {
|
func checkForSeriesSetExpansion(ctx context.Context, expr parser.Expr) {
|
||||||
switch e := expr.(type) {
|
switch e := expr.(type) {
|
||||||
case *MatrixSelector:
|
case *MatrixSelector:
|
||||||
checkForSeriesSetExpansion(ctx, e.VectorSelector)
|
checkForSeriesSetExpansion(ctx, e.parser.VectorSelector)
|
||||||
case *VectorSelector:
|
case *parser.VectorSelector:
|
||||||
if e.series == nil {
|
if e.series == nil {
|
||||||
series, err := expandSeriesSet(ctx, e.unexpandedSeriesSet)
|
series, err := expandSeriesSet(ctx, e.unexpandedSeriesSet)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -826,7 +826,7 @@ func (ev *evaluator) recover(errp *error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ev *evaluator) Eval(expr Expr) (v parser.Value, err error) {
|
func (ev *evaluator) Eval(expr parser.Expr) (v parser.Value, err error) {
|
||||||
defer ev.recover(&err)
|
defer ev.recover(&err)
|
||||||
return ev.eval(expr), nil
|
return ev.eval(expr), nil
|
||||||
}
|
}
|
||||||
|
@ -891,7 +891,7 @@ func (enh *EvalNodeHelper) signatureFunc(on bool, names ...string) func(labels.L
|
||||||
// the given function with the values computed for each expression at that
|
// the given function with the values computed for each expression at that
|
||||||
// step. The return value is the combination into time series of all the
|
// step. The return value is the combination into time series of all the
|
||||||
// function call results.
|
// function call results.
|
||||||
func (ev *evaluator) rangeEval(f func([]parser.Value, *EvalNodeHelper) Vector, exprs ...Expr) Matrix {
|
func (ev *evaluator) rangeEval(f func([]parser.Value, *EvalNodeHelper) Vector, exprs ...parser.Expr) Matrix {
|
||||||
numSteps := int((ev.endTimestamp-ev.startTimestamp)/ev.interval) + 1
|
numSteps := int((ev.endTimestamp-ev.startTimestamp)/ev.interval) + 1
|
||||||
matrixes := make([]Matrix, len(exprs))
|
matrixes := make([]Matrix, len(exprs))
|
||||||
origMatrixes := make([]Matrix, len(exprs))
|
origMatrixes := make([]Matrix, len(exprs))
|
||||||
|
@ -1011,17 +1011,17 @@ func (ev *evaluator) rangeEval(f func([]parser.Value, *EvalNodeHelper) Vector, e
|
||||||
return mat
|
return mat
|
||||||
}
|
}
|
||||||
|
|
||||||
// evalSubquery evaluates given SubqueryExpr and returns an equivalent
|
// evalSubquery evaluates given parser.SubqueryExpr and returns an equivalent
|
||||||
// evaluated MatrixSelector in its place. Note that the Name and LabelMatchers are not set.
|
// evaluated MatrixSelector in its place. Note that the Name and LabelMatchers are not set.
|
||||||
func (ev *evaluator) evalSubquery(subq *SubqueryExpr) *MatrixSelector {
|
func (ev *evaluator) evalSubquery(subq *parser.SubqueryExpr) *MatrixSelector {
|
||||||
val := ev.eval(subq).(Matrix)
|
val := ev.eval(subq).(Matrix)
|
||||||
vs := &VectorSelector{
|
vs := &parser.VectorSelector{
|
||||||
Offset: subq.Offset,
|
Offset: subq.Offset,
|
||||||
series: make([]storage.Series, 0, len(val)),
|
series: make([]storage.Series, 0, len(val)),
|
||||||
}
|
}
|
||||||
ms := &MatrixSelector{
|
ms := &MatrixSelector{
|
||||||
Range: subq.Range,
|
Range: subq.Range,
|
||||||
VectorSelector: vs,
|
parser.VectorSelector: vs,
|
||||||
}
|
}
|
||||||
for _, s := range val {
|
for _, s := range val {
|
||||||
vs.series = append(vs.series, NewStorageSeries(s))
|
vs.series = append(vs.series, NewStorageSeries(s))
|
||||||
|
@ -1030,7 +1030,7 @@ func (ev *evaluator) evalSubquery(subq *SubqueryExpr) *MatrixSelector {
|
||||||
}
|
}
|
||||||
|
|
||||||
// eval evaluates the given expression as the given AST expression node requires.
|
// eval evaluates the given expression as the given AST expression node requires.
|
||||||
func (ev *evaluator) eval(expr Expr) parser.Value {
|
func (ev *evaluator) eval(expr parser.Expr) parser.Value {
|
||||||
// This is the top-level evaluation method.
|
// This is the top-level evaluation method.
|
||||||
// Thus, we check for timeout/cancellation here.
|
// Thus, we check for timeout/cancellation here.
|
||||||
if err := contextDone(ev.ctx, "expression evaluation"); err != nil {
|
if err := contextDone(ev.ctx, "expression evaluation"); err != nil {
|
||||||
|
@ -1044,7 +1044,7 @@ func (ev *evaluator) eval(expr Expr) parser.Value {
|
||||||
if s, ok := e.Param.(*StringLiteral); ok {
|
if s, ok := e.Param.(*StringLiteral); ok {
|
||||||
return ev.rangeEval(func(v []parser.Value, enh *EvalNodeHelper) Vector {
|
return ev.rangeEval(func(v []parser.Value, enh *EvalNodeHelper) Vector {
|
||||||
return ev.aggregation(e.Op, e.Grouping, e.Without, s.Val, v[0].(Vector), enh)
|
return ev.aggregation(e.Op, e.Grouping, e.Without, s.Val, v[0].(Vector), enh)
|
||||||
}, e.Expr)
|
}, e.parser.Expr)
|
||||||
}
|
}
|
||||||
return ev.rangeEval(func(v []parser.Value, enh *EvalNodeHelper) Vector {
|
return ev.rangeEval(func(v []parser.Value, enh *EvalNodeHelper) Vector {
|
||||||
var param float64
|
var param float64
|
||||||
|
@ -1052,14 +1052,14 @@ func (ev *evaluator) eval(expr Expr) parser.Value {
|
||||||
param = v[0].(Vector)[0].V
|
param = v[0].(Vector)[0].V
|
||||||
}
|
}
|
||||||
return ev.aggregation(e.Op, e.Grouping, e.Without, param, v[1].(Vector), enh)
|
return ev.aggregation(e.Op, e.Grouping, e.Without, param, v[1].(Vector), enh)
|
||||||
}, e.Param, e.Expr)
|
}, e.Param, e.parser.Expr)
|
||||||
|
|
||||||
case *Call:
|
case *Call:
|
||||||
if e.Func.Name == "timestamp" {
|
if e.Func.Name == "timestamp" {
|
||||||
// Matrix evaluation always returns the evaluation time,
|
// Matrix evaluation always returns the evaluation time,
|
||||||
// so this function needs special handling when given
|
// so this function needs special handling when given
|
||||||
// a vector selector.
|
// a vector selector.
|
||||||
vs, ok := e.Args[0].(*VectorSelector)
|
vs, ok := e.Args[0].(*parser.VectorSelector)
|
||||||
if ok {
|
if ok {
|
||||||
return ev.rangeEval(func(v []parser.Value, enh *EvalNodeHelper) Vector {
|
return ev.rangeEval(func(v []parser.Value, enh *EvalNodeHelper) Vector {
|
||||||
return e.Func.Call([]parser.Value{ev.vectorSelector(vs, enh.ts)}, e.Args, enh)
|
return e.Func.Call([]parser.Value{ev.vectorSelector(vs, enh.ts)}, e.Args, enh)
|
||||||
|
@ -1078,11 +1078,11 @@ func (ev *evaluator) eval(expr Expr) parser.Value {
|
||||||
matrixArg = true
|
matrixArg = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
// SubqueryExpr can be used in place of MatrixSelector.
|
// parser.SubqueryExpr can be used in place of MatrixSelector.
|
||||||
if subq, ok := a.(*SubqueryExpr); ok {
|
if subq, ok := a.(*parser.SubqueryExpr); ok {
|
||||||
matrixArgIndex = i
|
matrixArgIndex = i
|
||||||
matrixArg = true
|
matrixArg = true
|
||||||
// Replacing SubqueryExpr with MatrixSelector.
|
// Replacing parser.SubqueryExpr with MatrixSelector.
|
||||||
e.Args[i] = ev.evalSubquery(subq)
|
e.Args[i] = ev.evalSubquery(subq)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -1107,7 +1107,7 @@ func (ev *evaluator) eval(expr Expr) parser.Value {
|
||||||
}
|
}
|
||||||
|
|
||||||
sel := e.Args[matrixArgIndex].(*MatrixSelector)
|
sel := e.Args[matrixArgIndex].(*MatrixSelector)
|
||||||
selVS := sel.VectorSelector.(*VectorSelector)
|
selVS := sel.parser.VectorSelector.(*parser.VectorSelector)
|
||||||
|
|
||||||
checkForSeriesSetExpansion(ev.ctx, sel)
|
checkForSeriesSetExpansion(ev.ctx, sel)
|
||||||
mat := make(Matrix, 0, len(selVS.series)) // Output matrix.
|
mat := make(Matrix, 0, len(selVS.series)) // Output matrix.
|
||||||
|
@ -1222,10 +1222,10 @@ func (ev *evaluator) eval(expr Expr) parser.Value {
|
||||||
return mat
|
return mat
|
||||||
|
|
||||||
case *ParenExpr:
|
case *ParenExpr:
|
||||||
return ev.eval(e.Expr)
|
return ev.eval(e.parser.Expr)
|
||||||
|
|
||||||
case *UnaryExpr:
|
case *UnaryExpr:
|
||||||
mat := ev.eval(e.Expr).(Matrix)
|
mat := ev.eval(e.parser.Expr).(Matrix)
|
||||||
if e.Op == SUB {
|
if e.Op == SUB {
|
||||||
for i := range mat {
|
for i := range mat {
|
||||||
mat[i].Metric = dropMetricName(mat[i].Metric)
|
mat[i].Metric = dropMetricName(mat[i].Metric)
|
||||||
|
@ -1282,7 +1282,7 @@ func (ev *evaluator) eval(expr Expr) parser.Value {
|
||||||
return append(enh.out, Sample{Point: Point{V: e.Val}})
|
return append(enh.out, Sample{Point: Point{V: e.Val}})
|
||||||
})
|
})
|
||||||
|
|
||||||
case *VectorSelector:
|
case *parser.VectorSelector:
|
||||||
checkForSeriesSetExpansion(ev.ctx, e)
|
checkForSeriesSetExpansion(ev.ctx, e)
|
||||||
mat := make(Matrix, 0, len(e.series))
|
mat := make(Matrix, 0, len(e.series))
|
||||||
it := storage.NewBuffer(durationMilliseconds(ev.lookbackDelta))
|
it := storage.NewBuffer(durationMilliseconds(ev.lookbackDelta))
|
||||||
|
@ -1320,7 +1320,7 @@ func (ev *evaluator) eval(expr Expr) parser.Value {
|
||||||
}
|
}
|
||||||
return ev.matrixSelector(e)
|
return ev.matrixSelector(e)
|
||||||
|
|
||||||
case *SubqueryExpr:
|
case *parser.SubqueryExpr:
|
||||||
offsetMillis := durationToInt64Millis(e.Offset)
|
offsetMillis := durationToInt64Millis(e.Offset)
|
||||||
rangeMillis := durationToInt64Millis(e.Range)
|
rangeMillis := durationToInt64Millis(e.Range)
|
||||||
newEv := &evaluator{
|
newEv := &evaluator{
|
||||||
|
@ -1345,7 +1345,7 @@ func (ev *evaluator) eval(expr Expr) parser.Value {
|
||||||
newEv.startTimestamp += newEv.interval
|
newEv.startTimestamp += newEv.interval
|
||||||
}
|
}
|
||||||
|
|
||||||
res := newEv.eval(e.Expr)
|
res := newEv.eval(e.parser.Expr)
|
||||||
ev.currentSamples = newEv.currentSamples
|
ev.currentSamples = newEv.currentSamples
|
||||||
return res
|
return res
|
||||||
case *StringLiteral:
|
case *StringLiteral:
|
||||||
|
@ -1359,8 +1359,8 @@ func durationToInt64Millis(d time.Duration) int64 {
|
||||||
return int64(d / time.Millisecond)
|
return int64(d / time.Millisecond)
|
||||||
}
|
}
|
||||||
|
|
||||||
// vectorSelector evaluates a *VectorSelector expression.
|
// vectorSelector evaluates a *parser.VectorSelector expression.
|
||||||
func (ev *evaluator) vectorSelector(node *VectorSelector, ts int64) Vector {
|
func (ev *evaluator) vectorSelector(node *parser.VectorSelector, ts int64) Vector {
|
||||||
checkForSeriesSetExpansion(ev.ctx, node)
|
checkForSeriesSetExpansion(ev.ctx, node)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -1388,7 +1388,7 @@ func (ev *evaluator) vectorSelector(node *VectorSelector, ts int64) Vector {
|
||||||
}
|
}
|
||||||
|
|
||||||
// vectorSelectorSingle evaluates a instant vector for the iterator of one time series.
|
// vectorSelectorSingle evaluates a instant vector for the iterator of one time series.
|
||||||
func (ev *evaluator) vectorSelectorSingle(it *storage.BufferedSeriesIterator, node *VectorSelector, ts int64) (int64, float64, bool) {
|
func (ev *evaluator) vectorSelectorSingle(it *storage.BufferedSeriesIterator, node *parser.VectorSelector, ts int64) (int64, float64, bool) {
|
||||||
refTime := ts - durationMilliseconds(node.Offset)
|
refTime := ts - durationMilliseconds(node.Offset)
|
||||||
var t int64
|
var t int64
|
||||||
var v float64
|
var v float64
|
||||||
|
@ -1435,7 +1435,7 @@ func putPointSlice(p []Point) {
|
||||||
func (ev *evaluator) matrixSelector(node *MatrixSelector) Matrix {
|
func (ev *evaluator) matrixSelector(node *MatrixSelector) Matrix {
|
||||||
checkForSeriesSetExpansion(ev.ctx, node)
|
checkForSeriesSetExpansion(ev.ctx, node)
|
||||||
|
|
||||||
vs := node.VectorSelector.(*VectorSelector)
|
vs := node.parser.VectorSelector.(*parser.VectorSelector)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
offset = durationMilliseconds(vs.Offset)
|
offset = durationMilliseconds(vs.Offset)
|
||||||
|
@ -2117,10 +2117,10 @@ func formatDate(t time.Time) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// unwrapParenExpr does the AST equivalent of removing parentheses around a expression.
|
// unwrapParenExpr does the AST equivalent of removing parentheses around a expression.
|
||||||
func unwrapParenExpr(e *Expr) {
|
func unwrapParenExpr(e *parser.Expr) {
|
||||||
for {
|
for {
|
||||||
if p, ok := (*e).(*ParenExpr); ok {
|
if p, ok := (*e).(*ParenExpr); ok {
|
||||||
*e = p.Expr
|
*e = p.parser.Expr
|
||||||
} else {
|
} else {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,11 +49,11 @@ type Function struct {
|
||||||
// Instant vector functions need only return a vector with the right values and
|
// Instant vector functions need only return a vector with the right values and
|
||||||
// metrics, the timestamp are not needed.
|
// metrics, the timestamp are not needed.
|
||||||
// Scalar results should be returned as the value of a sample in a Vector.
|
// Scalar results should be returned as the value of a sample in a Vector.
|
||||||
Call func(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector
|
Call func(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector
|
||||||
}
|
}
|
||||||
|
|
||||||
// === time() float64 ===
|
// === time() float64 ===
|
||||||
func funcTime(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcTime(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return Vector{Sample{Point: Point{
|
return Vector{Sample{Point: Point{
|
||||||
V: float64(enh.ts) / 1000,
|
V: float64(enh.ts) / 1000,
|
||||||
}}}
|
}}}
|
||||||
|
@ -63,9 +63,9 @@ func funcTime(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector
|
||||||
// It calculates the rate (allowing for counter resets if isCounter is true),
|
// It calculates the rate (allowing for counter resets if isCounter is true),
|
||||||
// extrapolates if the first/last sample is close to the boundary, and returns
|
// extrapolates if the first/last sample is close to the boundary, and returns
|
||||||
// the result as either per-second (if isRate is true) or overall.
|
// the result as either per-second (if isRate is true) or overall.
|
||||||
func extrapolatedRate(vals []parser.Value, args Expressions, enh *EvalNodeHelper, isCounter bool, isRate bool) Vector {
|
func extrapolatedRate(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper, isCounter bool, isRate bool) Vector {
|
||||||
ms := args[0].(*MatrixSelector)
|
ms := args[0].(*MatrixSelector)
|
||||||
vs := ms.VectorSelector.(*VectorSelector)
|
vs := ms.parser.VectorSelector.(*parser.VectorSelector)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
samples = vals[0].(Matrix)[0]
|
samples = vals[0].(Matrix)[0]
|
||||||
|
@ -139,27 +139,27 @@ func extrapolatedRate(vals []parser.Value, args Expressions, enh *EvalNodeHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
// === delta(Matrix parser.ValueTypeMatrix) Vector ===
|
// === delta(Matrix parser.ValueTypeMatrix) Vector ===
|
||||||
func funcDelta(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcDelta(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return extrapolatedRate(vals, args, enh, false, false)
|
return extrapolatedRate(vals, args, enh, false, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// === rate(node parser.ValueTypeMatrix) Vector ===
|
// === rate(node parser.ValueTypeMatrix) Vector ===
|
||||||
func funcRate(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcRate(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return extrapolatedRate(vals, args, enh, true, true)
|
return extrapolatedRate(vals, args, enh, true, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// === increase(node parser.ValueTypeMatrix) Vector ===
|
// === increase(node parser.ValueTypeMatrix) Vector ===
|
||||||
func funcIncrease(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcIncrease(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return extrapolatedRate(vals, args, enh, true, false)
|
return extrapolatedRate(vals, args, enh, true, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// === irate(node parser.ValueTypeMatrix) Vector ===
|
// === irate(node parser.ValueTypeMatrix) Vector ===
|
||||||
func funcIrate(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcIrate(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return instantValue(vals, enh.out, true)
|
return instantValue(vals, enh.out, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// === idelta(node model.ValMatrix) Vector ===
|
// === idelta(node model.ValMatrix) Vector ===
|
||||||
func funcIdelta(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcIdelta(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return instantValue(vals, enh.out, false)
|
return instantValue(vals, enh.out, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,7 +219,7 @@ func calcTrendValue(i int, sf, tf, s0, s1, b float64) float64 {
|
||||||
// data. A lower smoothing factor increases the influence of historical data. The trend factor (0 < tf < 1) affects
|
// data. A lower smoothing factor increases the influence of historical data. The trend factor (0 < tf < 1) affects
|
||||||
// how trends in historical data will affect the current data. A higher trend factor increases the influence.
|
// how trends in historical data will affect the current data. A higher trend factor increases the influence.
|
||||||
// of trends. Algorithm taken from https://en.wikipedia.org/wiki/Exponential_smoothing titled: "Double exponential smoothing".
|
// of trends. Algorithm taken from https://en.wikipedia.org/wiki/Exponential_smoothing titled: "Double exponential smoothing".
|
||||||
func funcHoltWinters(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcHoltWinters(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
samples := vals[0].(Matrix)[0]
|
samples := vals[0].(Matrix)[0]
|
||||||
|
|
||||||
// The smoothing factor argument.
|
// The smoothing factor argument.
|
||||||
|
@ -268,7 +268,7 @@ func funcHoltWinters(vals []parser.Value, args Expressions, enh *EvalNodeHelper)
|
||||||
}
|
}
|
||||||
|
|
||||||
// === sort(node parser.ValueTypeVector) Vector ===
|
// === sort(node parser.ValueTypeVector) Vector ===
|
||||||
func funcSort(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcSort(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
// NaN should sort to the bottom, so take descending sort with NaN first and
|
// NaN should sort to the bottom, so take descending sort with NaN first and
|
||||||
// reverse it.
|
// reverse it.
|
||||||
byValueSorter := vectorByReverseValueHeap(vals[0].(Vector))
|
byValueSorter := vectorByReverseValueHeap(vals[0].(Vector))
|
||||||
|
@ -277,7 +277,7 @@ func funcSort(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector
|
||||||
}
|
}
|
||||||
|
|
||||||
// === sortDesc(node parser.ValueTypeVector) Vector ===
|
// === sortDesc(node parser.ValueTypeVector) Vector ===
|
||||||
func funcSortDesc(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcSortDesc(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
// NaN should sort to the bottom, so take ascending sort with NaN first and
|
// NaN should sort to the bottom, so take ascending sort with NaN first and
|
||||||
// reverse it.
|
// reverse it.
|
||||||
byValueSorter := vectorByValueHeap(vals[0].(Vector))
|
byValueSorter := vectorByValueHeap(vals[0].(Vector))
|
||||||
|
@ -286,7 +286,7 @@ func funcSortDesc(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Ve
|
||||||
}
|
}
|
||||||
|
|
||||||
// === clamp_max(Vector parser.ValueTypeVector, max Scalar) Vector ===
|
// === clamp_max(Vector parser.ValueTypeVector, max Scalar) Vector ===
|
||||||
func funcClampMax(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcClampMax(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
vec := vals[0].(Vector)
|
vec := vals[0].(Vector)
|
||||||
max := vals[1].(Vector)[0].Point.V
|
max := vals[1].(Vector)[0].Point.V
|
||||||
for _, el := range vec {
|
for _, el := range vec {
|
||||||
|
@ -299,7 +299,7 @@ func funcClampMax(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Ve
|
||||||
}
|
}
|
||||||
|
|
||||||
// === clamp_min(Vector parser.ValueTypeVector, min Scalar) Vector ===
|
// === clamp_min(Vector parser.ValueTypeVector, min Scalar) Vector ===
|
||||||
func funcClampMin(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcClampMin(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
vec := vals[0].(Vector)
|
vec := vals[0].(Vector)
|
||||||
min := vals[1].(Vector)[0].Point.V
|
min := vals[1].(Vector)[0].Point.V
|
||||||
for _, el := range vec {
|
for _, el := range vec {
|
||||||
|
@ -312,7 +312,7 @@ func funcClampMin(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Ve
|
||||||
}
|
}
|
||||||
|
|
||||||
// === round(Vector parser.ValueTypeVector, toNearest=1 Scalar) Vector ===
|
// === round(Vector parser.ValueTypeVector, toNearest=1 Scalar) Vector ===
|
||||||
func funcRound(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcRound(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
vec := vals[0].(Vector)
|
vec := vals[0].(Vector)
|
||||||
// round returns a number rounded to toNearest.
|
// round returns a number rounded to toNearest.
|
||||||
// Ties are solved by rounding up.
|
// Ties are solved by rounding up.
|
||||||
|
@ -334,7 +334,7 @@ func funcRound(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vecto
|
||||||
}
|
}
|
||||||
|
|
||||||
// === Scalar(node parser.ValueTypeVector) Scalar ===
|
// === Scalar(node parser.ValueTypeVector) Scalar ===
|
||||||
func funcScalar(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcScalar(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
v := vals[0].(Vector)
|
v := vals[0].(Vector)
|
||||||
if len(v) != 1 {
|
if len(v) != 1 {
|
||||||
return append(enh.out, Sample{
|
return append(enh.out, Sample{
|
||||||
|
@ -355,7 +355,7 @@ func aggrOverTime(vals []parser.Value, enh *EvalNodeHelper, aggrFn func([]Point)
|
||||||
}
|
}
|
||||||
|
|
||||||
// === avg_over_time(Matrix parser.ValueTypeMatrix) Vector ===
|
// === avg_over_time(Matrix parser.ValueTypeMatrix) Vector ===
|
||||||
func funcAvgOverTime(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcAvgOverTime(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return aggrOverTime(vals, enh, func(values []Point) float64 {
|
return aggrOverTime(vals, enh, func(values []Point) float64 {
|
||||||
var mean, count float64
|
var mean, count float64
|
||||||
for _, v := range values {
|
for _, v := range values {
|
||||||
|
@ -367,7 +367,7 @@ func funcAvgOverTime(vals []parser.Value, args Expressions, enh *EvalNodeHelper)
|
||||||
}
|
}
|
||||||
|
|
||||||
// === count_over_time(Matrix parser.ValueTypeMatrix) Vector ===
|
// === count_over_time(Matrix parser.ValueTypeMatrix) Vector ===
|
||||||
func funcCountOverTime(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcCountOverTime(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return aggrOverTime(vals, enh, func(values []Point) float64 {
|
return aggrOverTime(vals, enh, func(values []Point) float64 {
|
||||||
return float64(len(values))
|
return float64(len(values))
|
||||||
})
|
})
|
||||||
|
@ -375,7 +375,7 @@ func funcCountOverTime(vals []parser.Value, args Expressions, enh *EvalNodeHelpe
|
||||||
|
|
||||||
// === floor(Vector parser.ValueTypeVector) Vector ===
|
// === floor(Vector parser.ValueTypeVector) Vector ===
|
||||||
// === max_over_time(Matrix parser.ValueTypeMatrix) Vector ===
|
// === max_over_time(Matrix parser.ValueTypeMatrix) Vector ===
|
||||||
func funcMaxOverTime(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcMaxOverTime(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return aggrOverTime(vals, enh, func(values []Point) float64 {
|
return aggrOverTime(vals, enh, func(values []Point) float64 {
|
||||||
max := values[0].V
|
max := values[0].V
|
||||||
for _, v := range values {
|
for _, v := range values {
|
||||||
|
@ -388,7 +388,7 @@ func funcMaxOverTime(vals []parser.Value, args Expressions, enh *EvalNodeHelper)
|
||||||
}
|
}
|
||||||
|
|
||||||
// === min_over_time(Matrix parser.ValueTypeMatrix) Vector ===
|
// === min_over_time(Matrix parser.ValueTypeMatrix) Vector ===
|
||||||
func funcMinOverTime(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcMinOverTime(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return aggrOverTime(vals, enh, func(values []Point) float64 {
|
return aggrOverTime(vals, enh, func(values []Point) float64 {
|
||||||
min := values[0].V
|
min := values[0].V
|
||||||
for _, v := range values {
|
for _, v := range values {
|
||||||
|
@ -401,7 +401,7 @@ func funcMinOverTime(vals []parser.Value, args Expressions, enh *EvalNodeHelper)
|
||||||
}
|
}
|
||||||
|
|
||||||
// === sum_over_time(Matrix parser.ValueTypeMatrix) Vector ===
|
// === sum_over_time(Matrix parser.ValueTypeMatrix) Vector ===
|
||||||
func funcSumOverTime(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcSumOverTime(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return aggrOverTime(vals, enh, func(values []Point) float64 {
|
return aggrOverTime(vals, enh, func(values []Point) float64 {
|
||||||
var sum float64
|
var sum float64
|
||||||
for _, v := range values {
|
for _, v := range values {
|
||||||
|
@ -412,7 +412,7 @@ func funcSumOverTime(vals []parser.Value, args Expressions, enh *EvalNodeHelper)
|
||||||
}
|
}
|
||||||
|
|
||||||
// === quantile_over_time(Matrix parser.ValueTypeMatrix) Vector ===
|
// === quantile_over_time(Matrix parser.ValueTypeMatrix) Vector ===
|
||||||
func funcQuantileOverTime(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcQuantileOverTime(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
q := vals[0].(Vector)[0].V
|
q := vals[0].(Vector)[0].V
|
||||||
el := vals[1].(Matrix)[0]
|
el := vals[1].(Matrix)[0]
|
||||||
|
|
||||||
|
@ -426,7 +426,7 @@ func funcQuantileOverTime(vals []parser.Value, args Expressions, enh *EvalNodeHe
|
||||||
}
|
}
|
||||||
|
|
||||||
// === stddev_over_time(Matrix parser.ValueTypeMatrix) Vector ===
|
// === stddev_over_time(Matrix parser.ValueTypeMatrix) Vector ===
|
||||||
func funcStddevOverTime(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcStddevOverTime(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return aggrOverTime(vals, enh, func(values []Point) float64 {
|
return aggrOverTime(vals, enh, func(values []Point) float64 {
|
||||||
var aux, count, mean float64
|
var aux, count, mean float64
|
||||||
for _, v := range values {
|
for _, v := range values {
|
||||||
|
@ -440,7 +440,7 @@ func funcStddevOverTime(vals []parser.Value, args Expressions, enh *EvalNodeHelp
|
||||||
}
|
}
|
||||||
|
|
||||||
// === stdvar_over_time(Matrix parser.ValueTypeMatrix) Vector ===
|
// === stdvar_over_time(Matrix parser.ValueTypeMatrix) Vector ===
|
||||||
func funcStdvarOverTime(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcStdvarOverTime(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return aggrOverTime(vals, enh, func(values []Point) float64 {
|
return aggrOverTime(vals, enh, func(values []Point) float64 {
|
||||||
var aux, count, mean float64
|
var aux, count, mean float64
|
||||||
for _, v := range values {
|
for _, v := range values {
|
||||||
|
@ -454,7 +454,7 @@ func funcStdvarOverTime(vals []parser.Value, args Expressions, enh *EvalNodeHelp
|
||||||
}
|
}
|
||||||
|
|
||||||
// === absent(Vector parser.ValueTypeVector) Vector ===
|
// === absent(Vector parser.ValueTypeVector) Vector ===
|
||||||
func funcAbsent(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcAbsent(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
if len(vals[0].(Vector)) > 0 {
|
if len(vals[0].(Vector)) > 0 {
|
||||||
return enh.out
|
return enh.out
|
||||||
}
|
}
|
||||||
|
@ -470,7 +470,7 @@ func funcAbsent(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vect
|
||||||
// This function will return 1 if the matrix has at least one element.
|
// This function will return 1 if the matrix has at least one element.
|
||||||
// Due to engine optimization, this function is only called when this condition is true.
|
// Due to engine optimization, this function is only called when this condition is true.
|
||||||
// Then, the engine post-processes the results to get the expected output.
|
// Then, the engine post-processes the results to get the expected output.
|
||||||
func funcAbsentOverTime(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcAbsentOverTime(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return append(enh.out,
|
return append(enh.out,
|
||||||
Sample{
|
Sample{
|
||||||
Point: Point{V: 1},
|
Point: Point{V: 1},
|
||||||
|
@ -488,47 +488,47 @@ func simpleFunc(vals []parser.Value, enh *EvalNodeHelper, f func(float64) float6
|
||||||
}
|
}
|
||||||
|
|
||||||
// === abs(Vector parser.ValueTypeVector) Vector ===
|
// === abs(Vector parser.ValueTypeVector) Vector ===
|
||||||
func funcAbs(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcAbs(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return simpleFunc(vals, enh, math.Abs)
|
return simpleFunc(vals, enh, math.Abs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// === ceil(Vector parser.ValueTypeVector) Vector ===
|
// === ceil(Vector parser.ValueTypeVector) Vector ===
|
||||||
func funcCeil(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcCeil(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return simpleFunc(vals, enh, math.Ceil)
|
return simpleFunc(vals, enh, math.Ceil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// === floor(Vector parser.ValueTypeVector) Vector ===
|
// === floor(Vector parser.ValueTypeVector) Vector ===
|
||||||
func funcFloor(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcFloor(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return simpleFunc(vals, enh, math.Floor)
|
return simpleFunc(vals, enh, math.Floor)
|
||||||
}
|
}
|
||||||
|
|
||||||
// === exp(Vector parser.ValueTypeVector) Vector ===
|
// === exp(Vector parser.ValueTypeVector) Vector ===
|
||||||
func funcExp(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcExp(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return simpleFunc(vals, enh, math.Exp)
|
return simpleFunc(vals, enh, math.Exp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// === sqrt(Vector VectorNode) Vector ===
|
// === sqrt(Vector VectorNode) Vector ===
|
||||||
func funcSqrt(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcSqrt(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return simpleFunc(vals, enh, math.Sqrt)
|
return simpleFunc(vals, enh, math.Sqrt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// === ln(Vector parser.ValueTypeVector) Vector ===
|
// === ln(Vector parser.ValueTypeVector) Vector ===
|
||||||
func funcLn(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcLn(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return simpleFunc(vals, enh, math.Log)
|
return simpleFunc(vals, enh, math.Log)
|
||||||
}
|
}
|
||||||
|
|
||||||
// === log2(Vector parser.ValueTypeVector) Vector ===
|
// === log2(Vector parser.ValueTypeVector) Vector ===
|
||||||
func funcLog2(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcLog2(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return simpleFunc(vals, enh, math.Log2)
|
return simpleFunc(vals, enh, math.Log2)
|
||||||
}
|
}
|
||||||
|
|
||||||
// === log10(Vector parser.ValueTypeVector) Vector ===
|
// === log10(Vector parser.ValueTypeVector) Vector ===
|
||||||
func funcLog10(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcLog10(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return simpleFunc(vals, enh, math.Log10)
|
return simpleFunc(vals, enh, math.Log10)
|
||||||
}
|
}
|
||||||
|
|
||||||
// === timestamp(Vector parser.ValueTypeVector) Vector ===
|
// === timestamp(Vector parser.ValueTypeVector) Vector ===
|
||||||
func funcTimestamp(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcTimestamp(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
vec := vals[0].(Vector)
|
vec := vals[0].(Vector)
|
||||||
for _, el := range vec {
|
for _, el := range vec {
|
||||||
enh.out = append(enh.out, Sample{
|
enh.out = append(enh.out, Sample{
|
||||||
|
@ -565,7 +565,7 @@ func linearRegression(samples []Point, interceptTime int64) (slope, intercept fl
|
||||||
}
|
}
|
||||||
|
|
||||||
// === deriv(node parser.ValueTypeMatrix) Vector ===
|
// === deriv(node parser.ValueTypeMatrix) Vector ===
|
||||||
func funcDeriv(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcDeriv(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
samples := vals[0].(Matrix)[0]
|
samples := vals[0].(Matrix)[0]
|
||||||
|
|
||||||
// No sense in trying to compute a derivative without at least two points.
|
// No sense in trying to compute a derivative without at least two points.
|
||||||
|
@ -584,7 +584,7 @@ func funcDeriv(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vecto
|
||||||
}
|
}
|
||||||
|
|
||||||
// === predict_linear(node parser.ValueTypeMatrix, k parser.ValueTypeScalar) Vector ===
|
// === predict_linear(node parser.ValueTypeMatrix, k parser.ValueTypeScalar) Vector ===
|
||||||
func funcPredictLinear(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcPredictLinear(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
samples := vals[0].(Matrix)[0]
|
samples := vals[0].(Matrix)[0]
|
||||||
duration := vals[1].(Vector)[0].V
|
duration := vals[1].(Vector)[0].V
|
||||||
|
|
||||||
|
@ -601,7 +601,7 @@ func funcPredictLinear(vals []parser.Value, args Expressions, enh *EvalNodeHelpe
|
||||||
}
|
}
|
||||||
|
|
||||||
// === histogram_quantile(k parser.ValueTypeScalar, Vector parser.ValueTypeVector) Vector ===
|
// === histogram_quantile(k parser.ValueTypeScalar, Vector parser.ValueTypeVector) Vector ===
|
||||||
func funcHistogramQuantile(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcHistogramQuantile(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
q := vals[0].(Vector)[0].V
|
q := vals[0].(Vector)[0].V
|
||||||
inVec := vals[1].(Vector)
|
inVec := vals[1].(Vector)
|
||||||
sigf := enh.signatureFunc(false, excludedLabels...)
|
sigf := enh.signatureFunc(false, excludedLabels...)
|
||||||
|
@ -649,7 +649,7 @@ func funcHistogramQuantile(vals []parser.Value, args Expressions, enh *EvalNodeH
|
||||||
}
|
}
|
||||||
|
|
||||||
// === resets(Matrix parser.ValueTypeMatrix) Vector ===
|
// === resets(Matrix parser.ValueTypeMatrix) Vector ===
|
||||||
func funcResets(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcResets(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
samples := vals[0].(Matrix)[0]
|
samples := vals[0].(Matrix)[0]
|
||||||
|
|
||||||
resets := 0
|
resets := 0
|
||||||
|
@ -668,7 +668,7 @@ func funcResets(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vect
|
||||||
}
|
}
|
||||||
|
|
||||||
// === changes(Matrix parser.ValueTypeMatrix) Vector ===
|
// === changes(Matrix parser.ValueTypeMatrix) Vector ===
|
||||||
func funcChanges(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcChanges(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
samples := vals[0].(Matrix)[0]
|
samples := vals[0].(Matrix)[0]
|
||||||
|
|
||||||
changes := 0
|
changes := 0
|
||||||
|
@ -687,7 +687,7 @@ func funcChanges(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vec
|
||||||
}
|
}
|
||||||
|
|
||||||
// === label_replace(Vector parser.ValueTypeVector, dst_label, replacement, src_labelname, regex parser.ValueTypeString) Vector ===
|
// === label_replace(Vector parser.ValueTypeVector, dst_label, replacement, src_labelname, regex parser.ValueTypeString) Vector ===
|
||||||
func funcLabelReplace(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcLabelReplace(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
var (
|
var (
|
||||||
vector = vals[0].(Vector)
|
vector = vals[0].(Vector)
|
||||||
dst = args[1].(*StringLiteral).Val
|
dst = args[1].(*StringLiteral).Val
|
||||||
|
@ -741,7 +741,7 @@ func funcLabelReplace(vals []parser.Value, args Expressions, enh *EvalNodeHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
// === Vector(s Scalar) Vector ===
|
// === Vector(s Scalar) Vector ===
|
||||||
func funcVector(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcVector(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return append(enh.out,
|
return append(enh.out,
|
||||||
Sample{
|
Sample{
|
||||||
Metric: labels.Labels{},
|
Metric: labels.Labels{},
|
||||||
|
@ -750,7 +750,7 @@ func funcVector(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vect
|
||||||
}
|
}
|
||||||
|
|
||||||
// === label_join(vector model.ValVector, dest_labelname, separator, src_labelname...) Vector ===
|
// === label_join(vector model.ValVector, dest_labelname, separator, src_labelname...) Vector ===
|
||||||
func funcLabelJoin(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcLabelJoin(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
var (
|
var (
|
||||||
vector = vals[0].(Vector)
|
vector = vals[0].(Vector)
|
||||||
dst = args[1].(*StringLiteral).Val
|
dst = args[1].(*StringLiteral).Val
|
||||||
|
@ -828,49 +828,49 @@ func dateWrapper(vals []parser.Value, enh *EvalNodeHelper, f func(time.Time) flo
|
||||||
}
|
}
|
||||||
|
|
||||||
// === days_in_month(v Vector) Scalar ===
|
// === days_in_month(v Vector) Scalar ===
|
||||||
func funcDaysInMonth(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcDaysInMonth(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return dateWrapper(vals, enh, func(t time.Time) float64 {
|
return dateWrapper(vals, enh, func(t time.Time) float64 {
|
||||||
return float64(32 - time.Date(t.Year(), t.Month(), 32, 0, 0, 0, 0, time.UTC).Day())
|
return float64(32 - time.Date(t.Year(), t.Month(), 32, 0, 0, 0, 0, time.UTC).Day())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// === day_of_month(v Vector) Scalar ===
|
// === day_of_month(v Vector) Scalar ===
|
||||||
func funcDayOfMonth(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcDayOfMonth(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return dateWrapper(vals, enh, func(t time.Time) float64 {
|
return dateWrapper(vals, enh, func(t time.Time) float64 {
|
||||||
return float64(t.Day())
|
return float64(t.Day())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// === day_of_week(v Vector) Scalar ===
|
// === day_of_week(v Vector) Scalar ===
|
||||||
func funcDayOfWeek(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcDayOfWeek(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return dateWrapper(vals, enh, func(t time.Time) float64 {
|
return dateWrapper(vals, enh, func(t time.Time) float64 {
|
||||||
return float64(t.Weekday())
|
return float64(t.Weekday())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// === hour(v Vector) Scalar ===
|
// === hour(v Vector) Scalar ===
|
||||||
func funcHour(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcHour(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return dateWrapper(vals, enh, func(t time.Time) float64 {
|
return dateWrapper(vals, enh, func(t time.Time) float64 {
|
||||||
return float64(t.Hour())
|
return float64(t.Hour())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// === minute(v Vector) Scalar ===
|
// === minute(v Vector) Scalar ===
|
||||||
func funcMinute(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcMinute(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return dateWrapper(vals, enh, func(t time.Time) float64 {
|
return dateWrapper(vals, enh, func(t time.Time) float64 {
|
||||||
return float64(t.Minute())
|
return float64(t.Minute())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// === month(v Vector) Scalar ===
|
// === month(v Vector) Scalar ===
|
||||||
func funcMonth(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcMonth(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return dateWrapper(vals, enh, func(t time.Time) float64 {
|
return dateWrapper(vals, enh, func(t time.Time) float64 {
|
||||||
return float64(t.Month())
|
return float64(t.Month())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// === year(v Vector) Scalar ===
|
// === year(v Vector) Scalar ===
|
||||||
func funcYear(vals []parser.Value, args Expressions, enh *EvalNodeHelper) Vector {
|
func funcYear(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return dateWrapper(vals, enh, func(t time.Time) float64 {
|
return dateWrapper(vals, enh, func(t time.Time) float64 {
|
||||||
return float64(t.Year())
|
return float64(t.Year())
|
||||||
})
|
})
|
||||||
|
@ -1237,15 +1237,15 @@ func (s *vectorByReverseValueHeap) Pop() interface{} {
|
||||||
|
|
||||||
// createLabelsForAbsentFunction returns the labels that are uniquely and exactly matched
|
// createLabelsForAbsentFunction returns the labels that are uniquely and exactly matched
|
||||||
// in a given expression. It is used in the absent functions.
|
// in a given expression. It is used in the absent functions.
|
||||||
func createLabelsForAbsentFunction(expr Expr) labels.Labels {
|
func createLabelsForAbsentFunction(expr parser.Expr) labels.Labels {
|
||||||
m := labels.Labels{}
|
m := labels.Labels{}
|
||||||
|
|
||||||
var lm []*labels.Matcher
|
var lm []*labels.Matcher
|
||||||
switch n := expr.(type) {
|
switch n := expr.(type) {
|
||||||
case *VectorSelector:
|
case *parser.VectorSelector:
|
||||||
lm = n.LabelMatchers
|
lm = n.LabelMatchers
|
||||||
case *MatrixSelector:
|
case *MatrixSelector:
|
||||||
lm = n.VectorSelector.(*VectorSelector).LabelMatchers
|
lm = n.parser.VectorSelector.(*parser.VectorSelector).LabelMatchers
|
||||||
default:
|
default:
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue