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']
- PLACEHOLDER_REGEXP =
/\$\{([^}]+)\}/- ERB_REGEXP =
"<%=record['" + '\1' + "'] %>"
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.
8 9 10 11 12 13 14 |
# File 'lib/fluent/plugin/out_http_shadow.rb', line 8 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
33 34 35 36 37 38 |
# File 'lib/fluent/plugin/out_http_shadow.rb', line 33 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
57 58 59 |
# File 'lib/fluent/plugin/out_http_shadow.rb', line 57 def format(tag, time, record) [tag, time, record].to_msgpack end |
#shutdown ⇒ Object
53 54 55 |
# File 'lib/fluent/plugin/out_http_shadow.rb', line 53 def shutdown super end |
#start ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/fluent/plugin/out_http_shadow.rb', line 40 def start super @path_format = ERB.new(@path_format.gsub(PLACEHOLDER_REGEXP, ERB_REGEXP)) @protocol_format = ERB.new(@protocol_format.gsub(PLACEHOLDER_REGEXP, ERB_REGEXP)) @headers = get_formatter(@header_hash) = get_formatter() if @no_send_header_pattern @no_send_header_pattern = /#{@no_send_header_pattern}/ end end |
#write(chunk) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/fluent/plugin/out_http_shadow.rb', line 61 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 |