Skip to content

Commit 3878f7c

Browse files
committed
Use a more resilient s3 object name by default
The s3 plugin uses a default object key that is problematic in a few ways. 1. It makes HEAD requests for each chunk it uploads, starting from 1 each time. If you have uploaded 2000 log files within the same time slice, it will make 2001 HEAD requests to figure out if it exists. fluent/fluent-plugin-s3#160 2. The above check is not thread-safe, and two threads can race and decide to use the same `%{index}` value, with the loser of the race overwriting the chunk from the winner. fluent/fluent-plugin-s3#326 This is planned to change for v2, but there's no clear path to v2 right now. The plugin does warn already if you use multiple threads and don't use either `%{chunk_id}` or `%{uuid_hash}` in the object key.
1 parent 9c81632 commit 3878f7c

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

pkg/sdk/model/output/s3.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ type S3OutputConfig struct {
127127
GrantFullControl string `json:"grant_full_control,omitempty"`
128128
// The length of `%{hex_random}` placeholder(4-16)
129129
HexRandomLength string `json:"hex_random_length,omitempty"`
130-
// The format of S3 object keys (default: %{path}%{time_slice}_%{index}.%{file_extension})
131-
S3ObjectKeyFormat string `json:"s3_object_key_format,omitempty"`
130+
// The format of S3 object keys (default: %{path}%{time_slice}_%{uuid_hash}_%{index}.%{file_extension})
131+
S3ObjectKeyFormat string `json:"s3_object_key_format,omitempty" plugin:"default:%{path}%{time_slice}_%{uuid_hash}_%{index}.%{file_extension}"`
132132
// S3 bucket name
133133
S3Bucket string `json:"s3_bucket"`
134134
// Archive format on S3

pkg/sdk/model/output/s3_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ buffer:
3939
@id test
4040
path logs/${tag}/%Y/%m/%d/
4141
s3_bucket logging-amazon-s3
42+
s3_object_key_format %{path}%{time_slice}_%{uuid_hash}_%{index}.%{file_extension}
4243
s3_region eu-central-1
4344
<buffer tag,time>
4445
@type file

pkg/sdk/model/render/fluent_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ func TestRenderS3(t *testing.T) {
479479
@id test
480480
path /var/buffer
481481
s3_bucket test_bucket
482+
s3_object_key_format %{path}%{time_slice}_%{uuid_hash}_%{index}.%{file_extension}
482483
<buffer tag,time>
483484
@type file
484485
path asd
@@ -502,6 +503,7 @@ func TestRenderS3(t *testing.T) {
502503
@id test
503504
path /var/buffer
504505
s3_bucket test_bucket
506+
s3_object_key_format %{path}%{time_slice}_%{uuid_hash}_%{index}.%{file_extension}
505507
<instance_profile_credentials>
506508
</instance_profile_credentials>`,
507509
},
@@ -519,6 +521,7 @@ func TestRenderS3(t *testing.T) {
519521
@id test
520522
path /var/buffer
521523
s3_bucket test_bucket
524+
s3_object_key_format %{path}%{time_slice}_%{uuid_hash}_%{index}.%{file_extension}
522525
<shared_credentials>
523526
path e
524527
profile_name f

0 commit comments

Comments
 (0)