From 6b6fb9317ebaa0cce8cd0988fbefb1126cb9d79f 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..89c63e8ae2 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_worker_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_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" + end + used_worker_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