Skip to content

Commit

Permalink
Change to error if Hash is passed to Fluent::Plugin::Base::configure()
Browse files Browse the repository at this point in the history
Signed-off-by: abetomo <[email protected]>
  • Loading branch information
abetomo committed Mar 10, 2023
1 parent 8325e10 commit b3a3aef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 25 deletions.
11 changes: 6 additions & 5 deletions lib/fluent/plugin/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ def fluentd_worker_id
@_fluentd_worker_id
end

# @param conf [Fluent::Config::Element, Hash] configuration
# @param conf [Fluent::Config::Element] configuration
def configure(conf)
if conf.is_a?(Fluent::Config::Element)
if (Fluent::Engine.supervisor_mode && !conf.target_worker_ids.empty?) || conf.for_this_worker?
system_config_override(workers: conf.target_worker_ids.size)
end
raise ArgumentError, 'type of conf is Fluent::Config::Element' unless conf.is_a?(Fluent::Config::Element)

if (Fluent::Engine.supervisor_mode && !conf.target_worker_ids.empty?) || conf.for_this_worker?
system_config_override(workers: conf.target_worker_ids.size)
end

super(conf, system_config.strict_config_value)
@_state ||= State.new(false, false, false, false, false, false, false, false, false)
@_state.configure = true
Expand Down
26 changes: 6 additions & 20 deletions test/plugin/test_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ class FluentPluginBaseTest::DummyPlugin2 < Fluent::Plugin::TestBase
end
end

test '`ArgumentError` when `conf` is not `Fluent::Config::Element`' do
assert_raise ArgumentError.new('type of conf is Fluent::Config::Element') do
@p.configure({})
end
end

sub_test_case 'system_config.workers value after configure' do
sub_test_case 'with <system> workers 3 </system>' do
setup do
Expand Down Expand Up @@ -188,11 +194,6 @@ class FluentPluginBaseTest::DummyPlugin2 < Fluent::Plugin::TestBase
@p.configure(conf)
assert{ @p.system_config.workers == 3 }
end

test '`conf` is `Hash`' do
@p.configure({})
assert{ @p.system_config.workers == 3 }
end
end

sub_test_case 'supervisor_mode is false' do
Expand Down Expand Up @@ -228,11 +229,6 @@ class FluentPluginBaseTest::DummyPlugin2 < Fluent::Plugin::TestBase
@p.configure(conf)
assert{ @p.system_config.workers == 3 }
end

test '`conf` is `Hash`' do
@p.configure({})
assert{ @p.system_config.workers == 3 }
end
end
end

Expand All @@ -256,11 +252,6 @@ class FluentPluginBaseTest::DummyPlugin2 < Fluent::Plugin::TestBase
@p.configure(conf)
assert{ @p.system_config.workers == 1 }
end

test '`conf` is `Hash`' do
@p.configure({})
assert{ @p.system_config.workers == 1 }
end
end

sub_test_case 'supervisor_mode is false' do
Expand All @@ -282,11 +273,6 @@ class FluentPluginBaseTest::DummyPlugin2 < Fluent::Plugin::TestBase
@p.configure(conf)
assert{ @p.system_config.workers == 1 }
end

test '`conf` is `Hash`' do
@p.configure({})
assert{ @p.system_config.workers == 1 }
end
end
end
end
Expand Down

0 comments on commit b3a3aef

Please sign in to comment.