Class: Fluent::Plugin::Base
Direct Known Subclasses
BareOutput, Buffer, Filter, Formatter, Input, Metrics, MultiOutput, Output, Parser, ServiceDiscovery, Storage, Test::Driver::OwnerDummy
Defined Under Namespace
Classes: State
Constant Summary
collapse
- LOCK_FILE_BUCKETS =
65536
Configurable::CONFIG_TYPE_REGISTRY
Instance Attribute Summary collapse
Instance Method Summary
collapse
#system_config, #system_config_override
#config, #configure_proxy_generate, #configured_section_create, included, lookup_type, register_type
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
32
33
34
35
36
37
38
39
40
|
# File 'lib/fluent/plugin/base.rb', line 32
def initialize
@log = nil
super
@fluentd_lock_dir = ENV['FLUENTD_LOCK_DIR']
@_state = State.new(false, false, false, false, false, false, false, false, false)
@_context_router = nil
@_fluentd_worker_id = nil
@under_plugin_development = false
end
|
Instance Attribute Details
#under_plugin_development ⇒ Object
Returns the value of attribute under_plugin_development.
30
31
32
|
# File 'lib/fluent/plugin/base.rb', line 30
def under_plugin_development
@under_plugin_development
end
|
Instance Method Details
#acquire_worker_lock(name) ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/fluent/plugin/base.rb', line 82
def acquire_worker_lock(name)
if @fluentd_lock_dir.nil?
raise InvalidLockDirectory, "can't acquire lock because FLUENTD_LOCK_DIR isn't set"
end
lock_path = get_lock_path(name)
File.open(lock_path, "w") do |f|
f.flock(File::LOCK_EX)
yield
end
FileUtils.touch(lock_path)
end
|
#after_shutdown ⇒ Object
142
143
144
145
|
# File 'lib/fluent/plugin/base.rb', line 142
def after_shutdown
@_state.after_shutdown = true
self
end
|
#after_shutdown? ⇒ Boolean
181
182
183
|
# File 'lib/fluent/plugin/base.rb', line 181
def after_shutdown?
@_state.after_shutdown
end
|
#after_start ⇒ Object
122
123
124
125
|
# File 'lib/fluent/plugin/base.rb', line 122
def after_start
@_state.after_start = true
self
end
|
#after_started? ⇒ Boolean
165
166
167
|
# File 'lib/fluent/plugin/base.rb', line 165
def after_started?
@_state.after_start
end
|
#before_shutdown ⇒ Object
132
133
134
135
|
# File 'lib/fluent/plugin/base.rb', line 132
def before_shutdown
@_state.before_shutdown = true
self
end
|
#before_shutdown? ⇒ Boolean
173
174
175
|
# File 'lib/fluent/plugin/base.rb', line 173
def before_shutdown?
@_state.before_shutdown
end
|
#called_in_test? ⇒ Boolean
193
194
195
196
197
198
199
200
201
202
203
|
# File 'lib/fluent/plugin/base.rb', line 193
def called_in_test?
caller_locations.each do |location|
if /\/test_[^\/]+\.rb$/.match?(location.absolute_path) return true
end
end
false
end
|
#close ⇒ Object
147
148
149
150
|
# File 'lib/fluent/plugin/base.rb', line 147
def close
@_state.close = true
self
end
|
#closed? ⇒ Boolean
185
186
187
|
# File 'lib/fluent/plugin/base.rb', line 185
def closed?
@_state.close
end
|
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/fluent/plugin/base.rb', line 56
def configure(conf)
raise ArgumentError, "BUG: type of conf must be Fluent::Config::Element, but #{conf.class} is passed." unless conf.is_a?(Fluent::Config::Element)
if conf.for_this_worker? || (Fluent::Engine.supervisor_mode && !conf.for_every_workers?)
system_config_override(workers: conf.target_worker_ids.size)
end
super(conf, system_config.strict_config_value)
@_state ||= State.new(false, false, false, false, false, false, false, false, false)
@_state.configure = true
self
end
|
157
158
159
|
# File 'lib/fluent/plugin/base.rb', line 157
def configured?
@_state.configure
end
|
#context_router ⇒ Object
107
108
109
|
# File 'lib/fluent/plugin/base.rb', line 107
def context_router
@_context_router
end
|
#context_router=(router) ⇒ Object
103
104
105
|
# File 'lib/fluent/plugin/base.rb', line 103
def context_router=(router)
@_context_router = router
end
|
#fluentd_worker_id ⇒ Object
50
51
52
53
54
|
# File 'lib/fluent/plugin/base.rb', line 50
def fluentd_worker_id
return @_fluentd_worker_id if @_fluentd_worker_id
@_fluentd_worker_id = (ENV['SERVERENGINE_WORKER_ID'] || 0).to_i
@_fluentd_worker_id
end
|
#get_lock_path(name) ⇒ Object
75
76
77
78
79
80
|
# File 'lib/fluent/plugin/base.rb', line 75
def get_lock_path(name)
bucket = Zlib.crc32(name.to_s) % LOCK_FILE_BUCKETS
File.join(@fluentd_lock_dir, "fluentd-bucket-#{bucket}.lock")
end
|
#has_router? ⇒ Boolean
42
43
44
|
# File 'lib/fluent/plugin/base.rb', line 42
def has_router?
false
end
|
#inspect ⇒ Object
205
206
207
208
209
210
211
|
# File 'lib/fluent/plugin/base.rb', line 205
def inspect
"#<%s:%014x>" % [self.class.name, '0x%014x' % (__id__ << 1)]
end
|
#multi_workers_ready? ⇒ Boolean
69
70
71
|
# File 'lib/fluent/plugin/base.rb', line 69
def multi_workers_ready?
true
end
|
#plugin_root_dir ⇒ Object
46
47
48
|
# File 'lib/fluent/plugin/base.rb', line 46
def plugin_root_dir
nil end
|
#reloadable_plugin? ⇒ Boolean
213
214
215
216
|
# File 'lib/fluent/plugin/base.rb', line 213
def reloadable_plugin?
self.class.class_variables.empty?
end
|
#shutdown ⇒ Object
137
138
139
140
|
# File 'lib/fluent/plugin/base.rb', line 137
def shutdown
@_state.shutdown = true
self
end
|
#shutdown? ⇒ Boolean
177
178
179
|
# File 'lib/fluent/plugin/base.rb', line 177
def shutdown?
@_state.shutdown
end
|
#start ⇒ Object
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/fluent/plugin/base.rb', line 111
def start
if @log.is_a?(Fluent::PluginLogger) && $log.respond_to?(:log_event_enabled) @log.log_event_enabled = $log.log_event_enabled
end
@_state.start = true
self
end
|
#started? ⇒ Boolean
161
162
163
|
# File 'lib/fluent/plugin/base.rb', line 161
def started?
@_state.start
end
|
#stop ⇒ Object
127
128
129
130
|
# File 'lib/fluent/plugin/base.rb', line 127
def stop
@_state.stop = true
self
end
|
#stopped? ⇒ Boolean
169
170
171
|
# File 'lib/fluent/plugin/base.rb', line 169
def stopped?
@_state.stop
end
|
#string_safe_encoding(str) {|str| ... } ⇒ Object
95
96
97
98
99
100
101
|
# File 'lib/fluent/plugin/base.rb', line 95
def string_safe_encoding(str)
unless str.valid_encoding?
str = str.scrub('?')
log.info "invalid byte sequence is replaced in `#{str}`" if self.respond_to?(:log)
end
yield str
end
|
#terminate ⇒ Object
152
153
154
155
|
# File 'lib/fluent/plugin/base.rb', line 152
def terminate
@_state.terminate = true
self
end
|
#terminated? ⇒ Boolean
189
190
191
|
# File 'lib/fluent/plugin/base.rb', line 189
def terminated?
@_state.terminate
end
|