From 3b02bea9d115a11ab55d84ab744e9183a6fe8015 Mon Sep 17 00:00:00 2001 From: broname <62005256+anhtaw@users.noreply.github.com> Date: Wed, 15 Oct 2025 17:05:02 +0700 Subject: [PATCH 1/7] Update s3reader.go --- receiver/awss3receiver/s3reader.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/receiver/awss3receiver/s3reader.go b/receiver/awss3receiver/s3reader.go index e6d39bd276d0a..850de112d5105 100644 --- a/receiver/awss3receiver/s3reader.go +++ b/receiver/awss3receiver/s3reader.go @@ -157,6 +157,11 @@ func (s3Reader *s3TimeBasedReader) getObjectPrefixForTime(t time.Time, telemetry case S3PartitionHour: timeKey = getTimeKeyPartitionHour(t) } + + if strings.HasPrefix(prefix, "/") && strings.HasSuffix(prefix, "/") { + return fmt.Sprintf("%s%s/%s/%s%s_", prefix, "", timeKey, s3Reader.filePrefix, telemetryType) + } + if s3Reader.s3Prefix != "" { return fmt.Sprintf("%s/%s/%s%s_", s3Reader.s3Prefix, timeKey, s3Reader.filePrefix, telemetryType) } From 176d5f25d62633a6e6706f5284e3c3385cd07233 Mon Sep 17 00:00:00 2001 From: broname <62005256+anhtaw@users.noreply.github.com> Date: Wed, 15 Oct 2025 17:32:35 +0700 Subject: [PATCH 2/7] Update s3reader_test.go --- receiver/awss3receiver/s3reader_test.go | 40 +++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/receiver/awss3receiver/s3reader_test.go b/receiver/awss3receiver/s3reader_test.go index e0bf46f335d79..451b05a59c0a1 100644 --- a/receiver/awss3receiver/s3reader_test.go +++ b/receiver/awss3receiver/s3reader_test.go @@ -83,6 +83,46 @@ func Test_s3Reader_getObjectPrefixForTime(t *testing.T) { }, want: "year=2021/month=02/day=01/hour=17/minute=32/metrics_", }, + + name: "prefix is / (should preserve leading slash)", + args: args{ + s3Prefix: "/", + s3Partition: "minute", + filePrefix: "file", + telemetryType: "logs", + }, + want: "/year=2021/month=02/day=01/hour=17/minute=32/filelogs_", +}, +{ + name: "prefix is // (should preserve double leading slashes)", + args: args{ + s3Prefix: "//", + s3Partition: "hour", + filePrefix: "file", + telemetryType: "metrics", + }, + want: "//year=2021/month=02/day=01/hour=17/filemetrics_", +}, +{ + name: "prefix starts and ends with slash /logs/", + args: args{ + s3Prefix: "/logs/", + s3Partition: "hour", + filePrefix: "file", + telemetryType: "traces", + }, + want: "/logs//year=2021/month=02/day=01/hour=17/filetraces_", +}, +{ + name: "prefix starts and ends with double slash //raw//", + args: args{ + s3Prefix: "//raw//", + s3Partition: "minute", + filePrefix: "file", + telemetryType: "logs", + }, + want: "//raw///year=2021/month=02/day=01/hour=17/minute=32/filelogs_", +}, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { From 5a340abeedd2477f9b83208c9f9951f0f91f0a95 Mon Sep 17 00:00:00 2001 From: broname <62005256+anhtaw@users.noreply.github.com> Date: Thu, 16 Oct 2025 22:20:48 +0700 Subject: [PATCH 3/7] fix error build --- receiver/awss3receiver/s3reader_test.go | 80 ++++++++++++------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/receiver/awss3receiver/s3reader_test.go b/receiver/awss3receiver/s3reader_test.go index 451b05a59c0a1..3f4a77a92c210 100644 --- a/receiver/awss3receiver/s3reader_test.go +++ b/receiver/awss3receiver/s3reader_test.go @@ -83,46 +83,46 @@ func Test_s3Reader_getObjectPrefixForTime(t *testing.T) { }, want: "year=2021/month=02/day=01/hour=17/minute=32/metrics_", }, - - name: "prefix is / (should preserve leading slash)", - args: args{ - s3Prefix: "/", - s3Partition: "minute", - filePrefix: "file", - telemetryType: "logs", - }, - want: "/year=2021/month=02/day=01/hour=17/minute=32/filelogs_", -}, -{ - name: "prefix is // (should preserve double leading slashes)", - args: args{ - s3Prefix: "//", - s3Partition: "hour", - filePrefix: "file", - telemetryType: "metrics", - }, - want: "//year=2021/month=02/day=01/hour=17/filemetrics_", -}, -{ - name: "prefix starts and ends with slash /logs/", - args: args{ - s3Prefix: "/logs/", - s3Partition: "hour", - filePrefix: "file", - telemetryType: "traces", - }, - want: "/logs//year=2021/month=02/day=01/hour=17/filetraces_", -}, -{ - name: "prefix starts and ends with double slash //raw//", - args: args{ - s3Prefix: "//raw//", - s3Partition: "minute", - filePrefix: "file", - telemetryType: "logs", - }, - want: "//raw///year=2021/month=02/day=01/hour=17/minute=32/filelogs_", -}, + { + name: "prefix is / (should preserve leading slash)", + args: args{ + s3Prefix: "/", + s3Partition: "minute", + filePrefix: "file", + telemetryType: "logs", + }, + want: "/year=2021/month=02/day=01/hour=17/minute=32/filelogs_", + }, + { + name: "prefix is // (should preserve double leading slashes)", + args: args{ + s3Prefix: "//", + s3Partition: "hour", + filePrefix: "file", + telemetryType: "metrics", + }, + want: "//year=2021/month=02/day=01/hour=17/filemetrics_", + }, + { + name: "prefix starts and ends with slash /logs/", + args: args{ + s3Prefix: "/logs/", + s3Partition: "hour", + filePrefix: "file", + telemetryType: "traces", + }, + want: "/logs//year=2021/month=02/day=01/hour=17/filetraces_", + }, + { + name: "prefix starts and ends with double slash //raw//", + args: args{ + s3Prefix: "//raw//", + s3Partition: "minute", + filePrefix: "file", + telemetryType: "logs", + }, + want: "//raw///year=2021/month=02/day=01/hour=17/minute=32/filelogs_", + } } for _, test := range tests { t.Run(test.name, func(t *testing.T) { From b3502ab4f3c1240ff14979fe4c8883f67ca43cf6 Mon Sep 17 00:00:00 2001 From: broname <62005256+anhtaw@users.noreply.github.com> Date: Thu, 16 Oct 2025 22:26:30 +0700 Subject: [PATCH 4/7] Fix formatting in s3reader_test.gof --- receiver/awss3receiver/s3reader_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/receiver/awss3receiver/s3reader_test.go b/receiver/awss3receiver/s3reader_test.go index 3f4a77a92c210..e61a6fb7809d1 100644 --- a/receiver/awss3receiver/s3reader_test.go +++ b/receiver/awss3receiver/s3reader_test.go @@ -122,7 +122,7 @@ func Test_s3Reader_getObjectPrefixForTime(t *testing.T) { telemetryType: "logs", }, want: "//raw///year=2021/month=02/day=01/hour=17/minute=32/filelogs_", - } + }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { From 688e2871eb22d359247ca61d77a6d036c9fb86e2 Mon Sep 17 00:00:00 2001 From: ducq Date: Thu, 16 Oct 2025 23:36:20 +0700 Subject: [PATCH 5/7] Fix formatting in s3reader_test.gof --- receiver/awss3receiver/s3reader.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/receiver/awss3receiver/s3reader.go b/receiver/awss3receiver/s3reader.go index 850de112d5105..dfa0ffdb4586a 100644 --- a/receiver/awss3receiver/s3reader.go +++ b/receiver/awss3receiver/s3reader.go @@ -7,6 +7,7 @@ import ( "context" "errors" "fmt" + "strings" "time" "github.com/aws/aws-sdk-go-v2/service/s3" @@ -157,15 +158,21 @@ func (s3Reader *s3TimeBasedReader) getObjectPrefixForTime(t time.Time, telemetry case S3PartitionHour: timeKey = getTimeKeyPartitionHour(t) } + // Retrieve the configured S3 prefix (may be empty, "/", "//", "logs/", etc.) + prefix := s3Reader.s3Prefix - if strings.HasPrefix(prefix, "/") && strings.HasSuffix(prefix, "/") { - return fmt.Sprintf("%s%s/%s/%s%s_", prefix, "", timeKey, s3Reader.filePrefix, telemetryType) - } - - if s3Reader.s3Prefix != "" { - return fmt.Sprintf("%s/%s/%s%s_", s3Reader.s3Prefix, timeKey, s3Reader.filePrefix, telemetryType) + //Case 1: No prefix provided → use only timeKey + filePrefix + if prefix == "" { + return fmt.Sprintf("%s/%s%s_", timeKey, s3Reader.filePrefix, telemetryType) } - return fmt.Sprintf("%s/%s%s_", timeKey, s3Reader.filePrefix, telemetryType) + // Case 2: Prefix contains only slashes (e.g., "/", "//", "///") + // Keep the exact number of slashes and directly append timeKey without adding an extra "/" + if strings.Trim(prefix, "/") == "" { + return fmt.Sprintf("%s%s/%s%s_", prefix, timeKey, s3Reader.filePrefix, telemetryType) + } + //Case 3: Normal prefix (e.g., "logs", "logs/", "/logs/", "//raw//") + // Always add a "/" between prefix and timeKey to build a valid S3 path + return fmt.Sprintf("%s/%s/%s%s_", prefix, timeKey, s3Reader.filePrefix, telemetryType) } func (s3Reader *s3TimeBasedReader) sendStatus(ctx context.Context, status statusNotification) { From 7a7084d61f6a5d5ddd5ac249fec8ff3cc4e4da39 Mon Sep 17 00:00:00 2001 From: ducq Date: Fri, 17 Oct 2025 22:30:07 +0700 Subject: [PATCH 6/7] add changelog entry for awss3 prefix trim fix (#43587) --- .chloggen/fix-awss3reader-prefix-trim.yaml | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .chloggen/fix-awss3reader-prefix-trim.yaml diff --git a/.chloggen/fix-awss3reader-prefix-trim.yaml b/.chloggen/fix-awss3reader-prefix-trim.yaml new file mode 100644 index 0000000000000..025b297477b03 --- /dev/null +++ b/.chloggen/fix-awss3reader-prefix-trim.yaml @@ -0,0 +1,29 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. receiver/filelog) +component: receiver/awss3 + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: "Fix S3 prefix trimming logic in awss3reader to correctly handle empty, single slash '/', and double slash '//' prefixes." + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [43587] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: | + This fix ensures the S3 object prefix is generated consistently for all prefix formats (e.g., `""`, `/`, `//`, `/logs/`, `//raw//`), + preventing malformed S3 paths when reading from buckets with non-standard prefixes. + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] From 68bbc337a9dcb6d4e6fec694c2e56d9fb79cd88c Mon Sep 17 00:00:00 2001 From: ducq Date: Fri, 17 Oct 2025 22:34:39 +0700 Subject: [PATCH 7/7] Fix scoped-tests-matrix (ubuntu-latest) fail --- receiver/awss3receiver/s3reader.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/receiver/awss3receiver/s3reader.go b/receiver/awss3receiver/s3reader.go index dfa0ffdb4586a..2f95f53298954 100644 --- a/receiver/awss3receiver/s3reader.go +++ b/receiver/awss3receiver/s3reader.go @@ -161,7 +161,7 @@ func (s3Reader *s3TimeBasedReader) getObjectPrefixForTime(t time.Time, telemetry // Retrieve the configured S3 prefix (may be empty, "/", "//", "logs/", etc.) prefix := s3Reader.s3Prefix - //Case 1: No prefix provided → use only timeKey + filePrefix + // Case 1: No prefix provided → use only timeKey + filePrefix if prefix == "" { return fmt.Sprintf("%s/%s%s_", timeKey, s3Reader.filePrefix, telemetryType) } @@ -170,7 +170,7 @@ func (s3Reader *s3TimeBasedReader) getObjectPrefixForTime(t time.Time, telemetry if strings.Trim(prefix, "/") == "" { return fmt.Sprintf("%s%s/%s%s_", prefix, timeKey, s3Reader.filePrefix, telemetryType) } - //Case 3: Normal prefix (e.g., "logs", "logs/", "/logs/", "//raw//") + // Case 3: Normal prefix (e.g., "logs", "logs/", "/logs/", "//raw//") // Always add a "/" between prefix and timeKey to build a valid S3 path return fmt.Sprintf("%s/%s/%s%s_", prefix, timeKey, s3Reader.filePrefix, telemetryType) }