Skip to content

Commit

Permalink
agent-flow: fix S3 object fetch when path has parent directories (gra…
Browse files Browse the repository at this point in the history
…fana#3800)

* agent-flow: fix S3 object fetch when path has parent directories

Signed-off-by: Jasti Sri Radhe Shyam <[email protected]>

* add unit test case for S3 path parsing functionality and bug fix entry in changelog

Signed-off-by: Jasti Sri Radhe Shyam <[email protected]>

---------

Signed-off-by: Jasti Sri Radhe Shyam <[email protected]>
Co-authored-by: mattdurham <[email protected]>
  • Loading branch information
jastisriradheshyam and mattdurham authored May 10, 2023
1 parent 6ac358c commit 0dda0ba
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ Main (unreleased)
`prometheus.exporter.unix` `diskstat_device_include` component could not set
the allowlist field for the diskstat collector. (@tpaschalis)

- Flow: Fix an issue within S3 Module where the S3 path was not parsed correctly when the
path consists of a parent directory. (@jastisriradheshyam)

### Other changes

- Add metrics when clustering mode is enabled. (@rfratto)
Expand Down
4 changes: 2 additions & 2 deletions component/remote/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ func (s *S3) handleContentPolling(newContent string, err error) {
// getPathBucketAndFile takes the path and splits it into a bucket and file.
func getPathBucketAndFile(path string) (bucket, file string) {
parts := strings.Split(path, "/")
file = parts[len(parts)-1]
bucket = strings.Join(parts[:len(parts)-1], "/")
file = strings.Join(parts[3:], "/")
bucket = strings.Join(parts[:3], "/")
bucket = strings.ReplaceAll(bucket, "s3://", "")
return
}
14 changes: 14 additions & 0 deletions component/remote/s3/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,17 @@ func TestCorrectBucket(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, s3File)
}

func TestPathBucketAndFileParsing(t *testing.T) {
// Path without parent directory
pathWithoutParentDir := "s3://bucket/file"
bucket, file := getPathBucketAndFile(pathWithoutParentDir)
require.Equal(t, "bucket", bucket)
require.Equal(t, "file", file)

// Path with parent directory
pathWithParentDir := "s3://bucket/parent/file"
bucket, file = getPathBucketAndFile(pathWithParentDir)
require.Equal(t, "bucket", bucket)
require.Equal(t, "parent/file", file)
}

0 comments on commit 0dda0ba

Please sign in to comment.