class Fluent::Plugin::MultiOutput

Attributes

outputs[R]
outputs_statically_created[R]

Public Class Methods

new() click to toggle source
Calls superclass method Fluent::PluginLoggerMixin.new
# File lib/fluent/plugin/multi_output.rb, line 41
def initialize
  super
  @outputs = []
  @outputs_statically_created = false

  @counters_monitor = Monitor.new
  # TODO: well organized counters
  @num_errors = 0
  @emit_count = 0
  @emit_records = 0
  # @write_count = 0
  # @rollback_count = 0
end

Public Instance Methods

after_shutdown() click to toggle source
Calls superclass method Fluent::Plugin::Base#after_shutdown
# File lib/fluent/plugin/multi_output.rb, line 131
def after_shutdown
  super
  call_lifecycle_method(:after_shutdown, :after_shutdown?)
end
after_start() click to toggle source
Calls superclass method Fluent::Plugin::Base#after_start
# File lib/fluent/plugin/multi_output.rb, line 111
def after_start
  super
  call_lifecycle_method(:after_start, :after_started?)
end
before_shutdown() click to toggle source
Calls superclass method Fluent::Plugin::Base#before_shutdown
# File lib/fluent/plugin/multi_output.rb, line 121
def before_shutdown
  super
  call_lifecycle_method(:before_shutdown, :before_shutdown?)
end
call_lifecycle_method(method_name, checker_name) click to toggle source

But when MultiOutput plugins are created dynamically (by forest plugin or others), agent cannot find sub-plugins. So child plugins' lifecycles MUST be controlled by MultiOutput plugin itself. TODO: this hack will be removed at v2.

# File lib/fluent/plugin/multi_output.rb, line 93
def call_lifecycle_method(method_name, checker_name)
  return if @outputs_statically_created
  @outputs.each do |o|
    begin
      log.debug "calling #{method_name} on output plugin dynamically created", type: Fluent::Plugin.lookup_type_from_class(o.class), plugin_id: o.plugin_id
      o.send(method_name) unless o.send(checker_name)
    rescue Exception => e
      log.warn "unexpected error while calling #{method_name} on output plugin dynamically created", plugin: o.class, plugin_id: o.plugin_id, error: e
      log.warn_backtrace
    end
  end
end
close() click to toggle source
Calls superclass method Fluent::Plugin::Base#close
# File lib/fluent/plugin/multi_output.rb, line 136
def close
  super
  call_lifecycle_method(:close, :closed?)
end
configure(conf) click to toggle source
Calls superclass method Fluent::PluginLoggerMixin#configure
# File lib/fluent/plugin/multi_output.rb, line 59
def configure(conf)
  super

  @stores.each do |store|
    store_conf = store.corresponding_config_element
    type = store_conf['@type']
    unless type
      raise Fluent::ConfigError, "Missing '@type' parameter in <store> section"
    end

    log.debug "adding store", type: type

    output = Fluent::Plugin.new_output(type)
    if output.has_router?
      output.router = router
    end
    output.configure(store_conf)
    @outputs << output
  end
end
emit_events(tag, es)
Alias for: emit_sync
emit_sync(tag, es) click to toggle source
# File lib/fluent/plugin/multi_output.rb, line 146
def emit_sync(tag, es)
  @counters_monitor.synchronize{ @emit_count += 1 }
  begin
    process(tag, es)
    @counters_monitor.synchronize{ @emit_records += es.size }
  rescue
    @counters_monitor.synchronize{ @num_errors += 1 }
    raise
  end
end
Also aliased as: emit_events
multi_output?() click to toggle source
# File lib/fluent/plugin/multi_output.rb, line 55
def multi_output?
  true
end
process(tag, es) click to toggle source
# File lib/fluent/plugin/multi_output.rb, line 37
def process(tag, es)
  raise NotImplementedError, "BUG: output plugins MUST implement this method"
end
shutdown() click to toggle source
Calls superclass method Fluent::Plugin::Base#shutdown
# File lib/fluent/plugin/multi_output.rb, line 126
def shutdown
  super
  call_lifecycle_method(:shutdown, :shutdown?)
end
start() click to toggle source
Calls superclass method Fluent::PluginLoggerMixin#start
# File lib/fluent/plugin/multi_output.rb, line 106
def start
  super
  call_lifecycle_method(:start, :started?)
end
static_outputs() click to toggle source
# File lib/fluent/plugin/multi_output.rb, line 80
def static_outputs
  @outputs_statically_created = true
  @outputs
end
stop() click to toggle source
Calls superclass method Fluent::Plugin::Base#stop
# File lib/fluent/plugin/multi_output.rb, line 116
def stop
  super
  call_lifecycle_method(:stop, :stopped?)
end
terminate() click to toggle source
Calls superclass method Fluent::PluginLoggerMixin#terminate
# File lib/fluent/plugin/multi_output.rb, line 141
def terminate
  super
  call_lifecycle_method(:terminate, :terminated?)
end