Skip to content

Commit

Permalink
DEV-45405 - Fix more grafana tests (#54)
Browse files Browse the repository at this point in the history
fix tests from change of ExecErrState:
api_provisioning_test.go
api_ruler_export_test.go
api_ruler_validation_test.go
  • Loading branch information
yasmin-tr authored Nov 3, 2024
1 parent 2996e94 commit 39dc34a
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 22 deletions.
3 changes: 2 additions & 1 deletion pkg/services/ngalert/api/api_provisioning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ func TestProvisioningApi(t *testing.T) {
insertRule(t, sut, rule1)
insertRule(t, sut, createTestAlertRule("rule2", 1))

// LOGZ.IO GRAFANA CHANGE :: DEV-46410 - Change default ExecErrState to OK and enforce OK value
expectedResponse := `resource "grafana_rule_group" "rule_group_0000" {
org_id = 1
name = "my-cool-group"
Expand All @@ -610,7 +611,7 @@ func TestProvisioningApi(t *testing.T) {
}
no_data_state = "Alerting"
exec_err_state = "Error"
exec_err_state = "OK"
for = "0s"
annotations = {
test = "annotation"
Expand Down
1 change: 1 addition & 0 deletions pkg/services/ngalert/api/api_ruler_export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestExportFromPayload(t *testing.T) {

srv := createService(ruleStore)

// LOGZ.IO GRAFANA CHANGE :: DEV-46410 - Change default ExecErrState to OK and enforce OK value - changed in test files: post-rulegroup-101.json, post-rulegroup-101-export.yaml, post-rulegroup-101-export.json, post-rulegroup-101-export.hcl
requestFile := "post-rulegroup-101.json"
rawBody, err := testData.ReadFile(path.Join("test-data", requestFile))
require.NoError(t, err)
Expand Down
27 changes: 14 additions & 13 deletions pkg/services/ngalert/api/api_ruler_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func validRule() apimodels.PostableExtendedRuleNode {
},
UID: util.GenerateShortUID(),
NoDataState: allNoData[rand.Intn(len(allNoData))],
ExecErrState: allExecError[rand.Intn(len(allExecError))],
ExecErrState: apimodels.OkErrState, // LOGZ.IO GRAFANA CHANGE :: DEV-46410 - Change default ExecErrState to OK and enforce OK value
},
}
}
Expand Down Expand Up @@ -365,14 +365,14 @@ func TestValidateRuleNode_NoUID(t *testing.T) {
},
},
{
name: "defaults to Alerting if ExecErrState is empty",
name: "defaults to OK if ExecErrState is empty", // LOGZ.IO GRAFANA CHANGE :: DEV-46410 - Change default ExecErrState to OK and enforce OK value
rule: func() *apimodels.PostableExtendedRuleNode {
r := validRule()
r.GrafanaManagedAlert.ExecErrState = ""
return &r
},
assert: func(t *testing.T, api *apimodels.PostableExtendedRuleNode, alert *models.AlertRule) {
require.Equal(t, models.AlertingErrState, alert.ExecErrState)
require.Equal(t, models.OkErrState, alert.ExecErrState) // LOGZ.IO GRAFANA CHANGE :: DEV-46410 - Change default ExecErrState to OK and enforce OK value
},
},
{
Expand Down Expand Up @@ -459,14 +459,15 @@ func TestValidateRuleNodeFailures_NoUID(t *testing.T) {
return &r
},
},
{
name: "fail if ExecErrState is not known",
rule: func() *apimodels.PostableExtendedRuleNode {
r := validRule()
r.GrafanaManagedAlert.ExecErrState = apimodels.ExecutionErrorState(util.GenerateShortUID())
return &r
},
},
// LOGZ.IO GRAFANA CHANGE :: DEV-46410 - Change default ExecErrState to OK and enforce OK value - will not fail on unknown ExecErrState
//{
// name: "fail if ExecErrState is not known",
// rule: func() *apimodels.PostableExtendedRuleNode {
// r := validRule()
// r.GrafanaManagedAlert.ExecErrState = apimodels.ExecutionErrorState(util.GenerateShortUID())
// return &r
// },
//},
{
name: "fail if there are not data (nil)",
rule: func() *apimodels.PostableExtendedRuleNode {
Expand Down Expand Up @@ -604,14 +605,14 @@ func TestValidateRuleNode_UID(t *testing.T) {
},
},
{
name: "use empty Alerting if ExecErrState is empty",
name: "use OK state if ExecErrState is empty", // LOGZ.IO GRAFANA CHANGE :: DEV-46410 - Change default ExecErrState to OK and enforce OK value
rule: func() *apimodels.PostableExtendedRuleNode {
r := validRule()
r.GrafanaManagedAlert.ExecErrState = ""
return &r
},
assert: func(t *testing.T, api *apimodels.PostableExtendedRuleNode, alert *models.AlertRule) {
require.Equal(t, models.ExecutionErrorState(""), alert.ExecErrState)
require.Equal(t, models.OkErrState, alert.ExecErrState) // LOGZ.IO GRAFANA CHANGE :: DEV-46410 - Change default ExecErrState to OK and enforce OK value
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ resource "grafana_rule_group" "rule_group_0000" {
}

no_data_state = "NoData"
exec_err_state = "Alerting"
exec_err_state = "OK"
for = "2m"
is_paused = false
}
Expand Down Expand Up @@ -75,7 +75,7 @@ resource "grafana_rule_group" "rule_group_0000" {
}

no_data_state = "NoData"
exec_err_state = "Alerting"
exec_err_state = "OK"
is_paused = false

notification_settings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
}
],
"noDataState": "NoData",
"execErrState": "Alerting",
"execErrState": "OK",
"for": "2m",
"isPaused": false
},
Expand Down Expand Up @@ -107,7 +107,7 @@
}
],
"noDataState": "NoData",
"execErrState": "Alerting",
"execErrState": "OK",
"for": "0s",
"isPaused": false,
"notification_settings":{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ groups:
refId: condition
type: math
noDataState: NoData
execErrState: Alerting
execErrState: OK
for: 2m
isPaused: false
- title: reduced testdata query - 2
Expand Down Expand Up @@ -80,7 +80,7 @@ groups:
refId: B
type: reduce
noDataState: NoData
execErrState: Alerting
execErrState: OK
for: 0s
isPaused: false
notification_settings:
Expand Down
4 changes: 2 additions & 2 deletions pkg/services/ngalert/api/test-data/post-rulegroup-101.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
}
],
"no_data_state": "NoData",
"exec_err_state": "Alerting"
"exec_err_state": "OK"
}
},
{
Expand Down Expand Up @@ -109,7 +109,7 @@
}
],
"no_data_state": "NoData",
"exec_err_state": "Alerting",
"exec_err_state": "OK",
"notification_settings":{
"receiver":"Test-Receiver",
"group_by":["alertname","grafana_folder","test"],
Expand Down

0 comments on commit 39dc34a

Please sign in to comment.