Class: Fluent::LogDNAOutput

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

Constant Summary collapse

MAX_RETRIES =
5

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fluent/plugin/out_logdna.rb', line 19

def configure(conf)
  super
  @host = conf['hostname']

  # make these two variables globals
  timeout_unit_map = { s: 1.0, ms: 0.001  }
  timeout_regex = Regexp.new("^([0-9]+)\s*(#{timeout_unit_map.keys.join("|")})$")

  # this section goes into this part of the code
  num_component = 30.0
  unit_component = 's'

  timeout_regex.match(@request_timeout) do |match|
    num_component = match[1].to_f
    unit_component = match[2]
  end

  @request_timeout = num_component * timeout_unit_map[unit_component.to_sym]
end

#format(tag, time, record) ⇒ Object



54
55
56
# File 'lib/fluent/plugin/out_logdna.rb', line 54

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

#shutdownObject



49
50
51
52
# File 'lib/fluent/plugin/out_logdna.rb', line 49

def shutdown
  super
  @ingester.close if @ingester
end

#startObject



39
40
41
42
43
44
45
46
47
# File 'lib/fluent/plugin/out_logdna.rb', line 39

def start
  super
  require 'json'
  require 'base64'
  require 'http'
  HTTP.default_options = { :keep_alive_timeout => 60 }
  @ingester = HTTP.persistent @ingester_domain
  @requests = Queue.new
end

#write(chunk) ⇒ Object



58
59
60
61
62
63
# File 'lib/fluent/plugin/out_logdna.rb', line 58

def write(chunk)
  body = chunk_to_body(chunk)
  response = send_request(body)
  raise 'Encountered server error' if response.code >= 400
  response.flush
end