Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(telemetry): issue with aws sns #1444

Merged
merged 4 commits into from
Mar 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions flow/shared/telemetry/sns_message_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/sha256"
"encoding/hex"
"strings"
"unicode"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
Expand Down Expand Up @@ -37,7 +38,19 @@ func (s *SNSMessageSenderImpl) SendMessage(ctx context.Context, subject string,
h := sha256.New()
h.Write([]byte(deduplicationString))
deduplicationHash := hex.EncodeToString(h.Sum(nil))

// AWS SNS Subject constraints
var messageSubjectBuilder strings.Builder
maxSubjectSize := 99
for currentLength, char := range subject {
if unicode.IsPrint(char) {
messageSubjectBuilder.WriteRune(char)
} else {
messageSubjectBuilder.WriteRune(' ')
}
if currentLength > maxSubjectSize {
break
}
}
publish, err := s.client.Publish(ctx, &sns.PublishInput{
Message: aws.String(body),
MessageAttributes: map[string]types.MessageAttributeValue{
Expand Down Expand Up @@ -66,7 +79,7 @@ func (s *SNSMessageSenderImpl) SendMessage(ctx context.Context, subject string,
StringValue: aws.String(deduplicationHash),
},
},
Subject: aws.String(subject[:100]),
Subject: aws.String(messageSubjectBuilder.String()),
TopicArn: aws.String(s.topic),
})
if err != nil {
Expand Down
Loading