Chore: Expression engine to support relative time range (#57474)

* make TimeRange interface and add relative range
* make Execute methods support the current time
* update resample to support relative time range
* update DSNode to support relative time range
* update query service to create queries with absolute time
* make alerting evaluator create relative time ranges
This commit is contained in:
Yuriy Tseretyan
2022-10-26 16:13:58 -04:00
committed by GitHub
parent 596b4fecb0
commit 2d20c8db7b
15 changed files with 79 additions and 42 deletions
+4 -3
View File
@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"time"
"github.com/grafana/grafana/pkg/expr/mathexp"
@@ -37,7 +38,7 @@ type Node interface {
ID() int64 // ID() allows the gonum graph node interface to be fulfilled
NodeType() NodeType
RefID() string
Execute(c context.Context, vars mathexp.Vars, s *Service) (mathexp.Results, error)
Execute(ctx context.Context, now time.Time, vars mathexp.Vars, s *Service) (mathexp.Results, error)
String() string
}
@@ -46,10 +47,10 @@ type DataPipeline []Node
// execute runs all the command/datasource requests in the pipeline return a
// map of the refId of the of each command
func (dp *DataPipeline) execute(c context.Context, s *Service) (mathexp.Vars, error) {
func (dp *DataPipeline) execute(c context.Context, now time.Time, s *Service) (mathexp.Vars, error) {
vars := make(mathexp.Vars)
for _, node := range *dp {
res, err := node.Execute(c, vars, s)
res, err := node.Execute(c, now, vars, s)
if err != nil {
return nil, err
}