From d900a736d11320a954a2b0482f71b80ca023b64d Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Mon, 18 Feb 2019 18:03:17 +0900 Subject: [PATCH] Add worker_id collision detector Signed-off-by: Hiroshi Hatake --- lib/fluent/root_agent.rb | 5 +++++ test/test_root_agent.rb | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/fluent/root_agent.rb b/lib/fluent/root_agent.rb index 9b5ac9304e..91b8dbf593 100644 --- a/lib/fluent/root_agent.rb +++ b/lib/fluent/root_agent.rb @@ -64,6 +64,7 @@ def initialize(log:, system_config: SystemConfig.new) attr_reader :labels def configure(conf) + used_workers_ids = [] # initialize elements conf.elements(name: 'worker').each do |e| target_worker_id_str = e.arg @@ -83,6 +84,10 @@ 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 + if used_workers_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" + end + used_workers_ids << worker_id e.elements.each do |elem| unless ['source', 'match', 'filter', 'label'].include?(elem.name) diff --git a/test/test_root_agent.rb b/test/test_root_agent.rb index 25beac9449..143a9a63dd 100644 --- a/test/test_root_agent.rb +++ b/test/test_root_agent.rb @@ -697,6 +697,19 @@ def configure_ra(conf_str) end 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" + 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