-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
113 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
rvm: | ||
- 1.9.3 | ||
- 2.0.0 | ||
- 2.1.* | ||
- 2.1 | ||
- 2.2 | ||
gemfile: | ||
- Gemfile | ||
- Gemfile.v0.10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source "https://rubygems.org" | ||
|
||
gemspec | ||
gem 'fluentd', '~> 0.10.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<source> | ||
type dummy | ||
tag dummy | ||
</source> | ||
|
||
<filter dummy> | ||
type flowcounter_simple | ||
unit second | ||
</filter> | ||
|
||
<match dummy> | ||
type null | ||
</match> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<source> | ||
type dummy | ||
tag dummy | ||
</source> | ||
|
||
<match dummy> | ||
type flowcounter_simple | ||
unit second | ||
</match> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# I'm lazy to to implement filter plugin. Use output plugin instance | ||
require_relative 'out_flowcounter_simple' | ||
require 'forwardable' | ||
|
||
class Fluent::FlowCounterSimpleFilter < Fluent::Filter | ||
Fluent::Plugin.register_filter('flowcounter_simple', self) | ||
|
||
extend Forwardable | ||
attr_reader :output | ||
def_delegators :@output, :configure, :start, :shutdown, :flush_emit | ||
|
||
def initialize | ||
super | ||
@output = Fluent::FlowCounterSimpleOutput.new | ||
end | ||
|
||
def filter_stream(tag, es) | ||
@output.emit(tag, es, Fluent::NullOutputChain.instance) | ||
es | ||
end | ||
end if defined?(Fluent::Filter) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
require_relative '../helper' | ||
require "test/unit/rr" | ||
|
||
class FlowCounterSimpleFilterTest < Test::Unit::TestCase | ||
include Fluent | ||
|
||
def setup | ||
Fluent::Test.setup | ||
@time = Fluent::Engine.now | ||
end | ||
|
||
CONFIG = %[ | ||
unit second | ||
] | ||
|
||
def create_driver(conf = CONFIG) | ||
Fluent::Test::FilterTestDriver.new(Fluent::FlowCounterSimpleFilter).configure(conf, true) | ||
end | ||
|
||
def test_filter | ||
msgs = [] | ||
10.times do | ||
msgs << {'message'=> 'a' * 100} | ||
msgs << {'message'=> 'b' * 100} | ||
end | ||
d = create_driver | ||
filtered, log = filter(d, msgs) | ||
assert_equal msgs, filtered | ||
assert( log.include?("count:20"), log ) | ||
end | ||
|
||
private | ||
|
||
def filter(d, msgs) | ||
stub(d.instance.output).start | ||
stub(d.instance.output).shutdown | ||
d.run { | ||
msgs.each {|msg| | ||
d.filter(msg, @time) | ||
} | ||
} | ||
log = capture_log(d.instance.output.log) do | ||
d.instance.flush_emit(0) | ||
end | ||
filtered = d.filtered_as_array | ||
filtered_msgs = filtered.map {|m| m[2] } | ||
[filtered_msgs, log] | ||
end | ||
|
||
def capture_log(log) | ||
tmp = log.out | ||
log.out = StringIO.new | ||
yield | ||
return log.out.string | ||
ensure | ||
log.out = tmp | ||
end | ||
end if defined?(Fluent::Test::FilterTestDriver) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters