Skip to content

Commit

Permalink
Add a check that primary and secondary use custom_format or not
Browse files Browse the repository at this point in the history
  • Loading branch information
ganmacs committed Aug 10, 2016
1 parent c8f5b7a commit 5428755
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/fluent/plugin/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 26 additions & 1 deletion test/test_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 + %[
<secondary>
type test2
name c0
</secondary>
])

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 + %[
<secondary>
type test2
name c0
</secondary>
])

assert_not_nil d.instance.instance_variable_get(:@secondary).router
end
end
Expand Down

0 comments on commit 5428755

Please sign in to comment.