Alerting: remove instances from db and cache on rule update (#33722)

* remove instances from db and cache on rule update

* fix panic

* rename
This commit is contained in:
David Parrott
2021-05-06 18:39:34 +02:00
committed by GitHub
parent 47af158ddb
commit e58aca2d20
2 changed files with 27 additions and 0 deletions
+6
View File
@@ -230,6 +230,7 @@ func (srv RulerSrv) RoutePostNameRulesConfig(c *models.ReqContext, ruleGroupConf
return response.Error(http.StatusBadRequest, "rule group name is not valid", nil)
}
var alertRuleUIDs []string
for _, r := range ruleGroupConfig.Rules {
cond := ngmodels.Condition{
Condition: r.GrafanaManagedAlert.Condition,
@@ -239,6 +240,7 @@ func (srv RulerSrv) RoutePostNameRulesConfig(c *models.ReqContext, ruleGroupConf
if err := validateCondition(cond, c.SignedInUser, c.SkipCache, srv.DatasourceCache); err != nil {
return response.Error(http.StatusBadRequest, fmt.Sprintf("failed to validate alert rule %s", r.GrafanaManagedAlert.Title), err)
}
alertRuleUIDs = append(alertRuleUIDs, r.GrafanaManagedAlert.UID)
}
if err := srv.store.UpdateRuleGroup(store.UpdateRuleGroupCmd{
@@ -254,6 +256,10 @@ func (srv RulerSrv) RoutePostNameRulesConfig(c *models.ReqContext, ruleGroupConf
return response.Error(http.StatusInternalServerError, "failed to update rule group", err)
}
for _, uid := range alertRuleUIDs {
srv.manager.RemoveByRuleUID(c.OrgId, uid)
}
return response.JSON(http.StatusAccepted, util.DynMap{"message": "rule group updated successfully"})
}