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
+2 -1
View File
@@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"strconv"
"time"
"github.com/grafana/grafana-plugin-sdk-go/data"
@@ -67,7 +68,7 @@ func (cmd *ConditionsCmd) NeedsVars() []string {
// Execute runs the command and returns the results or an error if the command
// failed to execute.
func (cmd *ConditionsCmd) Execute(_ context.Context, vars mathexp.Vars) (mathexp.Results, error) {
func (cmd *ConditionsCmd) Execute(_ context.Context, _ time.Time, vars mathexp.Vars) (mathexp.Results, error) {
firing := true
newRes := mathexp.Results{}
noDataFound := true
+2 -1
View File
@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"testing"
"time"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/stretchr/testify/require"
@@ -405,7 +406,7 @@ func TestConditionsCmdExecute(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
res, err := tt.conditionsCmd.Execute(context.Background(), tt.vars)
res, err := tt.conditionsCmd.Execute(context.Background(), time.Now(), tt.vars)
require.NoError(t, err)
require.Equal(t, 1, len(res.Values))