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

Use Fluent::Plugin::Filter instead Fluent::Filter to cover all filter classes #1118

Merged
merged 1 commit into from
Jul 20, 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
2 changes: 1 addition & 1 deletion lib/fluent/event_router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def find(tag)
pipeline = nil
@match_rules.each_with_index { |rule, i|
if rule.match?(tag)
if rule.collector.is_a?(Filter)
if rule.collector.is_a?(Plugin::Filter)
pipeline ||= Pipeline.new
pipeline.add_filter(rule.collector)
else
Expand Down
17 changes: 13 additions & 4 deletions test/test_event_router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class EventRouterTest < ::Test::Unit::TestCase
teardown do
@output = nil
@filter = nil
@compat_filter = nil
@error_output = nil
@emit_handler = nil
@default_collector = nil
Expand All @@ -22,6 +23,10 @@ def filter
@filter ||= FluentTestFilter.new
end

def compat_filter
@compat_filter ||= FluentCompatTestFilter.new
end

def error_output
@error_output ||= FluentTestErrorOutput.new
end
Expand Down Expand Up @@ -107,16 +112,20 @@ def events(num = DEFAULT_EVENT_NUM)
@pipeline.set_output(output)
end

test 'set one filer' do
@pipeline.add_filter(filter)
data('Filter plugin' => 'filter',
'Compat::Filter plugin' => 'compat_filter')
test 'set one filer' do |filter_type|
@pipeline.add_filter(filter_type == 'filter' ? filter : compat_filter)
@pipeline.emit_events('test', @es)
assert_equal 1, output.events.size
assert_equal 'value', output.events['test'].first['key']
assert_equal 0, output.events['test'].first['__test__']
end

test 'set one filer with multi events' do
@pipeline.add_filter(filter)
data('Filter plugin' => 'filter',
'Compat::Filter plugin' => 'compat_filter')
test 'set one filer with multi events' do |filter_type|
@pipeline.add_filter(filter_type == 'filter' ? filter : compat_filter)
@pipeline.emit_events('test', events)
assert_equal 1, output.events.size
assert_equal 5, output.events['test'].size
Expand Down
29 changes: 28 additions & 1 deletion test/test_plugin_classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,34 @@ def write(chunk)
end
end

class FluentTestFilter < ::Fluent::Filter
class FluentCompatTestFilter < ::Fluent::Filter
::Fluent::Plugin.register_filter('test_compat_filter', self)

def initialize(field = '__test__')
super()
@num = 0
@field = field
end

attr_reader :num
attr_reader :started

def start
@started = true
end

def shutdown
@started = false
end

def filter(tag, time, record)
record[@field] = @num
@num += 1
record
end
end

class FluentTestFilter < ::Fluent::Plugin::Filter
::Fluent::Plugin.register_filter('test_filter', self)

def initialize(field = '__test__')
Expand Down