Skip to content

Commit

Permalink
fix(telemetry): issue with aws sns (#1444)
Browse files Browse the repository at this point in the history
`subject[:100]` is byte based, not character based, causing AWS to
reject control characters

Properly limit to 100 characters, rather than 100 bytes
  • Loading branch information
iamKunalGupta authored Mar 6, 2024
1 parent 373bfb2 commit 6b47812
Showing 1 changed file with 15 additions and 2 deletions.
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

0 comments on commit 6b47812

Please sign in to comment.