fluent-plugin-select 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +19 -1
- data/fluent-plugin-select.gemspec +2 -2
- data/lib/fluent/plugin/out_select.rb +44 -14
- data/test/plugin/test_out_select.rb +47 -2
- metadata +6 -6
data/README.markdown
CHANGED
@@ -16,8 +16,9 @@ This sample config outputs access logs that have status code 200.
|
|
16
16
|
</source>
|
17
17
|
<match tag>
|
18
18
|
type select
|
19
|
-
|
19
|
+
select record["code"] == "200"
|
20
20
|
add_prefix filtered
|
21
|
+
timeout 1s
|
21
22
|
</match>
|
22
23
|
<match filtered.tag>
|
23
24
|
type file
|
@@ -26,3 +27,20 @@ This sample config outputs access logs that have status code 200.
|
|
26
27
|
|
27
28
|
|
28
29
|
The parameter "select" can use 3 variables in event log; tag, time, record. The format of time is an integer number of seconds since the Epoch. The format of record is hash.
|
30
|
+
|
31
|
+
|
32
|
+
tag is alternative for add\_prefix. The 2 following match directives are same:
|
33
|
+
|
34
|
+
<match tag>
|
35
|
+
type select
|
36
|
+
select record["code"] == "200"
|
37
|
+
add_prefix filtered
|
38
|
+
timeout 1s
|
39
|
+
</match>
|
40
|
+
<match tag>
|
41
|
+
type select
|
42
|
+
select record["code"] == "200"
|
43
|
+
tag filtered.tag
|
44
|
+
timeout 1s
|
45
|
+
</match>
|
46
|
+
|
@@ -3,14 +3,14 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "fluent-plugin-select"
|
6
|
-
s.version = "0.0.
|
6
|
+
s.version = "0.0.3"
|
7
7
|
s.authors = ["Kohei Tomita"]
|
8
8
|
s.email = ["tommy.fmale@gmail.com"]
|
9
9
|
s.homepage = "https://github.com/tomity/fluent-plugin-select"
|
10
10
|
s.summary = %q{fluent-plugin-select is the non-buffered plugin that can be filtered by ruby script. }
|
11
11
|
s.description = %q{fluent-plugin-select is the non-buffered plugin that can be filtered by ruby script. }
|
12
12
|
|
13
|
-
s.rubyforge_project = "fluent-plugin-select
|
13
|
+
s.rubyforge_project = "fluent-plugin-select"
|
14
14
|
|
15
15
|
s.files = `git ls-files`.split("\n")
|
16
16
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -4,30 +4,60 @@ module Fluent
|
|
4
4
|
Fluent::Plugin.register_output('select', self)
|
5
5
|
|
6
6
|
config_param :select, :string
|
7
|
-
config_param :add_prefix, :string
|
8
|
-
config_param :
|
7
|
+
config_param :add_prefix, :string, :default => nil
|
8
|
+
config_param :tag, :string, :default => nil
|
9
|
+
config_param :timeout, :time, :default => 1
|
10
|
+
|
11
|
+
def configure(conf)
|
12
|
+
super
|
13
|
+
if @add_prefix
|
14
|
+
@mode = "add_prefix"
|
15
|
+
elsif @tag
|
16
|
+
@mode = "tag"
|
17
|
+
else
|
18
|
+
raise ConfigError, "Either add_prefix or tag is required "
|
19
|
+
end
|
20
|
+
end
|
9
21
|
|
10
22
|
def emit(tag, es, chain)
|
11
23
|
begin
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
else
|
18
|
-
$log.trace {"filtered: #{Time.at(time)} #{tag} #{record.inspect}"}
|
19
|
-
end
|
20
|
-
}
|
21
|
-
time_records.each do |time, record|
|
22
|
-
Fluent::Engine::emit(@add_prefix + "." + tag, time, record)
|
24
|
+
output_es = do_select(tag, es)
|
25
|
+
if @mode == "add_prefix"
|
26
|
+
Fluent::Engine::emit_stream(@add_prefix + "." + tag, output_es)
|
27
|
+
else
|
28
|
+
Fluent::Engine::emit_stream(@tag, output_es)
|
23
29
|
end
|
24
30
|
chain.next
|
25
|
-
|
31
|
+
output_es #for test
|
26
32
|
rescue SyntaxError => e
|
27
33
|
chain.next
|
28
34
|
$log.error "Select command is syntax error: #{@select}"
|
29
35
|
e #for test
|
30
36
|
end
|
31
37
|
end
|
38
|
+
|
39
|
+
def do_select(tag, es)
|
40
|
+
output_es = MultiEventStream.new
|
41
|
+
es.each {|time, record|
|
42
|
+
timeout_block{
|
43
|
+
if eval(@select)
|
44
|
+
output_es.add(time, record)
|
45
|
+
else
|
46
|
+
$log.trace {"filtered: #{Time.at(time)} #{tag} #{record.inspect}"}
|
47
|
+
end
|
48
|
+
}
|
49
|
+
}
|
50
|
+
output_es
|
51
|
+
end
|
52
|
+
|
53
|
+
def timeout_block
|
54
|
+
begin
|
55
|
+
Timeout.timeout(@timeout){
|
56
|
+
yield
|
57
|
+
}
|
58
|
+
rescue Timeout::Error
|
59
|
+
$log.error {"Timeout: #{Time.at(time)} #{tag} #{record.inspect}"}
|
60
|
+
end
|
61
|
+
end
|
32
62
|
end
|
33
63
|
end
|
@@ -66,8 +66,8 @@ class SelectOutputTest < Test::Unit::TestCase
|
|
66
66
|
d1.run do
|
67
67
|
d1.emit(record, time)
|
68
68
|
end
|
69
|
-
|
70
|
-
assert_equal 0,
|
69
|
+
es = d1.emits
|
70
|
+
assert_equal 0, es.length
|
71
71
|
end
|
72
72
|
|
73
73
|
def test_syntax_error
|
@@ -86,4 +86,49 @@ class SelectOutputTest < Test::Unit::TestCase
|
|
86
86
|
e = d1.instance.emit(tag, es, chain)
|
87
87
|
assert e.kind_of?(SyntaxError)
|
88
88
|
end
|
89
|
+
|
90
|
+
def test_match_tag_using_tag_param
|
91
|
+
tag = 'tag' #match
|
92
|
+
time = Time.local(2012, 10, 10, 10, 10, 10) #not match
|
93
|
+
record = {'code' => '300'} #not match
|
94
|
+
|
95
|
+
d1 = create_driver %[
|
96
|
+
select tag == "tag" or record["code"] == "200" or Time.at(time).sec == 0
|
97
|
+
tag prefix.tag
|
98
|
+
], tag
|
99
|
+
d1.run do
|
100
|
+
d1.emit(record, time)
|
101
|
+
end
|
102
|
+
emits = d1.emits
|
103
|
+
assert_equal 1, emits.length
|
104
|
+
assert_equal ["prefix.#{tag}", time.to_i, record], emits[0]
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_config_error
|
108
|
+
tag = 'tag' #match
|
109
|
+
time = Time.local(2012, 10, 10, 10, 10, 10) #not match
|
110
|
+
record = {'code' => '300'} #not match
|
111
|
+
|
112
|
+
assert_raise(Fluent::ConfigError){
|
113
|
+
create_driver %[
|
114
|
+
select tag == "tag" or record["code"] == "200" or Time.at(time).sec == 0
|
115
|
+
], tag
|
116
|
+
}
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_timeout
|
120
|
+
tag = 'tag' #match
|
121
|
+
time = Time.local(2012, 10, 10, 10, 10, 10) #not match
|
122
|
+
record = {'code' => '300'} #not match
|
123
|
+
|
124
|
+
d1 = create_driver %[
|
125
|
+
select sleep 10
|
126
|
+
add_prefix prefix
|
127
|
+
], tag
|
128
|
+
d1.run do
|
129
|
+
d1.emit(record, time)
|
130
|
+
end
|
131
|
+
emits = d1.emits
|
132
|
+
assert_equal 0, emits.length
|
133
|
+
end
|
89
134
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-select
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-08-11 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70178059895040 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.9.2.2
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70178059895040
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: fluentd
|
27
|
-
requirement: &
|
27
|
+
requirement: &70178059894500 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: 0.10.24
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70178059894500
|
36
36
|
description: ! 'fluent-plugin-select is the non-buffered plugin that can be filtered
|
37
37
|
by ruby script. '
|
38
38
|
email:
|
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
70
|
requirements: []
|
71
|
-
rubyforge_project: fluent-plugin-select
|
71
|
+
rubyforge_project: fluent-plugin-select
|
72
72
|
rubygems_version: 1.8.17
|
73
73
|
signing_key:
|
74
74
|
specification_version: 3
|