From 03da2b3b51fcc6ccd9a435a51e73703dd2d1f208 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Tue, 19 Feb 2019 10:42:57 +0900 Subject: [PATCH] Make more kindly error message when occurring worker_ids collisions Signed-off-by: Hiroshi Hatake --- lib/fluent/root_agent.rb | 7 ++++++- test/test_root_agent.rb | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/fluent/root_agent.rb b/lib/fluent/root_agent.rb index 89c63e8ae2..e726ae8019 100644 --- a/lib/fluent/root_agent.rb +++ b/lib/fluent/root_agent.rb @@ -65,6 +65,10 @@ def initialize(log:, system_config: SystemConfig.new) def configure(conf) used_worker_ids = [] + available_worker_ids = [] + 0.step(Fluent::Engine.system_config.workers - 1, 1).each do |id| + available_worker_ids << id + end # initialize elements conf.elements(name: 'worker').each do |e| target_worker_id_str = e.arg @@ -84,8 +88,9 @@ def configure(conf) if target_worker_id < 0 || target_worker_id > (Fluent::Engine.system_config.workers - 1) raise Fluent::ConfigError, "worker id #{target_worker_id} specified by directive is not allowed. Available worker id is between 0 and #{(Fluent::Engine.system_config.workers - 1)}" end + available_worker_ids.delete(worker_id) if available_worker_ids.include?(worker_id) if used_worker_ids.include?(worker_id) - raise Fluent::ConfigError, "specified worker_id<#{worker_id}> collisions is detected on directive. Available worker id is between 0 and #{(Fluent::Engine.system_config.workers - 1)} without collisions" + raise Fluent::ConfigError, "specified worker_id<#{worker_id}> collisions is detected on directive. Available worker id(s): #{available_worker_ids}" end used_worker_ids << worker_id diff --git a/test/test_root_agent.rb b/test/test_root_agent.rb index 143a9a63dd..054dc1fbdc 100644 --- a/test/test_root_agent.rb +++ b/test/test_root_agent.rb @@ -698,7 +698,7 @@ def configure_ra(conf_str) end test 'raises configuration error for worker id collisions on multi workers syntax' do - errmsg = "specified worker_id<2> collisions is detected on directive. Available worker id is between 0 and 3 without collisions" + errmsg = "specified worker_id<2> collisions is detected on directive. Available worker id(s): [3]" assert_raise Fluent::ConfigError.new(errmsg) do conf = <<-EOC @@ -710,6 +710,19 @@ def configure_ra(conf_str) end end + test 'raises configuration error for worker id collisions on multi workers syntax when multi avaliable worker_ids are left' do + errmsg = "specified worker_id<1> collisions is detected on directive. Available worker id(s): [2, 3]" + assert_raise Fluent::ConfigError.new(errmsg) do + conf = <<-EOC + + + + +EOC + configure_ra(conf) + end + end + test 'raises configuration error for too big worker id on invalid reversed multi workers syntax' do errmsg = "greater first_worker_id<3> than last_worker_id<0> specified by directive is not allowed. Available multi worker assign syntax is -" assert_raise Fluent::ConfigError.new(errmsg) do