Skip to content

Commit

Permalink
chore: use sha as dedup id instead
Browse files Browse the repository at this point in the history
  • Loading branch information
iamKunalGupta committed Mar 1, 2024
1 parent a32f990 commit 2f4dc26
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion flow/shared/telemetry/sns_message_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package telemetry

import (
"context"
"crypto/sha256"
"encoding/hex"
"fmt"
"strings"
"time"
Expand All @@ -26,6 +28,11 @@ type SNSMessageSenderConfig struct {
}

func (s *SNSMessageSenderImpl) SendMessage(ctx context.Context, subject string, body string, attributes Attributes) (*string, error) {
deduplicationString := fmt.Sprintf("[%s] - [%s] - [Window: %s]", attributes.DeploymentUID, subject, time.Now().Truncate(30*time.Minute))
h := sha256.New()
h.Write([]byte(deduplicationString))
deduplicationHash := hex.EncodeToString(h.Sum(nil))

publish, err := s.client.Publish(ctx, &sns.PublishInput{
Message: aws.String(body),
MessageAttributes: map[string]types.MessageAttributeValue{
Expand All @@ -51,7 +58,7 @@ func (s *SNSMessageSenderImpl) SendMessage(ctx context.Context, subject string,
},
"alias": { // This will act as a de-duplication ID
DataType: aws.String("String"),
StringValue: aws.String(fmt.Sprintf("[%s] - [%s] - [Window: %s]", attributes.DeploymentUID, subject, time.Now().Truncate(30*time.Minute))),
StringValue: aws.String(deduplicationHash),
},
},
Subject: aws.String(subject[:100]),
Expand Down

0 comments on commit 2f4dc26

Please sign in to comment.