Skip to content

Commit

Permalink
chore(ses): deduplicate config load and update email
Browse files Browse the repository at this point in the history
  • Loading branch information
iamKunalGupta committed Mar 8, 2024
1 parent 9e0604c commit 6cafb4c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
6 changes: 3 additions & 3 deletions flow/alerting/alerting.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (a *Alerter) AlertIfSlotLag(ctx context.Context, peerName string, slotInfo
}
}

alertKey := peerName + "-slot-lag-threshold-exceeded"
alertKey := fmt.Sprintf("%s Slot Lag Threshold Exceeded for Peer %s", deploymentUIDPrefix, peerName)
alertMessageTemplate := fmt.Sprintf("%sSlot `%s` on peer `%s` has exceeded threshold size of %%dMB, "+
`currently at %.2fMB!`, deploymentUIDPrefix, slotInfo.SlotName, peerName, slotInfo.LagInMb)

Expand Down Expand Up @@ -147,7 +147,7 @@ func (a *Alerter) AlertIfOpenConnections(ctx context.Context, peerName string,

deploymentUIDPrefix := ""
if peerdbenv.PeerDBDeploymentUID() != "" {
deploymentUIDPrefix = fmt.Sprintf("[%s] ", peerdbenv.PeerDBDeploymentUID())
deploymentUIDPrefix = fmt.Sprintf("[%s] - ", peerdbenv.PeerDBDeploymentUID())
}

// same as with slot lag, use lowest threshold for catalog
Expand All @@ -159,7 +159,7 @@ func (a *Alerter) AlertIfOpenConnections(ctx context.Context, peerName string,
}
}

alertKey := peerName + "-max-open-connections-threshold-exceeded"
alertKey := fmt.Sprintf("%s Max Open Connections Threshold Exceeded for Peer %s", deploymentUIDPrefix, peerName)
alertMessageTemplate := fmt.Sprintf("%sOpen connections from PeerDB user `%s` on peer `%s`"+
` has exceeded threshold size of %%d connections, currently at %d connections!`,
deploymentUIDPrefix, openConnections.UserName, peerName, openConnections.CurrentOpenConnections)
Expand Down
11 changes: 3 additions & 8 deletions flow/alerting/email_alert_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package alerting

import (
"context"

Check failure on line 4 in flow/alerting/email_alert_sender.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
"github.com/PeerDB-io/peer-flow/shared/aws_common"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/ses"
"github.com/aws/aws-sdk-go-v2/service/ses/types"

Expand Down Expand Up @@ -89,15 +89,10 @@ func NewEmailAlertSender(client *ses.Client, config *EmailAlertSenderConfig) Ema
}

func newSesClient(ctx context.Context, region *string) (*ses.Client, error) {
sdkConfig, err := config.LoadDefaultConfig(ctx, func(options *config.LoadOptions) error {
if region != nil {
options.Region = *region
}
return nil
})
sdkConfig, err := aws_common.LoadSdkConfig(ctx, region)
if err != nil {
return nil, err
}
snsClient := ses.NewFromConfig(sdkConfig)
snsClient := ses.NewFromConfig(*sdkConfig)
return snsClient, nil
}
21 changes: 21 additions & 0 deletions flow/shared/aws_common/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package aws_common

import (
"context"

Check failure on line 4 in flow/shared/aws_common/config.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s prefix(github.com/PeerDB-io) -s default (gci)
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
)

func LoadSdkConfig(ctx context.Context, region *string) (*aws.Config, error) {
sdkConfig, err := config.LoadDefaultConfig(ctx, func(options *config.LoadOptions) error {
if region != nil {
options.Region = *region
}
return nil
})
if err != nil {
return nil, err
}
return &sdkConfig, nil

Check failure on line 20 in flow/shared/aws_common/config.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
}

Check failure on line 21 in flow/shared/aws_common/config.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary trailing newline (whitespace)
11 changes: 3 additions & 8 deletions flow/shared/telemetry/sns_message_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"context"
"crypto/sha256"
"encoding/hex"
"github.com/PeerDB-io/peer-flow/shared/aws_common"

Check failure on line 7 in flow/shared/telemetry/sns_message_sender.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s prefix(github.com/PeerDB-io) -s default (gci)
"strings"

Check failure on line 9 in flow/shared/telemetry/sns_message_sender.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/sns"
"github.com/aws/aws-sdk-go-v2/service/sns/types"
"go.temporal.io/sdk/activity"
Expand Down Expand Up @@ -96,15 +96,10 @@ func NewSNSMessageSender(client *sns.Client, config *SNSMessageSenderConfig) SNS
}

func newSnsClient(ctx context.Context, region *string) (*sns.Client, error) {
sdkConfig, err := config.LoadDefaultConfig(ctx, func(options *config.LoadOptions) error {
if region != nil {
options.Region = *region
}
return nil
})
sdkConfig, err := aws_common.LoadSdkConfig(ctx, region)
if err != nil {
return nil, err
}
snsClient := sns.NewFromConfig(sdkConfig)
snsClient := sns.NewFromConfig(*sdkConfig)
return snsClient, nil
}

0 comments on commit 6cafb4c

Please sign in to comment.