Skip to content

Commit

Permalink
Alerting: Exclude expression refIDs from NoData state (#72219)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuri-tceretian authored and sarahzinger committed Aug 1, 2023
1 parent 4035ba9 commit eac726b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 1 addition & 3 deletions pkg/services/ngalert/eval/eval.go
Expand Up @@ -324,8 +324,6 @@ func queryDataResponseToExecutionResults(c models.Condition, execResp *backend.Q
for _, next := range c.Data {
datasourceUIDsForRefIDs[next.RefID] = next.DatasourceUID
}
// datasourceExprUID is a special DatasourceUID for expressions
datasourceExprUID := strconv.FormatInt(expr.DatasourceID, 10)

result := ExecutionResults{Results: make(map[string]data.Frames)}
for refID, res := range execResp.Responses {
Expand All @@ -347,7 +345,7 @@ func queryDataResponseToExecutionResults(c models.Condition, execResp *backend.Q
hasNoFrames := len(res.Frames) == 0
hasNoFields := len(res.Frames) == 1 && len(res.Frames[0].Fields) == 0
if hasNoFrames || hasNoFields {
if s, ok := datasourceUIDsForRefIDs[refID]; ok && s != datasourceExprUID {
if s, ok := datasourceUIDsForRefIDs[refID]; ok && expr.NodeTypeFromDatasourceUID(s) == expr.TypeDatasourceNode { // TODO perhaps extract datasource UID from ML expression too.
result.NoData[refID] = s
}
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/services/ngalert/eval/eval_test.go
Expand Up @@ -562,11 +562,23 @@ func TestEvaluate(t *testing.T) {
Data: []models.AlertQuery{{
RefID: "A",
DatasourceUID: "test",
}, {
RefID: "B",
DatasourceUID: expr.DatasourceUID,
}, {
RefID: "C",
DatasourceUID: expr.OldDatasourceUID,
}, {
RefID: "D",
DatasourceUID: expr.MLDatasourceUID,
}},
},
resp: backend.QueryDataResponse{
Responses: backend.Responses{
"A": {Frames: nil},
"B": {Frames: []*data.Frame{{Fields: nil}}},
"C": {Frames: nil},
"D": {Frames: []*data.Frame{{Fields: nil}}},
},
},
expected: Results{{
Expand Down

0 comments on commit eac726b

Please sign in to comment.