Skip to content

Commit

Permalink
Add test for reload config
Browse files Browse the repository at this point in the history
Signed-off-by: Yuta Iwama <[email protected]>
  • Loading branch information
ganmacs committed Dec 18, 2019
1 parent fb88222 commit e3dee30
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
18 changes: 15 additions & 3 deletions lib/fluent/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
require 'fluent/system_config'
require 'fluent/plugin'
require 'fluent/fluent_log_event_router'
require 'fluent/static_config_analysis'

module Fluent
class EngineClass
Expand Down Expand Up @@ -166,16 +167,27 @@ def run
def reload_config(conf, supervisor: false)
# configure first to reduce down time while restarting
new_agent = RootAgent.new(log: log, system_config: @system_config)
if (plugin = new_agent.find_unreloadable_plugin)
raise Fluent::ConfigError, "Unreloadable plugin: #{plugin.class}"
ret = Fluent::StaticConfigAnalysis.call(conf, workers: system_config.workers)

ret.all_plugins.each do |plugin|
if plugin.respond_to?(:reloadable_plugin?) && !plugin.reloadable_plugin?
raise Fluent::ConfigError, "Unreloadable plugin: #{plugin.class}"
end
end

new_agent.configure(conf)
unless @suppress_config_dump
$log.info :supervisor, "using configuration file: #{conf.to_s.rstrip}"
end

# Assign @root_agent to new root_agent
# for https://github.com/fluent/fluentd/blob/fcef949ce40472547fde295ddd2cfe297e1eddd6/lib/fluent/plugin_helper/event_emitter.rb#L50
old_agent, @root_agent = @root_agent, new_agent
begin
@root_agent.configure(conf)
rescue
@root_agent = old_agent
raise
end

# supervisor doesn't handle actual data. so the following code is unnecessary.
if supervisor
Expand Down
10 changes: 0 additions & 10 deletions lib/fluent/root_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,6 @@ def initialize(log:, system_config: SystemConfig.new)
attr_reader :inputs
attr_reader :labels

def find_unreloadable_plugin
lifecycle do |instance|
if instance.respond_to?(:reloadable_plugin?) && !instance.reloadable_plugin?
return instance
end
end

nil
end

def configure(conf)
used_worker_ids = []
available_worker_ids = (0..Fluent::Engine.system_config.workers - 1).to_a
Expand Down

0 comments on commit e3dee30

Please sign in to comment.