Skip to content

[AWSINTS-3515] feat(go-forwarder): add SNS S3 wrapper + refactor S3#1111

Closed
ndakkoune wants to merge 6 commits into
nabil.dakkoune/go-forwarderfrom
nabil.dakkoune/AWSINTS-3515
Closed

[AWSINTS-3515] feat(go-forwarder): add SNS S3 wrapper + refactor S3#1111
ndakkoune wants to merge 6 commits into
nabil.dakkoune/go-forwarderfrom
nabil.dakkoune/AWSINTS-3515

Conversation

@ndakkoune
Copy link
Copy Markdown
Contributor

What does this PR do?

Adds the S3 message wrapping into SNS

Motivation

Testing Guidelines

Additional Notes

Types of changes

  • Bug fix
  • New feature
  • Breaking change
  • Misc (docs, refactoring, dependency upgrade, etc.)

Check all that apply

  • This PR's description is comprehensive
  • This PR contains breaking changes that are documented in the description
  • This PR introduces new APIs or parameters that are documented and unlikely to change in the foreseeable future
  • This PR impacts documentation, and it has been updated (or a ticket has been logged)
  • This PR's changes are covered by the automated tests
  • This PR collects user input/sensitive content into Datadog
  • This PR passes the integration tests (ask a Datadog member to run the tests)
  • This PR passes the unit tests
  • This PR passes the installation tests (ask a Datadog member to run the tests)

@github-actions github-actions Bot added the aws label Apr 21, 2026
)

type s3RecordContext struct {
type s3Record struct {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small refactor to not confuse this the context package.

return client, metadata, nil
}

func handleS3Event(ctx context.Context, event json.RawMessage, cfg *config.Config, client S3APIClient, metadata model.Metadata, out chan<- model.S3LogEntry) error {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handleS3Event will be called for each events.SNSEvent.Records entry and we don't want to create multiple S3 clients : we initialise it outside


rc := s3RecordContext{
forwarderMetadata, tags, source, service, bucket, key, cfg.S3MultilineLogRegex,
service = cmp.Or(service, source)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More elegant solution. Will update the Cloudwatch flow also in a next PR (avoids cluttering this one).

}
if err := processS3Record(ctx, client, out, rc); err != nil {
return fmt.Errorf("process S3 record: %w", err)
slog.WarnContext(ctx, "skipping s3 record",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Standardizing the behavior between handlers.

}

ddtags = append(ddtags, "service:"+entryService)
tags := slices.Concat(ddtags, model.Tags{"service:" + entryService}, rc.tags)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More elegant and performant solution since it is capped at most 1 allocation.

}

for _, record := range snsEvent.Records {
s3Record := json.RawMessage(record.SNS.Message)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could have had move this to a handleSNSRecord function but it would have take too many arguments to make it clean.

@ndakkoune ndakkoune closed this Apr 30, 2026
@ndakkoune ndakkoune deleted the nabil.dakkoune/AWSINTS-3515 branch April 30, 2026 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant