lib/fluent/plugin/out_s3.rb in fluent-plugin-s3-1.1.0 vs lib/fluent/plugin/out_s3.rb in fluent-plugin-s3-1.1.1

- old
+ new

@@ -96,10 +96,12 @@ config_param :grant_read_acp, :string, default: nil desc "Allows grantee to write the ACL for the applicable object" config_param :grant_write_acp, :string, default: nil desc "The length of `%{hex_random}` placeholder(4-16)" config_param :hex_random_length, :integer, default: 4 + desc "`sprintf` format for `%{index}`" + config_param :index_format, :string, default: "%d" desc "Overwrite already existing path" config_param :overwrite, :bool, default: false desc "Check bucket if exists or not" config_param :check_bucket, :bool, default: true desc "Check object before creation" @@ -160,10 +162,14 @@ if @hex_random_length > MAX_HEX_RANDOM_LENGTH raise Fluent::ConfigError, "hex_random_length parameter must be less than or equal to #{MAX_HEX_RANDOM_LENGTH}" end + unless @index_format =~ /^%(0\d*)?[dxX]$/ + raise Fluent::ConfigError, "index_format parameter should follow `%[flags][width]type`. `0` is the only supported flag, and is mandatory if width is specified. `d`, `x` and `X` are supported types" + end + if @reduced_redundancy log.warn "reduced_redundancy parameter is deprecated. Use storage_class parameter instead" @storage_class = "REDUCED_REDUNDANCY" end @@ -234,11 +240,11 @@ } values_for_s3_object_key = { "%{path}" => @path, "%{time_slice}" => time_slice, "%{file_extension}" => @compressor.ext, - "%{index}" => i, + "%{index}" => sprintf(@index_format,i), }.merge!(@values_for_s3_object_chunk[chunk.unique_id]) values_for_s3_object_key["%{uuid_flush}".freeze] = uuid_random if @uuid_flush_enabled s3path = @s3_object_key_format.gsub(%r(%{[^}]+}), values_for_s3_object_key) s3path = extract_placeholders(s3path, metadata) @@ -300,10 +306,10 @@ put_options[:grant_write_acp] = @grant_write_acp if @grant_write_acp if @s3_metadata put_options[:metadata] = {} @s3_metadata.each do |k, v| - put_options[:metadata][k] = extract_placeholders(v, metadata).gsub(%r(%{[^}]+}), {"%{index}" => i - 1}) + put_options[:metadata][k] = extract_placeholders(v, metadata).gsub(%r(%{[^}]+}), {"%{index}" => sprintf(@index_format, i - 1)}) end end @bucket.object(s3path).put(put_options) @values_for_s3_object_chunk.delete(chunk.unique_id)