Skip to content

Conversation

@anhtaw
Copy link
Contributor

@anhtaw anhtaw commented Oct 16, 2025

Description

Fixing a bug in the awss3receiver key generation logic where object keys could contain
an unexpected leading slash (/year=...) when s3_prefix was empty and s3_partition_format
was not explicitly set.
This change makes the behavior consistent between default and custom s3_partition_format
by ensuring keys do not start with a slash unless explicitly configured.

Additional logic was added to handle cases where prefix equals / or //, preserving the
user-defined format without stripping or duplicating slashes.


Link to tracking issue

Fixes #43522


Testing

  • Added new unit tests in s3reader_test.go covering:
    • Default s3_partition_format behavior with empty prefix.
    • Explicit s3_partition_format override.
    • Custom prefix values / and //.
  • Verified generated S3 keys match expected format:
    • year=2025/month=10/day=15/... (no leading slash)
    • /year=2025/... when prefix = /.
  • All existing tests pass (make test).

Documentation

No external documentation changes required.
Internal behavior change documented in code comments for getObjectPrefixForTime().

@anhtaw anhtaw requested review from a team and atoulme as code owners October 16, 2025 03:41
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 16, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: anhtaw / name: broname (bdbca67)

@github-actions github-actions bot added the first-time contributor PRs made by new contributors label Oct 16, 2025
@github-actions
Copy link
Contributor

Welcome, contributor! Thank you for your contribution to opentelemetry-collector-contrib.

Important reminders:

A maintainer will review your pull request soon. Thank you for helping make OpenTelemetry better!

Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

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

@anhtaw
Copy link
Contributor Author

anhtaw commented Oct 17, 2025

Thanks for the contribution @anhtaw! please ensure a changelog entry is added https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#adding-a-changelog-entry

Hi @codeboten Changelog entry has been added. Thanks for the reminder!

@anhtaw anhtaw requested a review from codeboten October 17, 2025 15:32
@anhtaw anhtaw requested a review from atoulme October 21, 2025 07:01
Copy link
Contributor

@adcharre adcharre left a comment

Choose a reason for hiding this comment

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

Looks OK to me and seems to follow similar behaviour as to the S3 Exporter.

@atoulme atoulme added the ready to merge Code review completed; ready to merge by maintainers label Oct 24, 2025
@github-actions
Copy link
Contributor

Welcome, contributor! Thank you for your contribution to opentelemetry-collector-contrib.

Important reminders:

A maintainer will review your pull request soon. Thank you for helping make OpenTelemetry better!

@songy23 songy23 merged commit f24023a into open-telemetry:main Oct 27, 2025
206 checks passed
@github-actions github-actions bot added this to the next release milestone Oct 27, 2025
@otelbot
Copy link
Contributor

otelbot bot commented Oct 27, 2025

Thank you for your contribution @anhtaw! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey. If you are getting started contributing, you can also join the CNCF Slack channel #opentelemetry-new-contributors to ask for guidance and get help.

dyl10s pushed a commit to dyl10s/opentelemetry-collector-contrib that referenced this pull request Nov 21, 2025
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

Fixing a bug in the `awss3receiver` key generation logic where object
keys could contain
an unexpected leading slash (`/year=...`) when `s3_prefix` was empty and
`s3_partition_format`
was not explicitly set.  
This change makes the behavior consistent between default and custom
`s3_partition_format`
by ensuring keys do not start with a slash unless explicitly configured.

Additional logic was added to handle cases where `prefix` equals `/` or
`//`, preserving the
user-defined format without stripping or duplicating slashes.

---

<!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes open-telemetry#43522

---

<!--Describe what testing was performed and which tests were added.-->
#### Testing

- Added new unit tests in `s3reader_test.go` covering:
  - Default `s3_partition_format` behavior with empty prefix.
  - Explicit `s3_partition_format` override.
  - Custom prefix values `/` and `//`.
- Verified generated S3 keys match expected format:
  - `year=2025/month=10/day=15/...` (no leading slash)
  - `/year=2025/...` when prefix = `/`.
- All existing tests pass (`make test`).

---

<!--Describe the documentation added.-->
#### Documentation

No external documentation changes required.  
Internal behavior change documented in code comments for
`getObjectPrefixForTime()`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

first-time contributor PRs made by new contributors ready to merge Code review completed; ready to merge by maintainers receiver/awss3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unable to read S3 objects when keys start with leading slash ("/") — path.Join removes leading "/" from s3_prefix

6 participants