Skip to content

Commit

Permalink
interface changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Amogh-Bharadwaj committed Mar 12, 2024
1 parent 0b34a0b commit f4a3968
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
6 changes: 3 additions & 3 deletions flow/alerting/alerting.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ func (a *Alerter) registerSendersFromPool(ctx context.Context) ([]AlertSenderCon
region = &envRegion
}

alertSender, err2 := NewEmailAlertSenderWithNewClient(ctx, region, &emailServiceConfig)
if err2 != nil {
return fmt.Errorf("failed to initialize email alerter: %w", err2)
alertSender, alertSenderErr := NewEmailAlertSenderWithNewClient(ctx, region, &emailServiceConfig)
if alertSenderErr != nil {
return fmt.Errorf("failed to initialize email alerter: %w", alertSenderErr)
}
alertSenderConfigs = append(alertSenderConfigs, AlertSenderConfig{Id: id, Sender: alertSender})
default:
Expand Down
17 changes: 7 additions & 10 deletions flow/alerting/email_alert_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ import (
"github.com/PeerDB-io/peer-flow/shared/aws_common"
)

type EmailAlertSender interface {
type EmailAlertSender struct {
AlertSender
}

type emailAlertSenderImpl struct {
client *ses.Client
sourceEmail string
configurationSetName string
Expand All @@ -25,11 +22,11 @@ type emailAlertSenderImpl struct {
emailAddresses []string
}

func (e *emailAlertSenderImpl) getSlotLagMBAlertThreshold() uint32 {
func (e *EmailAlertSender) getSlotLagMBAlertThreshold() uint32 {
return e.slotLagMBAlertThreshold
}

func (e *emailAlertSenderImpl) getOpenConnectionsAlertThreshold() uint32 {
func (e *EmailAlertSender) getOpenConnectionsAlertThreshold() uint32 {
return e.openConnectionsAlertThreshold
}

Expand All @@ -42,7 +39,7 @@ type EmailAlertSenderConfig struct {
EmailAddresses []string `json:"email_addresses"`
}

func (e *emailAlertSenderImpl) sendAlert(ctx context.Context, alertTitle string, alertMessage string) error {
func (e *EmailAlertSender) sendAlert(ctx context.Context, alertTitle string, alertMessage string) error {
_, err := e.client.SendEmail(ctx, &ses.SendEmailInput{
Destination: &types.Destination{
ToAddresses: e.emailAddresses,
Expand Down Expand Up @@ -72,16 +69,16 @@ func (e *emailAlertSenderImpl) sendAlert(ctx context.Context, alertTitle string,
return nil
}

func NewEmailAlertSenderWithNewClient(ctx context.Context, region *string, config *EmailAlertSenderConfig) (EmailAlertSender, error) {
func NewEmailAlertSenderWithNewClient(ctx context.Context, region *string, config *EmailAlertSenderConfig) (*EmailAlertSender, error) {
client, err := newSesClient(ctx, region)
if err != nil {
return nil, err
}
return NewEmailAlertSender(client, config), nil
}

func NewEmailAlertSender(client *ses.Client, config *EmailAlertSenderConfig) EmailAlertSender {
return &emailAlertSenderImpl{
func NewEmailAlertSender(client *ses.Client, config *EmailAlertSenderConfig) *EmailAlertSender {
return &EmailAlertSender{
client: client,
sourceEmail: config.sourceEmail,
configurationSetName: config.configurationSetName,
Expand Down
15 changes: 6 additions & 9 deletions flow/alerting/slack_alert_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,19 @@ import (
"github.com/slack-go/slack"
)

type SlackAlertSender interface {
type SlackAlertSender struct {
AlertSender
}

type slackAlertSenderImpl struct {
client *slack.Client
channelIDs []string
slotLagMBAlertThreshold uint32
openConnectionsAlertThreshold uint32
}

func (s *slackAlertSenderImpl) getSlotLagMBAlertThreshold() uint32 {
func (s *SlackAlertSender) getSlotLagMBAlertThreshold() uint32 {
return s.slotLagMBAlertThreshold
}

func (s *slackAlertSenderImpl) getOpenConnectionsAlertThreshold() uint32 {
func (s *SlackAlertSender) getOpenConnectionsAlertThreshold() uint32 {
return s.openConnectionsAlertThreshold
}

Expand All @@ -33,16 +30,16 @@ type slackAlertConfig struct {
OpenConnectionsAlertThreshold uint32 `json:"open_connections_alert_threshold"`
}

func newSlackAlertSender(config *slackAlertConfig) SlackAlertSender {
return &slackAlertSenderImpl{
func newSlackAlertSender(config *slackAlertConfig) *SlackAlertSender {
return &SlackAlertSender{
client: slack.New(config.AuthToken),
channelIDs: config.ChannelIDs,
slotLagMBAlertThreshold: config.SlotLagMBAlertThreshold,
openConnectionsAlertThreshold: config.OpenConnectionsAlertThreshold,
}
}

func (s *slackAlertSenderImpl) sendAlert(ctx context.Context, alertTitle string, alertMessage string) error {
func (s *SlackAlertSender) sendAlert(ctx context.Context, alertTitle string, alertMessage string) error {
for _, channelID := range s.channelIDs {
_, _, _, err := s.client.SendMessageContext(ctx, channelID, slack.MsgOptionBlocks(
slack.NewHeaderBlock(slack.NewTextBlockObject("plain_text", ":rotating_light:Alert:rotating_light:: "+alertTitle, true, false)),
Expand Down

0 comments on commit f4a3968

Please sign in to comment.