lib/fluent/plugin/out_dd.rb in fluent-plugin-dd-0.1.3 vs lib/fluent/plugin/out_dd.rb in fluent-plugin-dd-0.1.4
- old
+ new
@@ -6,23 +6,41 @@
end
config_param :dd_api_key, :string
config_param :host, :string, :default => nil
config_param :use_fluentd_tag_for_datadog_tag, :bool, :default => false
+ config_param :emit_in_background, :bool, :default => false
def initialize
super
require 'dogapi'
require 'socket'
+ require 'thread'
end
def start
super
+
+ if @emit_in_background
+ @queue = Queue.new
+
+ @thread = Thread.start do
+ while(chunk = @queue.pop)
+ emit_points(chunk)
+ Thread.pass
+ end
+ end
+ end
end
def shutdown
super
+
+ if @emit_in_background
+ @queue.push(false)
+ @thread.join
+ end
end
def configure(conf)
super
@@ -41,9 +59,19 @@
def format(tag, time, record)
[tag, time, record].to_msgpack
end
def write(chunk)
+ if @emit_in_background
+ @queue.push(chunk)
+ else
+ emit_points(chunk)
+ end
+ end
+
+ private
+
+ def emit_points(chunk)
enum = chunk.to_enum(:msgpack_each)
enum.select {|tag, time, record|
unless record['metric']
log.warn("`metric` key does not exist: #{[tag, time, record].inspect}")