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

Fix to add plugin instances created by MultiOutput plugins, into agents #1167

Merged
merged 2 commits into from
Aug 22, 2016
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/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ def add_match(type, pattern, conf)
output.router = @event_router if output.respond_to?(:router=)
output.configure(conf)
@outputs << output
if output.respond_to?(:outputs) && (output.is_a?(Fluent::Plugin::MultiOutput) || output.is_a?(Fluent::MultiOutput))
@outputs.push(*output.outputs)
end
@event_router.add_rule(pattern, output)

output
Expand Down
8 changes: 8 additions & 0 deletions test/test_plugin_classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ class FluentTestInput < ::Fluent::Input
attr_reader :started

def start
super
@started = true
end

def shutdown
@started = false
super
end
end

Expand All @@ -30,11 +32,13 @@ def initialize
attr_reader :started

def start
super
@started = true
end

def shutdown
@started = false
super
end

def emit(tag, es, chain)
Expand Down Expand Up @@ -69,11 +73,13 @@ def initialize(field = '__test__')
attr_reader :started

def start
super
@started = true
end

def shutdown
@started = false
super
end

def filter(tag, time, record)
Expand All @@ -96,11 +102,13 @@ def initialize(field = '__test__')
attr_reader :started

def start
super
@started = true
end

def shutdown
@started = false
super
end

def filter(tag, time, record)
Expand Down
142 changes: 142 additions & 0 deletions test/test_root_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,146 @@ def configure_ra(conf_str)
assert_false @ra.outputs.first.started
end
end

sub_test_case 'configured with MultiOutput plugins' do
setup do
@ra = RootAgent.new(log: $log)
stub(Engine).root_agent { @ra }
@ra.configure(Config.parse(<<-EOC, "(test)", "(test_dir)", true))
<source>
@type test_in
@id test_in
</source>
<filter>
@type test_filter
@id test_filter
</filter>
<match **>
@type copy
@id test_copy
<store>
@type test_out
@id test_out1
</store>
<store>
@type test_out
@id test_out2
</store>
</match>
EOC
@ra
end

test 'plugin status with multi output' do
assert_equal 1, @ra.inputs.size
assert_equal 1, @ra.filters.size
assert_equal 3, @ra.outputs.size

@ra.start
assert_equal [true], @ra.inputs.map{|i| i.started? }
assert_equal [true], @ra.filters.map{|i| i.started? }
assert_equal [true, true, true], @ra.outputs.map{|i| i.started? }

@ra.shutdown
assert_equal [true], @ra.inputs.map{|i| i.stopped? }
assert_equal [true], @ra.filters.map{|i| i.stopped? }
assert_equal [true, true, true], @ra.outputs.map{|i| i.stopped? }

assert_equal [true], @ra.inputs.map{|i| i.before_shutdown? }
assert_equal [true], @ra.filters.map{|i| i.before_shutdown? }
assert_equal [true, true, true], @ra.outputs.map{|i| i.before_shutdown? }

assert_equal [true], @ra.inputs.map{|i| i.shutdown? }
assert_equal [true], @ra.filters.map{|i| i.shutdown? }
assert_equal [true, true, true], @ra.outputs.map{|i| i.shutdown? }

assert_equal [true], @ra.inputs.map{|i| i.after_shutdown? }
assert_equal [true], @ra.filters.map{|i| i.after_shutdown? }
assert_equal [true, true, true], @ra.outputs.map{|i| i.after_shutdown? }

assert_equal [true], @ra.inputs.map{|i| i.closed? }
assert_equal [true], @ra.filters.map{|i| i.closed? }
assert_equal [true, true, true], @ra.outputs.map{|i| i.closed? }

assert_equal [true], @ra.inputs.map{|i| i.terminated? }
assert_equal [true], @ra.filters.map{|i| i.terminated? }
assert_equal [true, true, true], @ra.outputs.map{|i| i.terminated? }
end
end

sub_test_case 'configured with MultiOutput plugins and labels' do
setup do
@ra = RootAgent.new(log: $log)
stub(Engine).root_agent { @ra }
@ra.configure(Config.parse(<<-EOC, "(test)", "(test_dir)", true))
<source>
@type test_in
@id test_in
@label @testing
</source>
<label @testing>
<filter>
@type test_filter
@id test_filter
</filter>
<match **>
@type copy
@id test_copy
<store>
@type test_out
@id test_out1
</store>
<store>
@type test_out
@id test_out2
</store>
</match>
</label>
EOC
@ra
end

test 'plugin status with multi output' do
assert_equal 1, @ra.inputs.size
assert_equal 0, @ra.filters.size
assert_equal 0, @ra.outputs.size
assert_equal 1, @ra.labels.size
assert_equal '@testing', @ra.labels.keys.first
assert_equal 1, @ra.labels.values.first.filters.size
assert_equal 3, @ra.labels.values.first.outputs.size

label_filters = @ra.labels.values.first.filters
label_outputs = @ra.labels.values.first.outputs

@ra.start
assert_equal [true], @ra.inputs.map{|i| i.started? }
assert_equal [true], label_filters.map{|i| i.started? }
assert_equal [true, true, true], label_outputs.map{|i| i.started? }

@ra.shutdown
assert_equal [true], @ra.inputs.map{|i| i.stopped? }
assert_equal [true], label_filters.map{|i| i.stopped? }
assert_equal [true, true, true], label_outputs.map{|i| i.stopped? }

assert_equal [true], @ra.inputs.map{|i| i.before_shutdown? }
assert_equal [true], label_filters.map{|i| i.before_shutdown? }
assert_equal [true, true, true], label_outputs.map{|i| i.before_shutdown? }

assert_equal [true], @ra.inputs.map{|i| i.shutdown? }
assert_equal [true], label_filters.map{|i| i.shutdown? }
assert_equal [true, true, true], label_outputs.map{|i| i.shutdown? }

assert_equal [true], @ra.inputs.map{|i| i.after_shutdown? }
assert_equal [true], label_filters.map{|i| i.after_shutdown? }
assert_equal [true, true, true], label_outputs.map{|i| i.after_shutdown? }

assert_equal [true], @ra.inputs.map{|i| i.closed? }
assert_equal [true], label_filters.map{|i| i.closed? }
assert_equal [true, true, true], label_outputs.map{|i| i.closed? }

assert_equal [true], @ra.inputs.map{|i| i.terminated? }
assert_equal [true], label_filters.map{|i| i.terminated? }
assert_equal [true, true, true], label_outputs.map{|i| i.terminated? }
end
end
end