Alerting: Add MissingSeriesEvalsToResolve to the APIs (#102150)
What is this feature? A follow-up for #101184, adds AlertRule.MissingSeriesEvalsToResolve to the APIs. missing_series_evals_to_resolve must be specified too and it must be > 0. POST /api/ruler/grafana/api/v1/rules/{folderUID} works in the following way: If missing_series_evals_to_resolve is not sent or null, the rule keeps its existing value If missing_series_evals_to_resolve > 0: updates to that value If missing_series_evals_to_resolve = 0: resets to default (nil). AlertRule.MissingSeriesEvalsToResolve can't be 0, so I used it to reset In the Provisioning API, the value is just set if present and > 0. Otherwise it's reset: PUT to /api/v1/provisioning/alert-rules/{UID}: If missing_series_evals_to_resolve is nil, it's reset to the default value If missing_series_evals_to_resolve > 0, it's updated
This commit is contained in:
@@ -29,6 +29,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/tests/testinfra"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
|
||||
func createRuleWithNotificationSettings(t *testing.T, client apiClient, folder string, nfSettings *definitions.AlertRuleNotificationSettings) (definitions.PostableRuleGroupConfig, string) {
|
||||
@@ -664,14 +665,24 @@ func TestIntegrationProvisioningRules(t *testing.T) {
|
||||
Model: json.RawMessage([]byte(`{"type":"math","expression":"2 + 3 \u003e 1"}`)),
|
||||
},
|
||||
},
|
||||
MissingSeriesEvalsToResolve: util.Pointer(3),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
result, status, raw := apiClient.CreateOrUpdateRuleGroupProvisioning(t, originalRuleGroup)
|
||||
|
||||
t.Run("should create a new rule group with UIDs specified", func(t *testing.T) {
|
||||
requireStatusCode(t, http.StatusOK, status, raw)
|
||||
require.Equal(t, originalRuleGroup, result)
|
||||
|
||||
require.Len(t, result.Rules, 3)
|
||||
for _, rule := range result.Rules {
|
||||
require.NotEmpty(t, rule.UID)
|
||||
if rule.UID == "rule3" {
|
||||
require.Equal(t, 3, *rule.MissingSeriesEvalsToResolve)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("should remove a rule when updating group with a rule removed", func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user