mirror of
https://github.com/grafana/grafana.git
synced 2026-08-13 06:34:55 -05:00
AlertingNG: rename Condition properties to match front end (#32267)
This commit is contained in:
@@ -213,7 +213,7 @@ func (dc *dashConditionsJSON) GetNew(orgID int64) (*ngmodels.Condition, error) {
|
||||
RelativeTimeRange: *rTR,
|
||||
DatasourceUID: getDsInfo.Uid,
|
||||
}
|
||||
ngCond.QueriesAndExpressions = append(ngCond.QueriesAndExpressions, alertQuery)
|
||||
ngCond.Data = append(ngCond.Data, alertQuery)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,7 +236,7 @@ func (dc *dashConditionsJSON) GetNew(orgID int64) (*ngmodels.Condition, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ngCond.RefID = ccRefID // set the alert condition to point to the classic condition
|
||||
ngCond.Condition = ccRefID // set the alert condition to point to the classic condition
|
||||
ngCond.OrgID = orgID
|
||||
|
||||
exprModel := struct {
|
||||
@@ -261,17 +261,17 @@ func (dc *dashConditionsJSON) GetNew(orgID int64) (*ngmodels.Condition, error) {
|
||||
Model: exprModelJSON,
|
||||
}
|
||||
|
||||
ngCond.QueriesAndExpressions = append(ngCond.QueriesAndExpressions, ccAlertQuery)
|
||||
ngCond.Data = append(ngCond.Data, ccAlertQuery)
|
||||
|
||||
for i := range ngCond.QueriesAndExpressions {
|
||||
err := ngCond.QueriesAndExpressions[i].PreSave() // Set query model properties
|
||||
for i := range ngCond.Data {
|
||||
err := ngCond.Data[i].PreSave() // Set query model properties
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
sort.Slice(ngCond.QueriesAndExpressions, func(i, j int) bool {
|
||||
return ngCond.QueriesAndExpressions[i].RefID < ngCond.QueriesAndExpressions[j].RefID
|
||||
sort.Slice(ngCond.Data, func(i, j int) bool {
|
||||
return ngCond.Data[i].RefID < ngCond.Data[j].RefID
|
||||
})
|
||||
|
||||
return ngCond, nil
|
||||
|
||||
@@ -31,24 +31,24 @@ func TestDashboardAlertConditions(t *testing.T) {
|
||||
name: "two conditions one query but different time ranges",
|
||||
inputJSONFName: `sameQueryDifferentTimeRange.json`,
|
||||
spotCheckFn: func(t *testing.T, cond *ngmodels.Condition) {
|
||||
require.Equal(t, "C", cond.RefID, "unexpected refId for condition")
|
||||
require.Equal(t, 3, len(cond.QueriesAndExpressions), "unexpected query/expression array length")
|
||||
require.Equal(t, "C", cond.Condition, "unexpected refId for condition")
|
||||
require.Equal(t, 3, len(cond.Data), "unexpected query/expression array length")
|
||||
|
||||
firstQuery := cond.QueriesAndExpressions[0]
|
||||
firstQuery := cond.Data[0]
|
||||
require.Equal(t, "A", firstQuery.RefID, "unexpected refId for first query")
|
||||
require.Equal(t, ngmodels.RelativeTimeRange{
|
||||
From: ngmodels.Duration(time.Second * 600),
|
||||
To: ngmodels.Duration(time.Second * 300),
|
||||
}, firstQuery.RelativeTimeRange, "unexpected timerange for first query")
|
||||
|
||||
secondQuery := cond.QueriesAndExpressions[1]
|
||||
secondQuery := cond.Data[1]
|
||||
require.Equal(t, "B", secondQuery.RefID, "unexpected refId for second query")
|
||||
require.Equal(t, ngmodels.RelativeTimeRange{
|
||||
From: ngmodels.Duration(time.Second * 300),
|
||||
To: ngmodels.Duration(0),
|
||||
}, secondQuery.RelativeTimeRange, "unexpected timerange for second query")
|
||||
|
||||
condQuery := cond.QueriesAndExpressions[2]
|
||||
condQuery := cond.Data[2]
|
||||
require.Equal(t, "C", condQuery.RefID, "unexpected refId for second query")
|
||||
isExpr, err := condQuery.IsExpression()
|
||||
require.NoError(t, err)
|
||||
@@ -78,10 +78,10 @@ func TestDashboardAlertConditions(t *testing.T) {
|
||||
name: "mixed shared and unshared time ranges",
|
||||
inputJSONFName: `mixedSharedUnsharedTimeRange.json`,
|
||||
spotCheckFn: func(t *testing.T, cond *ngmodels.Condition) {
|
||||
require.Equal(t, "G", cond.RefID, "unexpected refId for condition")
|
||||
require.Equal(t, 7, len(cond.QueriesAndExpressions), "unexpected query/expression array length")
|
||||
require.Equal(t, "G", cond.Condition, "unexpected refId for condition")
|
||||
require.Equal(t, 7, len(cond.Data), "unexpected query/expression array length")
|
||||
|
||||
condQuery := cond.QueriesAndExpressions[6]
|
||||
condQuery := cond.Data[6]
|
||||
isExpr, err := condQuery.IsExpression()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, true, isExpr, "expected last query to be an expression")
|
||||
@@ -123,7 +123,7 @@ func TestDashboardAlertConditions(t *testing.T) {
|
||||
}
|
||||
|
||||
func alertRuleByRefId(cond *ngmodels.Condition, refID string) (ngmodels.AlertQuery, error) {
|
||||
for _, aq := range cond.QueriesAndExpressions {
|
||||
for _, aq := range cond.Data {
|
||||
if aq.RefID == refID {
|
||||
return aq, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user