fluent-plugin-map 0.0.3.1 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/fluent-plugin-map.gemspec +1 -1
- data/lib/fluent/plugin/out_map.rb +56 -20
- data/test/plugin/test_out_map.rb +18 -0
- metadata +17 -7
data/fluent-plugin-map.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "fluent-plugin-map"
|
6
|
-
s.version = "0.0.
|
6
|
+
s.version = "0.0.4"
|
7
7
|
s.authors = ["Kohei Tomita"]
|
8
8
|
s.email = ["tommy.fmale@gmail.com"]
|
9
9
|
s.homepage = "https://github.com/tomity/fluent-plugin-map"
|
@@ -9,6 +9,7 @@ module Fluent
|
|
9
9
|
config_param :time, :string, :default => nil
|
10
10
|
config_param :record, :string, :default => nil
|
11
11
|
config_param :multi, :bool, :default => false
|
12
|
+
config_param :timeout, :time, :default => 1
|
12
13
|
|
13
14
|
def configure(conf)
|
14
15
|
super
|
@@ -27,16 +28,53 @@ module Fluent
|
|
27
28
|
|
28
29
|
def emit(tag, es, chain)
|
29
30
|
begin
|
30
|
-
|
31
|
-
|
31
|
+
tag_output_es = do_map(tag, es)
|
32
|
+
tag_output_es.each_pair do |tag, output_es|
|
33
|
+
Fluent::Engine::emit_stream(tag, output_es)
|
34
|
+
end
|
35
|
+
chain.next
|
36
|
+
tag_output_es
|
37
|
+
rescue SyntaxError => e
|
38
|
+
chain.next
|
39
|
+
$log.error "map command is syntax error: #{@map}"
|
40
|
+
e #for test
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def do_map(tag, es)
|
45
|
+
tuples = if @multi
|
46
|
+
generate_tuples_multi(tag, es)
|
47
|
+
else
|
48
|
+
generate_tuples_single(tag, es)
|
49
|
+
end
|
50
|
+
tag_output_es = Hash.new{|h, key| h[key] = MultiEventStream::new}
|
51
|
+
tuples.each do |tag, time, record|
|
52
|
+
if time == nil || record == nil
|
53
|
+
raise SyntaxError.new
|
54
|
+
end
|
55
|
+
tag_output_es[tag].add(time, record)
|
56
|
+
$log.trace { [tag, time, record].inspect }
|
57
|
+
end
|
58
|
+
tag_output_es
|
59
|
+
end
|
60
|
+
|
61
|
+
def generate_tuples_multi(tag, es)
|
62
|
+
tuples = []
|
63
|
+
es.each {|time, record|
|
64
|
+
new_tuple = eval(@map)
|
65
|
+
tuples.concat new_tuple
|
66
|
+
}
|
67
|
+
tuples
|
68
|
+
end
|
69
|
+
|
70
|
+
def generate_tuples_single(tag, es)
|
71
|
+
tuples = []
|
72
|
+
es.each {|time, record|
|
73
|
+
timeout_block(tag, time, record){
|
32
74
|
case @mode
|
33
75
|
when "tuple"
|
34
76
|
new_tuple = eval(@map)
|
35
|
-
|
36
|
-
tuples.concat new_tuple
|
37
|
-
else
|
38
|
-
tuples << new_tuple
|
39
|
-
end
|
77
|
+
tuples << new_tuple
|
40
78
|
when "each"
|
41
79
|
new_tag = eval(@tag)
|
42
80
|
new_time = eval(@time)
|
@@ -44,19 +82,17 @@ module Fluent
|
|
44
82
|
tuples << [new_tag, new_time, new_record]
|
45
83
|
end
|
46
84
|
}
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
rescue
|
57
|
-
|
58
|
-
$log.error "map command is syntax error: #{@map}"
|
59
|
-
e #for test
|
85
|
+
}
|
86
|
+
tuples
|
87
|
+
end
|
88
|
+
|
89
|
+
def timeout_block(tag, time, record)
|
90
|
+
begin
|
91
|
+
Timeout.timeout(@timeout){
|
92
|
+
yield
|
93
|
+
}
|
94
|
+
rescue Timeout::Error
|
95
|
+
$log.error {"Timeout: #{Time.at(time)} #{tag} #{record.inspect}"}
|
60
96
|
end
|
61
97
|
end
|
62
98
|
end
|
data/test/plugin/test_out_map.rb
CHANGED
@@ -173,4 +173,22 @@ class MapOutputTest < Test::Unit::TestCase
|
|
173
173
|
], tag
|
174
174
|
}
|
175
175
|
end
|
176
|
+
|
177
|
+
def test_timeout
|
178
|
+
tag = 'tag'
|
179
|
+
time = Time.local(2012, 10, 10, 10, 10, 10)
|
180
|
+
record = {'code' => '300'}
|
181
|
+
|
182
|
+
d1 = create_driver %[
|
183
|
+
key "newtag"
|
184
|
+
time sleep 10
|
185
|
+
record record
|
186
|
+
timeout 1s
|
187
|
+
], tag
|
188
|
+
d1.run do
|
189
|
+
d1.emit(record, time)
|
190
|
+
end
|
191
|
+
emits = d1.emits
|
192
|
+
assert_equal 0, emits.length
|
193
|
+
end
|
176
194
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-map
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: 0.9.2.2
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.9.2.2
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: fluentd
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ~>
|
@@ -32,7 +37,12 @@ dependencies:
|
|
32
37
|
version: 0.10.24
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.10.24
|
36
46
|
description: ! 'fluent-plugin-map is the non-buffered plugin that can convert an event
|
37
47
|
log to different event log(s). '
|
38
48
|
email:
|
@@ -69,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
79
|
version: '0'
|
70
80
|
requirements: []
|
71
81
|
rubyforge_project: fluent-plugin-map
|
72
|
-
rubygems_version: 1.8.
|
82
|
+
rubygems_version: 1.8.24
|
73
83
|
signing_key:
|
74
84
|
specification_version: 3
|
75
85
|
summary: fluent-plugin-map is the non-buffered plugin that can convert an event log
|