Skip to content

Commit

Permalink
refactor: streamline dispatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdh committed Jul 12, 2024
1 parent 49df13d commit c636f27
Show file tree
Hide file tree
Showing 78 changed files with 1,310 additions and 2,587 deletions.
28 changes: 12 additions & 16 deletions cli/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,30 +165,26 @@ func InitDeps(
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,
routerRegistry,
notifierRegistry,
// notification.NewDispatchBulkNotificationService(
// notificationDeps,
// notifierRegistry,
// routerRegistry,
// ),
// notification.NewDispatchSingleNotificationService(
// notificationDeps,
// notifierRegistry,
// routerRegistry,
// ),
)

alertService := alert.NewService(
Expand Down
4 changes: 0 additions & 4 deletions cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,6 @@ func StartServer(ctx context.Context, cfg config.Config) error {
if err != nil {
return err
}

// propagating the config explicitly
cfg.Notification.SubscriptionV2Enabled = cfg.Service.SubscriptionV2Enabled

defer cleanUpTelemetry()

var queue, dlq notification.Queuer
Expand Down
2 changes: 1 addition & 1 deletion core/alert/mocks/alert_repository.go

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

2 changes: 1 addition & 1 deletion core/alert/mocks/alert_transformer.go

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

2 changes: 1 addition & 1 deletion core/alert/mocks/log_service.go

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

31 changes: 15 additions & 16 deletions core/alert/mocks/notification_service.go

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

8 changes: 3 additions & 5 deletions core/alert/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type LogService interface {
}

type NotificationService interface {
Dispatch(context.Context, []notification.Notification, string) ([]string, error)
Dispatch(context.Context, []notification.Notification) ([]string, error)
}

// Service handles business logic
Expand Down Expand Up @@ -78,10 +78,8 @@ func (s *Service) CreateAlerts(ctx context.Context, providerType string, provide
}

// failure on dispatch won't rollback the db changes
for _, n := range ns {
if _, err := s.notificationService.Dispatch(ctx, []notification.Notification{n}, notification.DispatchKindSingleNotification); err != nil {
s.logger.Warn("failed to send alert as notification", "err", err, "notification", n)
}
if _, err := s.notificationService.Dispatch(ctx, ns); err != nil {
s.logger.Warn("failed to send alert as notification", "err", err, "notifications", ns)
}

} else {
Expand Down
2 changes: 1 addition & 1 deletion core/alert/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func TestService_CreateAlerts(t *testing.T) {
}, 1, nil)
ar.EXPECT().Create(mock.AnythingOfType("context.todoCtx"), mock.AnythingOfType("alert.Alert")).Return(alert.Alert{ID: 1, ProviderID: 1, ResourceName: "foo", Severity: "CRITICAL", MetricName: "lag", MetricValue: "20",
Rule: "lagHigh", TriggeredAt: timenow}, nil)
ns.EXPECT().Dispatch(mock.AnythingOfType("context.todoCtx"), mock.AnythingOfType("[]notification.Notification"), mock.AnythingOfType("string")).Return(nil, nil)
ns.EXPECT().Dispatch(mock.AnythingOfType("context.todoCtx"), mock.AnythingOfType("[]notification.Notification")).Return(nil, nil)
},
alertsToBeCreated: alertsToBeCreated,
expectedFiringLen: 1,
Expand Down
2 changes: 1 addition & 1 deletion core/log/mocks/notification_log_repository.go

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

2 changes: 1 addition & 1 deletion core/namespace/mocks/config_syncer.go

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

2 changes: 1 addition & 1 deletion core/namespace/mocks/encryptor.go

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

2 changes: 1 addition & 1 deletion core/namespace/mocks/namespace_repository.go

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

2 changes: 1 addition & 1 deletion core/namespace/mocks/provider_service.go

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

2 changes: 1 addition & 1 deletion core/namespace/mocks/transactor.go

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

4 changes: 1 addition & 3 deletions core/notification/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ type Config struct {
DLQHandler HandlerConfig `mapstructure:"dlq_handler" yaml:"dlq_handler"`
GroupBy []string `mapstructure:"group_by" yaml:"group_by"`

// experimental: derived from service.Config
SubscriptionV2Enabled bool
EnableSilenceFeature bool
EnableSilenceFeature bool
}

type HandlerConfig struct {
Expand Down
Loading

0 comments on commit c636f27

Please sign in to comment.