Skip to content

Commit

Permalink
Merge pull request #1077 from okkez/add-feature-to-get-filtered-records
Browse files Browse the repository at this point in the history
Add feature to get filtered records to Fluent::Test::Driver::Filter
  • Loading branch information
tagomoris authored Jul 5, 2016
2 parents b0c2bc2 + d4814e4 commit 8cba9f0
Showing 1 changed file with 22 additions and 0 deletions.
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

0 comments on commit 8cba9f0

Please sign in to comment.