Skip to content

Commit

Permalink
Make more kindly error message when occurring worker_ids collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmo0920 committed Feb 19, 2019
1 parent 6b6fb93 commit 297cabb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/fluent/root_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <worker> elements
conf.elements(name: 'worker').each do |e|
target_worker_id_str = e.arg
Expand All @@ -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 <worker> 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 <worker> 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 <worker> directive. Available worker id(s): #{available_worker_ids}"
end
used_worker_ids << worker_id

Expand Down
15 changes: 14 additions & 1 deletion test/test_root_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <worker> directive. Available worker id is between 0 and 3 without collisions"
errmsg = "specified worker_id<2> collisions is detected on <worker> directive. Available worker id(s): [3]"
assert_raise Fluent::ConfigError.new(errmsg) do
conf = <<-EOC
<worker 0-2>
Expand All @@ -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 <worker> directive. Available worker id(s): [2, 3]"
assert_raise Fluent::ConfigError.new(errmsg) do
conf = <<-EOC
<worker 0-1>
</worker>
<worker 1-3>
</worker>
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 <worker> directive is not allowed. Available multi worker assign syntax is <smaller_worker_id>-<greater_worker_id>"
assert_raise Fluent::ConfigError.new(errmsg) do
Expand Down

0 comments on commit 297cabb

Please sign in to comment.