class Fluent::Plugin::Base
Constants
- State
Attributes
under_plugin_development[RW]
Public Class Methods
new()
click to toggle source
Calls superclass method
Fluent::Configurable::new
# File lib/fluent/plugin/base.rb, line 31 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
Public Instance Methods
acquire_worker_lock(name) { || ... }
click to toggle source
# File lib/fluent/plugin/base.rb, line 79 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 # Update access time to prevent tmpwatch from deleting a lock file. FileUtils.touch(lock_path); end
after_shutdown()
click to toggle source
# File lib/fluent/plugin/base.rb, line 139 def after_shutdown @_state.after_shutdown = true self end
after_shutdown?()
click to toggle source
# File lib/fluent/plugin/base.rb, line 178 def after_shutdown? @_state.after_shutdown end
after_start()
click to toggle source
# File lib/fluent/plugin/base.rb, line 119 def after_start @_state.after_start = true self end
after_started?()
click to toggle source
# File lib/fluent/plugin/base.rb, line 162 def after_started? @_state.after_start end
before_shutdown()
click to toggle source
# File lib/fluent/plugin/base.rb, line 129 def before_shutdown @_state.before_shutdown = true self end
before_shutdown?()
click to toggle source
# File lib/fluent/plugin/base.rb, line 170 def before_shutdown? @_state.before_shutdown end
called_in_test?()
click to toggle source
# File lib/fluent/plugin/base.rb, line 190 def called_in_test? caller_locations.each do |location| # Thread::Backtrace::Location#path returns base filename or absolute path. # #absolute_path returns absolute_path always. # https://bugs.ruby-lang.org/issues/12159 if location.absolute_path =~ /\/test_[^\/]+\.rb$/ # location.path =~ /test_.+\.rb$/ return true end end false end
close()
click to toggle source
# File lib/fluent/plugin/base.rb, line 144 def close @_state.close = true self end
closed?()
click to toggle source
# File lib/fluent/plugin/base.rb, line 182 def closed? @_state.close end
configure(conf)
click to toggle source
Calls superclass method
Fluent::Configurable#configure
# File lib/fluent/plugin/base.rb, line 55 def configure(conf) if Fluent::Engine.supervisor_mode || (conf.respond_to?(:for_this_worker?) && conf.for_this_worker?) workers = if conf.target_worker_ids && !conf.target_worker_ids.empty? conf.target_worker_ids.size else 1 end system_config_override(workers: workers) 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
configured?()
click to toggle source
# File lib/fluent/plugin/base.rb, line 154 def configured? @_state.configure end
context_router()
click to toggle source
# File lib/fluent/plugin/base.rb, line 104 def context_router @_context_router end
context_router=(router)
click to toggle source
# File lib/fluent/plugin/base.rb, line 100 def context_router=(router) @_context_router = router end
fluentd_worker_id()
click to toggle source
# File lib/fluent/plugin/base.rb, line 49 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)
click to toggle source
# File lib/fluent/plugin/base.rb, line 74 def get_lock_path(name) name = name.gsub(/[^a-zA-Z0-9]/, "_") File.join(@fluentd_lock_dir, "fluentd-#{name}.lock") end
has_router?()
click to toggle source
# File lib/fluent/plugin/base.rb, line 41 def has_router? false end
inspect()
click to toggle source
# File lib/fluent/plugin/base.rb, line 202 def inspect # Plugin instances are sometimes too big to dump because it may have too many thins (buffer,storage, ...) # Original commit comment says that: # To emulate normal inspect behavior `ruby -e'o=Object.new;p o;p (o.__id__<<1).to_s(16)'`. # https://github.com/ruby/ruby/blob/trunk/gc.c#L788 "#<%s:%014x>" % [self.class.name, '0x%014x' % (__id__ << 1)] end
multi_workers_ready?()
click to toggle source
# File lib/fluent/plugin/base.rb, line 70 def multi_workers_ready? true end
plugin_root_dir()
click to toggle source
# File lib/fluent/plugin/base.rb, line 45 def plugin_root_dir nil # override this in plugin_id.rb end
reloadable_plugin?()
click to toggle source
# File lib/fluent/plugin/base.rb, line 210 def reloadable_plugin? # Engine can't capture all class variables. so it's forbbiden to use class variables in each plugins if enabling reload. self.class.class_variables.empty? end
shutdown()
click to toggle source
# File lib/fluent/plugin/base.rb, line 134 def shutdown @_state.shutdown = true self end
shutdown?()
click to toggle source
# File lib/fluent/plugin/base.rb, line 174 def shutdown? @_state.shutdown end
start()
click to toggle source
# File lib/fluent/plugin/base.rb, line 108 def start # By initialization order, plugin logger is created before set log_event_enabled. # It causes '@id' specified plugin, it uses plugin logger instead of global logger, ignores `<label @FLUENT_LOG>` setting. # This is adhoc approach but impact is minimal. if @log.is_a?(Fluent::PluginLogger) && $log.respond_to?(:log_event_enabled) # log_event_enabled check for tests @log.log_event_enabled = $log.log_event_enabled end @_state.start = true self end
started?()
click to toggle source
# File lib/fluent/plugin/base.rb, line 158 def started? @_state.start end
stop()
click to toggle source
# File lib/fluent/plugin/base.rb, line 124 def stop @_state.stop = true self end
stopped?()
click to toggle source
# File lib/fluent/plugin/base.rb, line 166 def stopped? @_state.stop end
string_safe_encoding(str) { |str| ... }
click to toggle source
# File lib/fluent/plugin/base.rb, line 92 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()
click to toggle source
# File lib/fluent/plugin/base.rb, line 149 def terminate @_state.terminate = true self end
terminated?()
click to toggle source
# File lib/fluent/plugin/base.rb, line 186 def terminated? @_state.terminate end