Class: Fluent::Plugin::MultiOutput
Constant Summary
Configurable::CONFIG_TYPE_REGISTRY
Instance Attribute Summary collapse
#log
Attributes inherited from Base
#under_plugin_development
Instance Method Summary
collapse
included
included
#plugin_id, #plugin_id_configured?, #plugin_id_for_test?
Methods inherited from Base
#after_shutdown?, #after_started?, #before_shutdown?, #closed?, #configured?, #has_router?, #inspect, #shutdown?, #started?, #stopped?, #terminated?
#system_config, #system_config_override
#config, included, lookup_type, register_type
Constructor Details
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
@num_errors = 0
@emit_count = 0
@emit_records = 0
end
|
Instance Attribute Details
#outputs ⇒ Object
Returns the value of attribute outputs.
35
36
37
|
# File 'lib/fluent/plugin/multi_output.rb', line 35
def outputs
@outputs
end
|
#outputs_statically_created ⇒ Object
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_shutdown ⇒ Object
131
132
133
134
|
# File 'lib/fluent/plugin/multi_output.rb', line 131
def after_shutdown
super
call_lifecycle_method(:after_shutdown, :after_shutdown?)
end
|
#after_start ⇒ Object
111
112
113
114
|
# File 'lib/fluent/plugin/multi_output.rb', line 111
def after_start
super
call_lifecycle_method(:after_start, :after_started?)
end
|
#before_shutdown ⇒ Object
121
122
123
124
|
# 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) ⇒ 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.
93
94
95
96
97
98
99
100
101
102
103
104
|
# 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 ⇒ Object
136
137
138
139
|
# File 'lib/fluent/plugin/multi_output.rb', line 136
def close
super
call_lifecycle_method(:close, :closed?)
end
|
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# 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_sync(tag, es) ⇒ Object
Also known as:
emit_events
146
147
148
149
150
151
152
153
154
155
|
# 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
|
#multi_output? ⇒ Boolean
55
56
57
|
# File 'lib/fluent/plugin/multi_output.rb', line 55
def multi_output?
true
end
|
#process(tag, es) ⇒ Object
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
|
#shutdown ⇒ Object
126
127
128
129
|
# File 'lib/fluent/plugin/multi_output.rb', line 126
def shutdown
super
call_lifecycle_method(:shutdown, :shutdown?)
end
|
#start ⇒ Object
106
107
108
109
|
# File 'lib/fluent/plugin/multi_output.rb', line 106
def start
super
call_lifecycle_method(:start, :started?)
end
|
#static_outputs ⇒ Object
80
81
82
83
|
# File 'lib/fluent/plugin/multi_output.rb', line 80
def static_outputs
@outputs_statically_created = true
@outputs
end
|
#stop ⇒ Object
116
117
118
119
|
# File 'lib/fluent/plugin/multi_output.rb', line 116
def stop
super
call_lifecycle_method(:stop, :stopped?)
end
|
#terminate ⇒ Object
141
142
143
144
|
# File 'lib/fluent/plugin/multi_output.rb', line 141
def terminate
super
call_lifecycle_method(:terminate, :terminated?)
end
|