Skip to content

Commit

Permalink
feat: bulk notification api (#63)
Browse files Browse the repository at this point in the history
* refactor: alerts notification service

* feat: bulk notifications api

* fix: test

* chore: remove unnecessary files

* feat: add substraction texttemplate
  • Loading branch information
mabdh authored May 30, 2024
1 parent cb928ec commit 94c684d
Show file tree
Hide file tree
Showing 77 changed files with 5,053 additions and 2,075 deletions.
10 changes: 8 additions & 2 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ packages:
LogService:
config:
filename: "log_service.go"
NotificationService:
config:
filename: "notification_service.go"
github.com/goto/siren/core/log:
config:
dir: "core/log/mocks"
Expand Down Expand Up @@ -99,6 +102,9 @@ packages:
Dispatcher:
config:
filename: "dispatcher.go"
Router:
config:
filename: "router.go"
SubscriptionService:
config:
filename: "subscription_service.go"
Expand All @@ -108,9 +114,9 @@ packages:
SilenceService:
config:
filename: "silence_service.go"
AlertService:
AlertRepository:
config:
filename: "alert_service.go"
filename: "alert_repository.go"
LogService:
config:
filename: "log_service.go"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ NAME="github.com/goto/siren"
LAST_COMMIT := $(shell git rev-parse --short HEAD)
LAST_TAG := "$(shell git rev-list --tags --max-count=1)"
APP_VERSION := "$(shell git describe --tags ${LAST_TAG})-next"
PROTON_COMMIT := "478369b80e67ec3c98464050e51f47332d915962"
PROTON_COMMIT := "ebb3a512fc98f28b3b2933da022d04c093673106"

.PHONY: all build test clean dist vet proto install

Expand Down
74 changes: 51 additions & 23 deletions cli/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,6 @@ func InitDeps(
}
}

alertRepository := postgres.NewAlertRepository(pgClient)
alertService := alert.NewService(
alertRepository,
logService,
alertTransformers,
)

namespaceRepository := postgres.NewNamespaceRepository(pgClient)
namespaceService := namespace.NewService(encryptor, namespaceRepository, providerService, configSyncers)

Expand Down Expand Up @@ -143,6 +136,24 @@ func InitDeps(
)

// notification
idempotencyRepository := postgres.NewIdempotencyRepository(pgClient)
notificationRepository := postgres.NewNotificationRepository(pgClient)
alertRepository := postgres.NewAlertRepository(pgClient)

notificationDeps := notification.Deps{
Logger: logger,
Cfg: cfg.Notification,
Repository: notificationRepository,
Q: queue,
LogService: logService,
IdempotencyRepository: idempotencyRepository,
AlertRepository: alertRepository,
ReceiverService: receiverService,
SubscriptionService: subscriptionService,
SilenceService: silenceService,
TemplateService: templateService,
}

notifierRegistry := map[string]notification.Notifier{
receiver.TypeSlack: slackPluginService,
receiver.TypeSlackChannel: slackChannelPluginService,
Expand All @@ -151,25 +162,42 @@ func InitDeps(
receiver.TypeFile: filePluginService,
}

idempotencyRepository := postgres.NewIdempotencyRepository(pgClient)
notificationRepository := postgres.NewNotificationRepository(pgClient)
routerRegistry := map[string]notification.Router{
notification.RouterReceiver: notification.NewRouterReceiverService(
notificationDeps,
notifierRegistry,
),
notification.RouterSubscriber: notification.NewRouterSubscriberService(
notificationDeps,
notifierRegistry,
),
}

dispatchServiceRegistry := map[string]notification.Dispatcher{
notification.DispatchKindBulkNotification: notification.NewDispatchBulkNotificationService(
notificationDeps,
notifierRegistry,
routerRegistry,
),
notification.DispatchKindSingleNotification: notification.NewDispatchSingleNotificationService(
notificationDeps,
notifierRegistry,
routerRegistry,
),
}

notificationService := notification.NewService(
notificationDeps,
dispatchServiceRegistry,
)

alertService := alert.NewService(
cfg.Alert,
logger,
cfg.Notification,
notificationRepository,
queue,
notifierRegistry,
notification.Deps{
LogService: logService,
IdempotencyRepository: idempotencyRepository,
ReceiverService: receiverService,
SubscriptionService: subscriptionService,
SilenceService: silenceService,
AlertService: alertService,
TemplateService: templateService,
},
cfg.Service.EnableSilenceFeature,
alertRepository,
logService,
notificationService,
alertTransformers,
)

return &api.Deps{
Expand Down
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/goto/salt/config"
"github.com/goto/salt/db"
"github.com/goto/salt/telemetry"
"github.com/goto/siren/core/alert"
"github.com/goto/siren/core/notification"
"github.com/goto/siren/internal/server"
"github.com/goto/siren/pkg/errors"
Expand Down Expand Up @@ -44,4 +45,5 @@ type Config struct {
Providers plugins.Config `mapstructure:"providers" yaml:"providers"`
Receivers receivers.Config `mapstructure:"receivers" yaml:"receivers"`
Notification notification.Config `mapstructure:"notification" yaml:"notification"`
Alert alert.Config `mapstructure:"alert" yaml:"alert"`
}
5 changes: 5 additions & 0 deletions core/alert/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package alert

type Config struct {
GroupBy []string `mapstructure:"group_by" yaml:"group_by"`
}
141 changes: 141 additions & 0 deletions core/alert/mocks/alert_repository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 94c684d

Please sign in to comment.