Skip to content

Commit

Permalink
[v10.0.x] Alerting: Exclude expression refIDs from NoData state (#72394)
Browse files Browse the repository at this point in the history
* Alerting: Exclude expression refIDs from NoData state (#72219)

(cherry picked from commit 5ba164d)

* use expr.IsDatasource

---------

Co-authored-by: Yuri Tseretyan <yuriy.tseretyan@grafana.com>
  • Loading branch information
grafana-delivery-bot[bot] and yuri-tceretian committed Jul 26, 2023
1 parent 1389f0f commit f848c9d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 1 addition & 3 deletions pkg/services/ngalert/eval/eval.go
Expand Up @@ -322,8 +322,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 @@ -345,7 +343,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.IsDataSource(s) {
result.NoData[refID] = s
}
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/services/ngalert/eval/eval_test.go
Expand Up @@ -561,11 +561,19 @@ func TestEvaluate(t *testing.T) {
Data: []models.AlertQuery{{
RefID: "A",
DatasourceUID: "test",
}, {
RefID: "B",
DatasourceUID: expr.DatasourceUID,
}, {
RefID: "C",
DatasourceUID: expr.OldDatasourceUID,
}},
},
resp: backend.QueryDataResponse{
Responses: backend.Responses{
"A": {Frames: nil},
"B": {Frames: []*data.Frame{{Fields: nil}}},
"C": {Frames: nil},
},
},
expected: Results{{
Expand Down

0 comments on commit f848c9d

Please sign in to comment.