From 54287552db770cf58507f9fc37f57ebfb7e915bf Mon Sep 17 00:00:00 2001 From: ganmacs Date: Tue, 9 Aug 2016 11:08:30 +0900 Subject: [PATCH] Add a check that primary and secondary use `custom_format` or not --- lib/fluent/plugin/output.rb | 2 +- test/test_output.rb | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/fluent/plugin/output.rb b/lib/fluent/plugin/output.rb index 32bc6ef3d0..1a1100f6a8 100644 --- a/lib/fluent/plugin/output.rb +++ b/lib/fluent/plugin/output.rb @@ -301,7 +301,7 @@ def configure(conf) @secondary.acts_as_secondary(self) @secondary.configure(secondary_conf) @secondary.router = router if @secondary.has_router? - if self.class != @secondary.class + if (self.class != @secondary.class) && (@custom_format || @secondary.implement?(:custom_format)) log.warn "secondary type should be same with primary one", primary: self.class.to_s, secondary: @secondary.class.to_s end else diff --git a/test/test_output.rb b/test/test_output.rb index 3bb9160bfd..79a8a5f8af 100644 --- a/test/test_output.rb +++ b/test/test_output.rb @@ -95,12 +95,37 @@ def write(chunk) end def test_secondary - d = create_driver(CONFIG + %[ + d = Fluent::Test::BufferedOutputTestDriver.new(Fluent::BufferedOutput) do + def write(chunk) + chunk.read + end + end + + mock(d.instance.log).warn("secondary type should be same with primary one", + { primary: d.instance.class.to_s, secondary: "Fluent::Plugin::Test2Output" }) + d.configure(CONFIG + %[ + + type test2 + name c0 + + ]) + + assert_not_nil d.instance.instance_variable_get(:@secondary).router + end + + def test_secondary_with_no_warn_log + # ObjectBufferedOutput doesn't implemnt `custom_filter` + d = Fluent::Test::BufferedOutputTestDriver.new(Fluent::ObjectBufferedOutput) + + mock(d.instance.log).warn("secondary type should be same with primary one", + { primary: d.instance.class.to_s, secondary: "Fluent::Plugin::Test2Output" }).never + d.configure(CONFIG + %[ type test2 name c0 ]) + assert_not_nil d.instance.instance_variable_get(:@secondary).router end end