Class: Fluent::HttpShadowOutput

Inherits:
BufferedOutput
  • Object
show all
Defined in:
lib/fluent/plugin/out_http_shadow.rb

Constant Summary collapse

SUPPORT_PROTOCOLS =
['http', 'https']

Instance Method Summary collapse

Constructor Details

#initializeHttpShadowOutput



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



30
31
32
33
34
35
# File 'lib/fluent/plugin/out_http_shadow.rb', line 30

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



51
52
53
# File 'lib/fluent/plugin/out_http_shadow.rb', line 51

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

#shutdownObject



47
48
49
# File 'lib/fluent/plugin/out_http_shadow.rb', line 47

def shutdown
  super
end

#startObject



37
38
39
40
41
42
43
44
45
# File 'lib/fluent/plugin/out_http_shadow.rb', line 37

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)
end

#write(chunk) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/fluent/plugin/out_http_shadow.rb', line 55

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