Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to get the root-router #3358

Merged
merged 7 commits into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/fluent/plugin_helper/event_emitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ def event_emitter_used_actually?

def event_emitter_router(label_name)
if label_name
Engine.root_agent.find_label(label_name).event_router
if label_name == "@ROOT"
Engine.root_agent.event_router
else
Engine.root_agent.find_label(label_name).event_router
end
elsif self.respond_to?(:as_secondary) && self.as_secondary
if @primary_instance.has_router?
@_event_emitter_lazy_init = true
Expand Down
1 change: 1 addition & 0 deletions lib/fluent/root_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def configure(conf)
end
name = e.arg
raise ConfigError, "Missing symbol argument on <label> directive" if name.empty?
raise ConfigError, "@ROOT for <label> is not permitted, reserved for getting root router" if name == '@ROOT'

if name == ERROR_LABEL
error_label_config = e
Expand Down
29 changes: 29 additions & 0 deletions test/plugin_helper/test_event_emitter.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require_relative '../helper'
require 'fluent/plugin_helper/event_emitter'
require 'fluent/plugin/base'
require 'flexmock/test_unit'

class EventEmitterTest < Test::Unit::TestCase
setup do
Expand Down Expand Up @@ -48,4 +49,32 @@ class Dummy < Fluent::Plugin::TestBase

d1.terminate
end

test 'should not have event_emitter_router' do
d0 = Dummy0.new
assert !d0.respond_to?(:event_emitter_router)
end

test 'should have event_emitter_router' do
d = Dummy.new
assert d.respond_to?(:event_emitter_router)
end

test 'get router' do
router_mock = flexmock('mytest')
label_mock = flexmock('mylabel')
label_mock.should_receive(:event_router).twice.and_return(router_mock)
Fluent::Engine.root_agent.labels['@mytest'] = label_mock

d = Dummy.new
d.configure(config_element('ROOT', '', {'@label' => '@mytest'}))
router = d.event_emitter_router("@mytest")
assert_equal router_mock, router
end

test 'get root router' do
d = Dummy.new
router = d.event_emitter_router("@ROOT")
assert_equal Fluent::Engine.root_agent.event_router, router
end
end
28 changes: 28 additions & 0 deletions test/test_root_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,34 @@ def configure_ra(conf_str)
end
end

test 'raises configuration error for label without name' do
conf = <<-EOC
<label>
@type test_out
</label>
EOC
errmsg = "Missing symbol argument on <label> directive"
assert_raise Fluent::ConfigError.new(errmsg) do
configure_ra(conf)
end
end

test 'raises configuration error for <label @ROOT>' do
conf = <<-EOC
<source>
@type test_in
@label @ROOT
</source>
<label @ROOT>
@type test_out
</label>
EOC
errmsg = "@ROOT for <label> is not permitted, reserved for getting root router"
assert_raise Fluent::ConfigError.new(errmsg) do
configure_ra(conf)
end
end

test 'raises configuration error if there are not match sections in label section' do
conf = <<-EOC
<source>
Expand Down