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

Check secondary type to avoid unexpected error. fix #2167 #2169

Merged
merged 2 commits into from
Nov 8, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/fluent/plugin/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ def configure(conf)
end
secondary_conf = conf.elements(name: 'secondary').first
@secondary = Plugin.new_output(secondary_type)
unless @secondary.respond_to?(:acts_as_secondary)
raise Fluent::ConfigError, "Failed to setup secondary plugin in '#{conf['@type']}'. '#{secondary_type}' plugin in not allowed due to non buffered output"
end
@secondary.acts_as_secondary(self)
@secondary.configure(secondary_conf)
if (self.class != @secondary.class) && (@custom_format || @secondary.implement?(:custom_format))
Expand Down
55 changes: 32 additions & 23 deletions test/plugin/test_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -828,34 +828,43 @@ def waiting(seconds)
assert_equal :interval, @i.instance_variable_get(:@flush_mode)
end

test "Warn if primary type is different from secondary type and either primary or secondary has custom_format" do
o = create_output(:buffered)
mock(o.log).warn("secondary type should be same with primary one",
{ primary: o.class.to_s, secondary: "Fluent::Plugin::TestOutput" })
sub_test_case 'configure secondary' do
test "Warn if primary type is different from secondary type and either primary or secondary has custom_format" do
o = create_output(:buffered)
mock(o.log).warn("secondary type should be same with primary one",
{ primary: o.class.to_s, secondary: "Fluent::Plugin::TestOutput" })

o.configure(config_element('ROOT','',{},[config_element('secondary','',{'@type'=>'test', 'name' => "cool"})]))
assert_not_nil o.instance_variable_get(:@secondary)
end

o.configure(config_element('ROOT','',{},[config_element('secondary','',{'@type'=>'test', 'name' => "cool"})]))
assert_not_nil o.instance_variable_get(:@secondary)
end
test "don't warn if primary type is the same as secondary type" do
o = Fluent::Plugin::TestOutput.new
mock(o.log).warn("secondary type should be same with primary one",
{ primary: o.class.to_s, secondary: "Fluent::Plugin::TestOutput" }).never

test "don't warn if primary type is the same as secondary type" do
o = Fluent::Plugin::TestOutput.new
mock(o.log).warn("secondary type should be same with primary one",
{ primary: o.class.to_s, secondary: "Fluent::Plugin::TestOutput" }).never
o.configure(config_element('ROOT','',{'name' => "cool2"},
[config_element('secondary','',{'@type'=>'test', 'name' => "cool"}),
config_element('buffer','',{'@type'=>'memory'})]
))
assert_not_nil o.instance_variable_get(:@secondary)
end

o.configure(config_element('ROOT','',{'name' => "cool2"},
[config_element('secondary','',{'@type'=>'test', 'name' => "cool"}),
config_element('buffer','',{'@type'=>'memory'})]
))
assert_not_nil o.instance_variable_get(:@secondary)
end
test "don't warn if primary type is different from secondary type and both don't have custom_format" do
o = create_output(:standard)
mock(o.log).warn("secondary type should be same with primary one",
{ primary: o.class.to_s, secondary: "Fluent::Plugin::TestOutput" }).never

test "don't warn if primary type is different from secondary type and both don't have custom_format" do
o = create_output(:standard)
mock(o.log).warn("secondary type should be same with primary one",
{ primary: o.class.to_s, secondary: "Fluent::Plugin::TestOutput" }).never
o.configure(config_element('ROOT','',{},[config_element('secondary','',{'@type'=>'test', 'name' => "cool"})]))
assert_not_nil o.instance_variable_get(:@secondary)
end

o.configure(config_element('ROOT','',{},[config_element('secondary','',{'@type'=>'test', 'name' => "cool"})]))
assert_not_nil o.instance_variable_get(:@secondary)
test "raise configuration error if secondary type specifies non buffered output" do
o = create_output(:standard)
assert_raise Fluent::ConfigError do
o.configure(config_element('ROOT','',{},[config_element('secondary','',{'@type'=>'copy'})]))
end
end
end
end

Expand Down