Alerting: fetch interval from stored namespace UID (#53195) (#53636)

(cherry picked from commit e14c91d5d4)

Co-authored-by: Jean-Philippe Quéméner <JohnnyQQQQ@users.noreply.github.com>
This commit is contained in:
Grot (@grafanabot)
2022-08-11 19:08:09 -04:00
committed by GitHub
co-authored by Jean-Philippe Quéméner
parent 8c587f177f
commit ff2f7f2621
2 changed files with 14 additions and 4 deletions
@@ -276,10 +276,7 @@ func (service *AlertRuleService) UpdateAlertRule(ctx context.Context, rule model
}
rule.Updated = time.Now()
rule.ID = storedRule.ID
rule.IntervalSeconds, err = service.ruleStore.GetRuleGroupInterval(ctx, rule.OrgID, rule.NamespaceUID, rule.RuleGroup)
if err != nil {
return models.AlertRule{}, err
}
rule.IntervalSeconds = storedRule.IntervalSeconds
err = rule.SetDashboardAndPanel()
if err != nil {
return models.AlertRule{}, err
@@ -69,6 +69,19 @@ func TestAlertRuleService(t *testing.T) {
require.Equal(t, interval, rule.IntervalSeconds)
})
t.Run("if a folder was renamed the interval should be fetched from the renamed folder", func(t *testing.T) {
var orgID int64 = 2
rule := dummyRule("test#1", orgID)
rule.NamespaceUID = "123abc"
rule, err := ruleService.CreateAlertRule(context.Background(), rule, models.ProvenanceNone, 0)
require.NoError(t, err)
rule.NamespaceUID = "abc123"
_, err = ruleService.UpdateAlertRule(context.Background(),
rule, models.ProvenanceNone)
require.NoError(t, err)
})
t.Run("group creation should propagate group title correctly", func(t *testing.T) {
var orgID int64 = 1
group := createDummyGroup("group-test-3", orgID)