Class: Fluent::Plugin::MultiOutput

Inherits:
Base
  • Object
show all
Includes:
Fluent::PluginHelper::Mixin, Fluent::PluginId, Fluent::PluginLoggerMixin
Defined in:
lib/fluent/plugin/multi_output.rb

Direct Known Subclasses

RoundRobinOutput

Constant Summary

Constants included from Configurable

Configurable::CONFIG_TYPE_REGISTRY

Instance Attribute Summary collapse

Attributes included from Fluent::PluginLoggerMixin

#log

Attributes inherited from Base

#under_plugin_development

Instance Method Summary collapse

Methods included from Fluent::PluginHelper::Mixin

included

Methods included from Fluent::PluginLoggerMixin

included

Methods included from Fluent::PluginId

#plugin_id, #plugin_id_configured?, #plugin_id_for_test?, #plugin_root_dir

Methods inherited from Base

#after_shutdown?, #after_started?, #before_shutdown?, #closed?, #configured?, #context_router, #context_router=, #fluentd_worker_id, #has_router?, #inspect, #multi_workers_ready?, #plugin_root_dir, #shutdown?, #started?, #stopped?, #string_safe_encoding, #terminated?

Methods included from SystemConfig::Mixin

#system_config, #system_config_override

Methods included from Configurable

#config, #configure_proxy_generate, #configured_section_create, included, lookup_type, register_type

Constructor Details

#initializeMultiOutput

Returns a new instance of MultiOutput.



41
42
43
44
45
46
47
48
49
50
51
52
53
# 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

Instance Attribute Details

#outputsObject (readonly)

Returns the value of attribute outputs.



35
36
37
# File 'lib/fluent/plugin/multi_output.rb', line 35

def outputs
  @outputs
end

#outputs_statically_createdObject (readonly)

Returns the value of attribute outputs_statically_created.



35
36
37
# File 'lib/fluent/plugin/multi_output.rb', line 35

def outputs_statically_created
  @outputs_statically_created
end

Instance Method Details

#after_shutdownObject



129
130
131
132
# File 'lib/fluent/plugin/multi_output.rb', line 129

def after_shutdown
  super
  call_lifecycle_method(:after_shutdown, :after_shutdown?)
end

#after_startObject



109
110
111
112
# File 'lib/fluent/plugin/multi_output.rb', line 109

def after_start
  super
  call_lifecycle_method(:after_start, :after_started?)
end

#before_shutdownObject



119
120
121
122
# File 'lib/fluent/plugin/multi_output.rb', line 119

def before_shutdown
  super
  call_lifecycle_method(:before_shutdown, :before_shutdown?)
end

#call_lifecycle_method(method_name, checker_name) ⇒ Object

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.



91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/fluent/plugin/multi_output.rb', line 91

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

#closeObject



134
135
136
137
# File 'lib/fluent/plugin/multi_output.rb', line 134

def close
  super
  call_lifecycle_method(:close, :closed?)
end

#configure(conf) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# 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)
    output.context_router = self.context_router
    output.configure(store_conf)
    @outputs << output
  end
end

#emit_sync(tag, es) ⇒ Object Also known as: emit_events



144
145
146
147
148
149
150
151
152
153
# File 'lib/fluent/plugin/multi_output.rb', line 144

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

#multi_output?Boolean

Returns:

  • (Boolean)


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

def multi_output?
  true
end

#process(tag, es) ⇒ Object

Raises:

  • (NotImplementedError)


37
38
39
# File 'lib/fluent/plugin/multi_output.rb', line 37

def process(tag, es)
  raise NotImplementedError, "BUG: output plugins MUST implement this method"
end

#shutdownObject



124
125
126
127
# File 'lib/fluent/plugin/multi_output.rb', line 124

def shutdown
  super
  call_lifecycle_method(:shutdown, :shutdown?)
end

#startObject



104
105
106
107
# File 'lib/fluent/plugin/multi_output.rb', line 104

def start
  super
  call_lifecycle_method(:start, :started?)
end

#static_outputsObject



78
79
80
81
# File 'lib/fluent/plugin/multi_output.rb', line 78

def static_outputs
  @outputs_statically_created = true
  @outputs
end

#stopObject



114
115
116
117
# File 'lib/fluent/plugin/multi_output.rb', line 114

def stop
  super
  call_lifecycle_method(:stop, :stopped?)
end

#terminateObject



139
140
141
142
# File 'lib/fluent/plugin/multi_output.rb', line 139

def terminate
  super
  call_lifecycle_method(:terminate, :terminated?)
end