diff --git a/lib/logstash/outputs/s3.rb b/lib/logstash/outputs/s3.rb index faafe019..6b8dfa6e 100644 --- a/lib/logstash/outputs/s3.rb +++ b/lib/logstash/outputs/s3.rb @@ -58,7 +58,6 @@ # bucket => "boss_please_open_your_bucket" (required) # size_file => 2048 (optional) # time_file => 5 (optional) -# format => "plain" (optional) # canned_acl => "private" (optional. Options are "private", "public_read", "public_read_write", "authenticated_read". Defaults to "private" ) # } # @@ -110,6 +109,9 @@ class LogStash::Outputs::S3 < LogStash::Outputs::Base # Specify how many workers to use to upload the files to S3 config :upload_workers_count, :validate => :number, :default => 1 + # Flags for enable move file to s3 in tear down. It's useful if you need to automatic teminate some EC2 instances in aws. + config :move_file_in_tear_down, :validate => :boolean, :default => false + # Exposed attributes for testing purpose. attr_accessor :tempfile attr_reader :page_counter @@ -123,7 +125,7 @@ def aws_s3_config def aws_service_endpoint(region) # Make the deprecated endpoint_region work # TODO: (ph) Remove this after deprecation. - + if @endpoint_region region_to_use = @endpoint_region else @@ -230,7 +232,7 @@ def test_s3_write File.delete(test_filename) end end - + public def restore_from_crashes @logger.debug("S3: is attempting to verify previous crashes...") @@ -308,10 +310,17 @@ def write_to_tempfile(event) public def teardown + #close temp file + @tempfile.close + + if @move_file_in_tear_down == true + # upload current temporary file if needed + move_file_to_bucket(@tempfile.path) + end + shutdown_upload_workers @periodic_rotation_thread.stop! if @periodic_rotation_thread - @tempfile.close finished end @@ -333,7 +342,7 @@ def handle_event(encoded_event) else @logger.debug("S3: tempfile file size report.", :tempfile_size => @tempfile.size, :size_file => @size_file) end - end + end write_to_tempfile(encoded_event) end