Alerting: Publish event when one or more rules are created or changed (#93637)

* Publish event when one or more rules are changed

* Publish affected rules

* Use a fake bus to test publish event without listening

* Wire alerting store into provisioning service
This commit is contained in:
William Wernert
2024-10-11 12:19:52 -04:00
committed by GitHub
parent 18e66d22b1
commit 19a9a79467
14 changed files with 238 additions and 114 deletions
+14 -18
View File
@@ -22,7 +22,7 @@ import (
"github.com/grafana/grafana/pkg/services/ngalert/notifier"
"github.com/grafana/grafana/pkg/services/ngalert/notifier/legacy_storage"
"github.com/grafana/grafana/pkg/services/ngalert/provisioning"
"github.com/grafana/grafana/pkg/services/ngalert/store"
alertstore "github.com/grafana/grafana/pkg/services/ngalert/store"
"github.com/grafana/grafana/pkg/services/notifications"
"github.com/grafana/grafana/pkg/services/org"
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginsettings"
@@ -42,6 +42,7 @@ func ProvideService(
cfg *setting.Cfg,
sqlStore db.DB,
pluginStore pluginstore.Store,
alertingStore *alertstore.DBstore,
encryptionService encryption.Internal,
notificatonService *notifications.NotificationService,
dashboardProvisioningService dashboardservice.DashboardProvisioningService,
@@ -62,6 +63,7 @@ func ProvideService(
SQLStore: sqlStore,
ac: ac,
pluginStore: pluginStore,
alertingStore: alertingStore,
EncryptionService: encryptionService,
NotificationService: notificatonService,
newDashboardProvisioner: dashboards.New,
@@ -139,6 +141,7 @@ type ProvisioningServiceImpl struct {
orgService org.Service
ac accesscontrol.AccessControl
pluginStore pluginstore.Store
alertingStore *alertstore.DBstore
EncryptionService encryption.Internal
NotificationService *notifications.NotificationService
log log.Logger
@@ -263,16 +266,9 @@ func (ps *ProvisioningServiceImpl) ProvisionDashboards(ctx context.Context) erro
func (ps *ProvisioningServiceImpl) ProvisionAlerting(ctx context.Context) error {
alertingPath := filepath.Join(ps.Cfg.ProvisioningPath, "alerting")
st := store.DBstore{
Cfg: ps.Cfg.UnifiedAlerting,
SQLStore: ps.SQLStore,
Logger: ps.log,
FolderService: nil, // we don't use it yet
DashboardService: ps.dashboardService,
}
ruleService := provisioning.NewAlertRuleService(
st,
st,
ps.alertingStore,
ps.alertingStore,
ps.folderService,
//ps.dashboardService,
ps.quotaService,
@@ -281,15 +277,15 @@ func (ps *ProvisioningServiceImpl) ProvisionAlerting(ctx context.Context) error
int64(ps.Cfg.UnifiedAlerting.BaseInterval.Seconds()),
ps.Cfg.UnifiedAlerting.RulesPerRuleGroupLimit,
ps.log,
notifier.NewCachedNotificationSettingsValidationService(&st),
notifier.NewCachedNotificationSettingsValidationService(ps.alertingStore),
alertingauthz.NewRuleService(ps.ac),
)
configStore := legacy_storage.NewAlertmanagerConfigStore(&st)
configStore := legacy_storage.NewAlertmanagerConfigStore(ps.alertingStore)
receiverSvc := notifier.NewReceiverService(
alertingauthz.NewReceiverAccess[*ngmodels.Receiver](ps.ac, true),
configStore,
st,
st,
ps.alertingStore,
ps.alertingStore,
ps.secretService,
ps.SQLStore,
ps.log,
@@ -297,11 +293,11 @@ func (ps *ProvisioningServiceImpl) ProvisionAlerting(ctx context.Context) error
ps.tracer,
)
contactPointService := provisioning.NewContactPointService(configStore, ps.secretService,
st, ps.SQLStore, receiverSvc, ps.log, &st, ps.resourcePermissions)
ps.alertingStore, ps.SQLStore, receiverSvc, ps.log, ps.alertingStore, ps.resourcePermissions)
notificationPolicyService := provisioning.NewNotificationPolicyService(configStore,
st, ps.SQLStore, ps.Cfg.UnifiedAlerting, ps.log)
mutetimingsService := provisioning.NewMuteTimingService(configStore, st, &st, ps.log, &st)
templateService := provisioning.NewTemplateService(configStore, st, &st, ps.log)
ps.alertingStore, ps.SQLStore, ps.Cfg.UnifiedAlerting, ps.log)
mutetimingsService := provisioning.NewMuteTimingService(configStore, ps.alertingStore, ps.alertingStore, ps.log, ps.alertingStore)
templateService := provisioning.NewTemplateService(configStore, ps.alertingStore, ps.alertingStore, ps.log)
cfg := prov_alerting.ProvisionerConfig{
Path: alertingPath,
RuleService: *ruleService,