@ -175,7 +175,7 @@ func (q *query) Exec(ctx context.Context) *Result {
span . SetTag ( queryTag , q . stmt . String ( ) )
}
res , err, warnings := q . ng . exec ( ctx , q )
res , warnings, err := q . ng . exec ( ctx , q )
return & Result { Err : err , Value : res , Warnings : warnings }
}
@ -353,7 +353,7 @@ func (ng *Engine) newTestQuery(f func(context.Context) error) Query {
//
// At this point per query only one EvalStmt is evaluated. Alert and record
// statements are not handled by the Engine.
func ( ng * Engine ) exec ( ctx context . Context , q * query ) ( Value , error , storage . Warnings ) {
func ( ng * Engine ) exec ( ctx context . Context , q * query ) ( Value , storage . Warnings , error ) {
ng . metrics . currentQueries . Inc ( )
defer ng . metrics . currentQueries . Dec ( )
@ -366,7 +366,7 @@ func (ng *Engine) exec(ctx context.Context, q *query) (Value, error, storage.War
queueSpanTimer , _ := q . stats . GetSpanTimer ( ctx , stats . ExecQueueTime , ng . metrics . queryQueueTime )
if err := ng . gate . Start ( ctx ) ; err != nil {
return nil , contextErr ( err , "query queue" ) , nil
return nil , nil , contextErr ( err , "query queue" )
}
defer ng . gate . Done ( )
@ -382,14 +382,14 @@ func (ng *Engine) exec(ctx context.Context, q *query) (Value, error, storage.War
// The base context might already be canceled on the first iteration (e.g. during shutdown).
if err := contextDone ( ctx , env ) ; err != nil {
return nil , err , nil
return nil , nil , err
}
switch s := q . Statement ( ) . ( type ) {
case * EvalStmt :
return ng . execEvalStmt ( ctx , q , s )
case testStmt :
return nil , s ( ctx ) , nil
return nil , nil , s ( ctx )
}
panic ( fmt . Errorf ( "promql.Engine.exec: unhandled statement of type %T" , q . Statement ( ) ) )
@ -404,9 +404,9 @@ func durationMilliseconds(d time.Duration) int64 {
}
// execEvalStmt evaluates the expression of an evaluation statement for the given time range.
func ( ng * Engine ) execEvalStmt ( ctx context . Context , query * query , s * EvalStmt ) ( Value , error , storage . Warnings ) {
func ( ng * Engine ) execEvalStmt ( ctx context . Context , query * query , s * EvalStmt ) ( Value , storage . Warnings , error ) {
prepareSpanTimer , ctxPrepare := query . stats . GetSpanTimer ( ctx , stats . QueryPreparationTime , ng . metrics . queryPrepareTime )
querier , err, warnings := ng . populateSeries ( ctxPrepare , query . queryable , s )
querier , warnings, err := ng . populateSeries ( ctxPrepare , query . queryable , s )
prepareSpanTimer . Finish ( )
// XXX(fabxc): the querier returned by populateSeries might be instantiated
@ -417,7 +417,7 @@ func (ng *Engine) execEvalStmt(ctx context.Context, query *query, s *EvalStmt) (
}
if err != nil {
return nil , err, warnings
return nil , warnings, err
}
evalSpanTimer , _ := query . stats . GetSpanTimer ( ctx , stats . InnerEvalTime , ng . metrics . queryInnerEval )
@ -435,7 +435,7 @@ func (ng *Engine) execEvalStmt(ctx context.Context, query *query, s *EvalStmt) (
}
val , err := evaluator . Eval ( s . Expr )
if err != nil {
return nil , err, warnings
return nil , warnings, err
}
evalSpanTimer . Finish ( )
@ -454,11 +454,11 @@ func (ng *Engine) execEvalStmt(ctx context.Context, query *query, s *EvalStmt) (
// timestamp as that is when we ran the evaluation.
vector [ i ] = Sample { Metric : s . Metric , Point : Point { V : s . Points [ 0 ] . V , T : start } }
}
return vector , nil , warnings
return vector , warnings , nil
case ValueTypeScalar :
return Scalar { V : mat [ 0 ] . Points [ 0 ] . V , T : start } , nil , warnings
return Scalar { V : mat [ 0 ] . Points [ 0 ] . V , T : start } , warnings , nil
case ValueTypeMatrix :
return mat , nil , warnings
return mat , warnings , nil
default :
panic ( fmt . Errorf ( "promql.Engine.exec: unexpected expression type %q" , s . Expr . Type ( ) ) )
}
@ -477,7 +477,7 @@ func (ng *Engine) execEvalStmt(ctx context.Context, query *query, s *EvalStmt) (
}
val , err := evaluator . Eval ( s . Expr )
if err != nil {
return nil , err, warnings
return nil , warnings, err
}
evalSpanTimer . Finish ( )
@ -488,7 +488,7 @@ func (ng *Engine) execEvalStmt(ctx context.Context, query *query, s *EvalStmt) (
query . matrix = mat
if err := contextDone ( ctx , "expression evaluation" ) ; err != nil {
return nil , err, warnings
return nil , warnings, err
}
// TODO(fabxc): order ensured by storage?
@ -497,7 +497,7 @@ func (ng *Engine) execEvalStmt(ctx context.Context, query *query, s *EvalStmt) (
sort . Sort ( mat )
sortSpanTimer . Finish ( )
return mat , nil , warnings
return mat , warnings , nil
}
// cumulativeSubqueryOffset returns the sum of range and offset of all subqueries in the path.
@ -512,7 +512,7 @@ func (ng *Engine) cumulativeSubqueryOffset(path []Node) time.Duration {
return subqOffset
}
func ( ng * Engine ) populateSeries ( ctx context . Context , q storage . Queryable , s * EvalStmt ) ( storage . Querier , error , storage . Warnings ) {
func ( ng * Engine ) populateSeries ( ctx context . Context , q storage . Queryable , s * EvalStmt ) ( storage . Querier , storage . Warnings , error ) {
var maxOffset time . Duration
Inspect ( s . Expr , func ( node Node , path [ ] Node ) error {
subqOffset := ng . cumulativeSubqueryOffset ( path )
@ -539,7 +539,7 @@ func (ng *Engine) populateSeries(ctx context.Context, q storage.Queryable, s *Ev
querier , err := q . Querier ( ctx , timestamp . FromTime ( mint ) , timestamp . FromTime ( s . End ) )
if err != nil {
return nil , err , nil
return nil , nil , err
}
var warnings storage . Warnings
@ -592,7 +592,7 @@ func (ng *Engine) populateSeries(ctx context.Context, q storage.Queryable, s *Ev
}
return nil
} )
return querier , err, warnings
return querier , warnings, err
}
// extractFuncFromPath walks up the path and searches for the first instance of
@ -1243,6 +1243,7 @@ func getPointSlice(sz int) []Point {
}
func putPointSlice ( p [ ] Point ) {
//lint:ignore SA6002 relax staticcheck verification.
pointPool . Put ( p [ : 0 ] )
}
@ -1665,21 +1666,6 @@ func vectorElemBinop(op ItemType, lhs, rhs float64) (float64, bool) {
panic ( fmt . Errorf ( "operator %q not allowed for operations between Vectors" , op ) )
}
// intersection returns the metric of common label/value pairs of two input metrics.
func intersection ( ls1 , ls2 labels . Labels ) labels . Labels {
res := make ( labels . Labels , 0 , 5 )
for _ , l1 := range ls1 {
for _ , l2 := range ls2 {
if l1 . Name == l2 . Name && l1 . Value == l2 . Value {
res = append ( res , l1 )
continue
}
}
}
return res
}
type groupedAggregation struct {
labels labels . Labels
value float64