Skip to content

Commit

Permalink
feat: add reply-to address
Browse files Browse the repository at this point in the history
  • Loading branch information
iamKunalGupta committed Mar 11, 2024
1 parent 149af0e commit 7f24192
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions flow/alerting/alerting.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"log/slog"
"strings"
"time"

"github.com/jackc/pgx/v5"
Expand Down Expand Up @@ -54,6 +55,7 @@ func (a *Alerter) registerSendersFromPool(ctx context.Context) ([]AlertSenderCon
emailServiceConfig := EmailAlertSenderConfig{
sourceEmail: peerdbenv.PeerDBAlertingEmailSenderSourceEmail(),
configurationSetName: peerdbenv.PeerDBAlertingEmailSenderConfigurationSet(),
replyToAddresses: strings.Split(peerdbenv.PeerDBAlertingEmailSenderReplyToAddresses(), ","),
}
if emailServiceConfig.sourceEmail == "" {
return errors.New("missing sourceEmail for Email alerting service")
Expand Down Expand Up @@ -131,7 +133,8 @@ func (a *Alerter) AlertIfSlotLag(ctx context.Context, peerName string, slotInfo

if slotInfo.LagInMb > float32(lowestSlotLagMBAlertThreshold) {
for _, alertSenderConfig := range alertSenderConfigs {
if a.checkAndAddAlertToCatalog(ctx, alertSenderConfig.Id, alertKey, fmt.Sprintf(alertMessageTemplate, lowestSlotLagMBAlertThreshold)) {
if a.checkAndAddAlertToCatalog(ctx,
alertSenderConfig.Id, alertKey, fmt.Sprintf(alertMessageTemplate, lowestSlotLagMBAlertThreshold)) {
if alertSenderConfig.Sender.getSlotLagMBAlertThreshold() > 0 {
if slotInfo.LagInMb > float32(alertSenderConfig.Sender.getSlotLagMBAlertThreshold()) {
a.alertToProvider(ctx, alertSenderConfig, alertKey,
Expand Down Expand Up @@ -178,7 +181,8 @@ func (a *Alerter) AlertIfOpenConnections(ctx context.Context, peerName string,

if openConnections.CurrentOpenConnections > int64(lowestOpenConnectionsThreshold) {
for _, alertSenderConfig := range alertSenderConfigs {
if a.checkAndAddAlertToCatalog(ctx, alertSenderConfig.Id, alertKey, fmt.Sprintf(alertMessageTemplate, lowestOpenConnectionsThreshold)) {
if a.checkAndAddAlertToCatalog(ctx,
alertSenderConfig.Id, alertKey, fmt.Sprintf(alertMessageTemplate, lowestOpenConnectionsThreshold)) {
if alertSenderConfig.Sender.getOpenConnectionsAlertThreshold() > 0 {
if openConnections.CurrentOpenConnections > int64(alertSenderConfig.Sender.getOpenConnectionsAlertThreshold()) {
a.alertToProvider(ctx, alertSenderConfig, alertKey,
Expand Down
4 changes: 4 additions & 0 deletions flow/alerting/email_alert_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type emailAlertSenderImpl struct {
client *ses.Client
sourceEmail string
configurationSetName string
replyToAddresses []string
slotLagMBAlertThreshold uint32
openConnectionsAlertThreshold uint32
emailAddresses []string
Expand All @@ -35,6 +36,7 @@ func (e *emailAlertSenderImpl) getOpenConnectionsAlertThreshold() uint32 {
type EmailAlertSenderConfig struct {
sourceEmail string
configurationSetName string
replyToAddresses []string
SlotLagMBAlertThreshold uint32 `json:"slot_lag_mb_alert_threshold"`
OpenConnectionsAlertThreshold uint32 `json:"open_connections_alert_threshold"`
EmailAddresses []string `json:"email_addresses"`
Expand All @@ -59,6 +61,7 @@ func (e *emailAlertSenderImpl) sendAlert(ctx context.Context, alertTitle string,
},
Source: aws.String(e.sourceEmail),
ConfigurationSetName: aws.String(e.configurationSetName),
ReplyToAddresses: e.replyToAddresses,
Tags: []types.MessageTag{
{Name: aws.String("DeploymentUUID"), Value: aws.String(peerdbenv.PeerDBDeploymentUID())},
},
Expand All @@ -82,6 +85,7 @@ func NewEmailAlertSender(client *ses.Client, config *EmailAlertSenderConfig) Ema
client: client,
sourceEmail: config.sourceEmail,
configurationSetName: config.configurationSetName,
replyToAddresses: config.replyToAddresses,
slotLagMBAlertThreshold: config.SlotLagMBAlertThreshold,
openConnectionsAlertThreshold: config.OpenConnectionsAlertThreshold,
emailAddresses: config.EmailAddresses,
Expand Down
5 changes: 5 additions & 0 deletions flow/peerdbenv/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,8 @@ func PeerDBAlertingEmailSenderConfigurationSet() string {
func PeerDBAlertingEmailSenderRegion() string {
return getEnvString("PEERDB_ALERTING_EMAIL_SENDER_REGION", "")
}

// Comma-separated reply-to addresses
func PeerDBAlertingEmailSenderReplyToAddresses() string {
return getEnvString("PEERDB_ALERTING_EMAIL_SENDER_REPLY_TO_ADDRESSES", "")
}

0 comments on commit 7f24192

Please sign in to comment.