Alerting: Support for condition field in /api/v1/eval (#79032)
Co-authored-by: Sonia Aguilar <soniaaguilarpeiron@gmail.com>
This commit is contained in:
co-authored by
Sonia Aguilar
parent
7a38a2e48b
commit
7e331c8507
@@ -156,11 +156,11 @@ func (srv TestingApiSrv) RouteEvalQueries(c *contextmodel.ReqContext, cmd apimod
|
||||
}
|
||||
|
||||
cond := ngmodels.Condition{
|
||||
Condition: "",
|
||||
Condition: cmd.Condition,
|
||||
Data: queries,
|
||||
}
|
||||
if len(cmd.Data) > 0 {
|
||||
cond.Condition = cmd.Data[0].RefID
|
||||
if cond.Condition == "" && len(cond.Data) > 0 {
|
||||
cond.Condition = cond.Data[len(cond.Data)-1].RefID
|
||||
}
|
||||
|
||||
_, err := store.OptimizeAlertQueries(cond.Data)
|
||||
|
||||
@@ -128,8 +128,9 @@ type EvalQueriesRequest struct {
|
||||
|
||||
// swagger:model
|
||||
type EvalQueriesPayload struct {
|
||||
Data []AlertQuery `json:"data"`
|
||||
Now time.Time `json:"now"`
|
||||
Condition string `json:"condition"`
|
||||
Data []AlertQuery `json:"data"`
|
||||
Now time.Time `json:"now"`
|
||||
}
|
||||
|
||||
func (p *TestRulePayload) UnmarshalJSON(b []byte) error {
|
||||
|
||||
@@ -2164,6 +2164,7 @@ func TestIntegrationEval(t *testing.T) {
|
||||
}
|
||||
}
|
||||
],
|
||||
"condition": "A",
|
||||
"now": "2021-04-11T14:38:14Z"
|
||||
}
|
||||
`,
|
||||
@@ -2221,6 +2222,7 @@ func TestIntegrationEval(t *testing.T) {
|
||||
}
|
||||
}
|
||||
],
|
||||
"condition": "A",
|
||||
"now": "2021-04-11T14:38:14Z"
|
||||
}
|
||||
`,
|
||||
@@ -2276,6 +2278,7 @@ func TestIntegrationEval(t *testing.T) {
|
||||
}
|
||||
}
|
||||
],
|
||||
"condition": "A",
|
||||
"now": "2021-04-11T14:38:14Z"
|
||||
}
|
||||
`,
|
||||
@@ -2293,6 +2296,63 @@ func TestIntegrationEval(t *testing.T) {
|
||||
return "Failed to build evaluator for queries and expressions: failed to build query 'A': data source not found"
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "condition is empty",
|
||||
payload: `
|
||||
{
|
||||
"data": [
|
||||
{
|
||||
"refId": "A",
|
||||
"relativeTimeRange": {
|
||||
"from": 18000,
|
||||
"to": 10800
|
||||
},
|
||||
"datasourceUid": "__expr__",
|
||||
"model": {
|
||||
"type":"math",
|
||||
"expression":"1 > 2"
|
||||
}
|
||||
}
|
||||
],
|
||||
"now": "2021-04-11T14:38:14Z"
|
||||
}
|
||||
`,
|
||||
expectedStatusCode: func() int { return http.StatusOK },
|
||||
expectedMessage: func() string { return "" },
|
||||
expectedResponse: func() string {
|
||||
return `{
|
||||
"results": {
|
||||
"A": {
|
||||
"status": 200,
|
||||
"frames": [
|
||||
{
|
||||
"schema": {
|
||||
"refId": "A",
|
||||
"fields": [
|
||||
{
|
||||
"name": "A",
|
||||
"type": "number",
|
||||
"typeInfo": {
|
||||
"frame": "float64",
|
||||
"nullable": true
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"data": {
|
||||
"values": [
|
||||
[
|
||||
0
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}`
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
|
||||
Reference in New Issue
Block a user