Skip to content

Commit 98b2557

Browse files
committed
s3_bucket_time_slice_substring suffix created as needed
1 parent f957b40 commit 98b2557

File tree

6 files changed

+59
-3
lines changed

6 files changed

+59
-3
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Release 1.4.1 - 2020/09/30
2+
3+
* Added feature s3_bucket_timestamp_suffix
4+
15
Release 1.4.0 - 2020/08/02
26

37
* Remove uuidtools dependency

Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM fluent/fluentd:edge
2+
3+
ARG VERSION=1.4.1
4+
5+
USER root
6+
7+
COPY fluent-plugin-s3-$VERSION.gem /
8+
9+
RUN gem install /fluent-plugin-s3-$VERSION.gem --no-document
10+
11+
USER fluent

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
all: build
2+
3+
gem: clean
4+
gem build fluent-plugin-s3
5+
6+
build: gem
7+
docker build -t fluentd-custom:edge .
8+
9+
clean:
10+
gem clean;
11+
rm -f fluent-plugin-s3*.gem

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,16 @@ full list of regions are available here. >
295295
http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region. We
296296
recommend using `s3_region` instead of `s3_endpoint`.
297297

298+
**s3_bucket_use_time_slice_sub**
299+
300+
Use a time slice substring to create new buckets as time slice changes. **auto_create_bucket** is required!
301+
For example:
302+
bucket = MYBUCKET
303+
time_slice = %Y-%m-%d-%H
304+
s3_bucket_use_time_slice_sub = %Y-%m-%d
305+
306+
Buckets will be created like: MYBUCKET-2020-09-25, MYBUCKET-2020-09-26 as days go by.
307+
298308
**s3_endpoint**
299309

300310
endpoint for S3 compatible services. For example, Riak CS based storage or

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4.0
1+
1.4.1

lib/fluent/plugin/out_s3.rb

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ def initialize
8787
config_param :aws_iam_retries, :integer, default: nil, deprecated: "Use 'instance_profile_credentials' instead"
8888
desc "S3 bucket name"
8989
config_param :s3_bucket, :string
90+
desc "Use time slice substring to rotate bucket name"
91+
config_param :s3_bucket_use_time_slice_sub, :string, default: ""
9092
desc "S3 region name"
9193
config_param :s3_region, :string, default: ENV["AWS_REGION"] || "us-east-1"
9294
desc "Use 's3_region' instead"
@@ -249,13 +251,29 @@ def start
249251

250252
s3_client = Aws::S3::Client.new(options)
251253
@s3 = Aws::S3::Resource.new(client: s3_client)
254+
@s3_bucket_prefix = @s3_bucket
255+
256+
if @s3_bucket_use_time_slice_sub != ""
257+
if !@configured_time_slice_format.start_with?(@s3_bucket_use_time_slice_sub)
258+
raise "s3_bucket_use_time_slice_sub (" + @s3_bucket_use_time_slice_sub + ") must be a substring of time_slice (" + @configured_time_slice_format + ")"
259+
end
260+
end
261+
262+
super
263+
end
264+
265+
def set_bucket
266+
if @s3_bucket_use_time_slice_sub != ""
267+
@s3_bucket = @s3_bucket_prefix + "-" + Time.new.strftime(@s3_bucket_use_time_slice_sub)
268+
else
269+
@s3_bucket = @s3_bucket_prefix
270+
end
271+
252272
@bucket = @s3.bucket(@s3_bucket)
253273

254274
check_apikeys if @check_apikey_on_start
255275
ensure_bucket if @check_bucket
256276
ensure_bucket_lifecycle
257-
258-
super
259277
end
260278

261279
def format(tag, time, record)
@@ -272,6 +290,8 @@ def write(chunk)
272290
else
273291
@time_slice_with_tz.call(metadata.timekey)
274292
end
293+
294+
set_bucket
275295

276296
if @check_object
277297
begin

0 commit comments

Comments
 (0)