Class: Fluent::HttpShadowOutput
- Inherits:
-
BufferedOutput
- Object
- BufferedOutput
- Fluent::HttpShadowOutput
- Defined in:
- lib/fluent/plugin/out_http_shadow.rb
Constant Summary collapse
- SUPPORT_PROTOCOLS =
['http', 'https']
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #format(tag, time, record) ⇒ Object
-
#initialize ⇒ HttpShadowOutput
constructor
A new instance of HttpShadowOutput.
- #shutdown ⇒ Object
- #start ⇒ Object
- #write(chunk) ⇒ Object
Constructor Details
#initialize ⇒ HttpShadowOutput
Returns a new instance of HttpShadowOutput.
6 7 8 9 10 11 12 |
# File 'lib/fluent/plugin/out_http_shadow.rb', line 6 def initialize super require 'erb' require 'typhoeus' require "addressable/uri" require 'string/scrub' if RUBY_VERSION.to_f < 2.1 end |
Instance Method Details
#configure(conf) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/fluent/plugin/out_http_shadow.rb', line 31 def configure(conf) super if @host.nil? && @host_hash.nil? raise ConfigError, "out_http_shadow: required to @host or @host_hash." end end |
#format(tag, time, record) ⇒ Object
56 57 58 |
# File 'lib/fluent/plugin/out_http_shadow.rb', line 56 def format(tag, time, record) [tag, time, record].to_msgpack end |
#shutdown ⇒ Object
52 53 54 |
# File 'lib/fluent/plugin/out_http_shadow.rb', line 52 def shutdown super end |
#start ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fluent/plugin/out_http_shadow.rb', line 38 def start super @regexp = /\$\{([^}]+)\}/ @path_format = ERB.new(@path_format.gsub(@regexp, "<%=record['" + '\1' + "'] %>")) @protocol_format = ERB.new(@protocol_format.gsub(@regexp, "<%=record['" + '\1' + "'] %>")) @headers = get_formatter(@header_hash) @cookies = get_formatter(@cookie_hash) if @no_send_header_pattern @no_send_header_pattern = Regexp.new(@no_send_header_pattern) end end |
#write(chunk) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/fluent/plugin/out_http_shadow.rb', line 60 def write(chunk) records = [] chunk.msgpack_each do |tag, time, record| records << record end sampling_size = (records.size * (@rate * 0.01)).to_i if @rate > 100 orig_records = records.dup loop do records.concat(orig_records) break if sampling_size < records.size end end send_request_parallel(records.first(sampling_size)) end |