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

Add feature to get filtered records to Fluent::Test::Driver::Filter #1077

Merged
merged 1 commit into from
Jul 5, 2016
Merged
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
22 changes: 22 additions & 0 deletions lib/fluent/test/driver/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,31 @@ module Driver
class Filter < Base
include EventFeeder

attr_reader :filtered

def initialize(klass, opts: {}, &block)
super
raise ArgumentError, "plugin is not an instance of Fluent::Plugin::Filter" unless @instance.is_a? Fluent::Plugin::Filter
@filtered = []
end

def filtered_records
@filtered.map {|_time, record| record }
end

def instance_hook_after_started
super
filter_hook = ->(time, record) { @filtered << [time, record] }
m = Module.new do
define_method(:filter_stream) do |tag, es|
new_es = super(tag, es)
new_es.each do |time, record|
filter_hook.call(time, record)
end
new_es
end
end
@instance.singleton_class.prepend(m)
end
end
end
Expand Down