From 2f4dc26fe724003240bd599bfb51e4b1ae7000f3 Mon Sep 17 00:00:00 2001 From: Kunal Gupta <39487888+iamKunalGupta@users.noreply.github.com> Date: Sat, 2 Mar 2024 01:01:35 +0530 Subject: [PATCH] chore: use sha as dedup id instead --- flow/shared/telemetry/sns_message_sender.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/flow/shared/telemetry/sns_message_sender.go b/flow/shared/telemetry/sns_message_sender.go index c3bc2a6b71..29ba69cef6 100644 --- a/flow/shared/telemetry/sns_message_sender.go +++ b/flow/shared/telemetry/sns_message_sender.go @@ -2,6 +2,8 @@ package telemetry import ( "context" + "crypto/sha256" + "encoding/hex" "fmt" "strings" "time" @@ -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{ @@ -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]),