Class: Fluent::HttpShadowOutput

Inherits:
BufferedOutput
  • Object
show all
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

Constructor Details

#initializeHttpShadowOutput

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



35
36
37
38
39
40
# File 'lib/fluent/plugin/out_http_shadow.rb', line 35

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



59
60
61
# File 'lib/fluent/plugin/out_http_shadow.rb', line 59

def format(tag, time, record)
  [tag, time, record].to_msgpack
end

#shutdownObject



55
56
57
# File 'lib/fluent/plugin/out_http_shadow.rb', line 55

def shutdown
  super
end

#startObject



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/fluent/plugin/out_http_shadow.rb', line 42

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)
  @cookies = get_formatter(@cookie_hash)

  if @no_send_header_pattern
    @no_send_header_pattern = /#{@no_send_header_pattern}/
  end
end

#write(chunk) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/fluent/plugin/out_http_shadow.rb', line 63

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