fix(alerting): extend instant vector check for non-nullable types (#93323)

This commit is contained in:
Jean-Philippe Quéméner
2024-09-17 13:20:40 +02:00
committed by GitHub
parent 41cd0f5180
commit 10314585ec
2 changed files with 81 additions and 6 deletions
+71
View File
@@ -2,6 +2,7 @@ package eval
import (
"context"
"encoding/json"
"errors"
"fmt"
"math/rand"
@@ -1342,6 +1343,76 @@ func TestCreate(t *testing.T) {
})
}
func TestQueryServiceResponse(t *testing.T) {
data := `
{
"results": {
"A": {
"status": 200,
"frames": [
{
"schema": {
"refId": "A",
"meta": {
"type": "numeric-multi",
"typeVersion": [
0,
1
],
"custom": {
"resultType": "scalar"
},
"executedQueryString": "Expr: 1\nStep: 15s"
},
"fields": [
{
"name": "Time",
"type": "time",
"typeInfo": {
"frame": "time.Time"
},
"config": {
"interval": 15000
}
},
{
"name": "Value",
"type": "number",
"typeInfo": {
"frame": "float64"
},
"labels": {},
"config": {
"displayNameFromDS": "1"
}
}
]
},
"data": {
"values": [
[
1719855251019
],
[
1
]
]
}
}
]
}
}
}
`
var s backend.QueryDataResponse
err := json.Unmarshal([]byte(data), &s)
require.NoError(t, err)
res := EvaluateAlert(&s, models.Condition{Condition: "A"}, time.Time{})
require.Equal(t, 1, len(res))
require.Equal(t, Alerting, res[0].State)
}
type fakeExpressionService struct {
hook func(ctx context.Context, now time.Time, pipeline expr.DataPipeline) (*backend.QueryDataResponse, error)
buildHook func(req *expr.Request) (expr.DataPipeline, error)