From e3dee3039007e14c246dcaee12b440e3f70f7cb0 Mon Sep 17 00:00:00 2001 From: Yuta Iwama Date: Wed, 18 Dec 2019 15:58:52 +0900 Subject: [PATCH] Add test for reload config Signed-off-by: Yuta Iwama --- lib/fluent/engine.rb | 18 +++++++++++++++--- lib/fluent/root_agent.rb | 10 ---------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/fluent/engine.rb b/lib/fluent/engine.rb index b69cdf36ad..2434fd1582 100644 --- a/lib/fluent/engine.rb +++ b/lib/fluent/engine.rb @@ -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 @@ -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 diff --git a/lib/fluent/root_agent.rb b/lib/fluent/root_agent.rb index 28d2977854..fcceb039e4 100644 --- a/lib/fluent/root_agent.rb +++ b/lib/fluent/root_agent.rb @@ -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