class Fluent::HttpFileUploadOutput
Constants
- SUPPORTED_COMPRESSION_TYPES
- StatDummy
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_http_file_upload.rb, line 53 def configure(conf) super @formatter = Plugin.new_formatter(@format) @formatter.configure(conf) @client = HTTPClient.new(agent_name: @user_agent, default_header: @headers) # @client.debug_dev = $stderr if @uri.start_with?("https://") @client.ssl_config.verify_mode = @ssl_verify_mode end case @compress when 'gzip' raise Fluent::ConfigError, "gzip command unavailable" unless system('gzip -h > /dev/null 2>&1') end end
format(tag, time, record)
click to toggle source
# File lib/fluent/plugin/out_http_file_upload.rb, line 70 def format(tag, time, record) @formatter.format(tag, time, record) end
upload(io, filename)
click to toggle source
# File lib/fluent/plugin/out_http_file_upload.rb, line 113 def upload(io, filename) stat_dummy = StatDummy.new(io.size) io.singleton_class.class_eval{ define_method(:path){ filename } # override path to feed specified filename to httpclient define_method(:lstat){ stat_dummy } # override lstat to return chunk size only (lstat doesn't work for chunk buffer file) } postdata = { @param_name => io } unless @parameters.empty? postdata = @parameters.merge(postdata) end res = @client.post(@uri, postdata) if res.status == 200 log.info "upload success with code 200" # TODO: make this `debug` else log.error "failed to upload", uri: @uri, code: res.status, content: res.content if res.status >= 500 && res.status < 600 raise "failed to upload with ServerError. retrying." end end end
write(chunk)
click to toggle source
# File lib/fluent/plugin/out_http_file_upload.rb, line 74 def write(chunk) case @compress when 'gzip' write_gzip(chunk) else write_plain(chunk) end end
write_gzip(chunk)
click to toggle source
# File lib/fluent/plugin/out_http_file_upload.rb, line 90 def write_gzip(chunk) filename = Time.now.strftime(@filename) + '.gz' path = if chunk.respond_to?(:path) chunk.path else w = Tempfile.new('chunk-gzip-temp-http_file_upload') chunk.write_to(w) w.close w.path end tmp = Tempfile.new('gzip-temp-http_file_upload') tmp.close # file will be removed after GC res = system "gzip -c #{path} > #{tmp.path}" unless res log.warn "failed to execute gzip command: exit code '#{$?}'" end tmp.open upload(tmp, filename) tmp.close end
write_plain(chunk)
click to toggle source
# File lib/fluent/plugin/out_http_file_upload.rb, line 83 def write_plain(chunk) filename = Time.now.strftime(@filename) chunk.open do |io| upload(io, filename) end end