lib/fluent/plugin/out_s3.rb in fluent-plugin-s3-0.6.8 vs lib/fluent/plugin/out_s3.rb in fluent-plugin-s3-0.6.9
- old
+ new
@@ -1,8 +1,7 @@
module Fluent
require 'fluent/mixin/config_placeholders'
- require 'securerandom'
class S3Output < Fluent::TimeSlicedOutput
Fluent::Plugin.register_output('s3', self)
def initialize
@@ -68,11 +67,11 @@
config_param :path, :string, :default => nil
desc "Profile name. Default to 'default' or ENV['AWS_PROFILE']"
config_param :profile_name, :string, :default => nil
end
desc "The number of attempts to load instance profile credentials from the EC2 metadata service using IAM role"
- config_param :aws_iam_retries, :integer, :default => 5
+ config_param :aws_iam_retries, :integer, :default => nil
desc "S3 bucket name"
config_param :s3_bucket, :string
desc "S3 region name"
config_param :s3_region, :string, :default => ENV["AWS_REGION"] || "us-east-1"
desc "Use 's3_region' instead"
@@ -163,11 +162,10 @@
end
@values_for_s3_object_chunk = {}
end
def start
- super
options = setup_credentials
options[:region] = @s3_region if @s3_region
options[:endpoint] = @s3_endpoint if @s3_endpoint
options[:http_proxy] = @proxy_uri if @proxy_uri
options[:force_path_style] = @force_path_style
@@ -179,12 +177,11 @@
@bucket = @s3.bucket(@s3_bucket)
check_apikeys if @check_apikey_on_start
ensure_bucket
- # Securerandom.hex(2) returns 4 length hex
- @hex_random_n = (@hex_random_length + 1) / 2
+ super
end
def format(tag, time, record)
@formatter.format(tag, time, record)
end
@@ -255,28 +252,19 @@
end
end
private
- # tsuffix is the one which file buffer filename has
- def tsuffix(chunk)
- if chunk.is_a?(Fluent::FileBufferChunk)
- unique_id = chunk.unique_id
- tsuffix = unique_id[0...(unique_id.size/2)].unpack('C*').map {|x| x.to_s(16) }.join('') # size: 16
- else
- nil
- end
+ # v0.14 has a useful Fluent::UniqueId.hex(unique_id) method, though
+ def unique_hex(chunk)
+ unique_id = chunk.unique_id
+ unique_id.unpack('C*').map {|x| x.to_s(16) }.join('')
end
def hex_random(chunk)
- if chunk.is_a?(Fluent::FileBufferChunk)
- # let me use tsuffix because its value is kept on retrying even after rebooting
- tsuffix = tsuffix(chunk)
- tsuffix.reverse! # tsuffix is like (time_sec, time_usec, rand) => reversing gives more randomness
- tsuffix[0...@hex_random_length]
- else
- SecureRandom.hex(@hex_random_n)[0...@hex_random_length]
- end
+ unique_hex = unique_hex(chunk)
+ unique_hex.reverse! # unique_hex is like (time_sec, time_usec, rand) => reversing gives more randomness
+ unique_hex[0...@hex_random_length]
end
def ensure_bucket
if !@bucket.exists?
if @auto_create_bucket