fluent-plugin-map 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 +13 -0
- data/fluent-plugin-map.gemspec +1 -1
- data/lib/fluent/plugin/out_map.rb +28 -8
- data/test/plugin/test_out_map.rb +75 -0
- metadata +6 -6
data/README.markdown
CHANGED
@@ -30,3 +30,16 @@ This sample config output code file and time file.
|
|
30
30
|
The parameter "map" 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.
|
31
31
|
The config file parses # as the begin of comment. So the "map" value cannot use #{tag} operation.
|
32
32
|
This plugin can output multi logs by seting multi to true.
|
33
|
+
|
34
|
+
If you don't use multi option, you can use key, time, record parameter. The 2 following match directive is same:
|
35
|
+
|
36
|
+
<match tag>
|
37
|
+
type map
|
38
|
+
map ["code." + tag, time, {"code" => record["code"].to_i}]
|
39
|
+
</match>
|
40
|
+
<match tag>
|
41
|
+
type map
|
42
|
+
tag "code." + tag
|
43
|
+
time time
|
44
|
+
record {"code" => record["code"].to_i}
|
45
|
+
</match>
|
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.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-map"
|
@@ -3,23 +3,43 @@ module Fluent
|
|
3
3
|
class MapOutput < Fluent::Output
|
4
4
|
Fluent::Plugin.register_output('map', self)
|
5
5
|
|
6
|
-
config_param :map, :string
|
6
|
+
config_param :map, :string, :default => nil
|
7
|
+
config_param :key, :string, :default => nil
|
8
|
+
config_param :time, :string, :default => nil
|
9
|
+
config_param :record, :string, :default => nil
|
7
10
|
config_param :multi, :bool, :default => false
|
8
11
|
|
9
12
|
def configure(conf)
|
10
13
|
super
|
11
|
-
|
14
|
+
if @map
|
15
|
+
$log.debug { "map: #{@map}" }
|
16
|
+
@mode = "tuple"
|
17
|
+
elsif @key && @time && @record
|
18
|
+
raise ConfigError, "multi and 3 parameters(key, time, and record) are not compatible" if @multi
|
19
|
+
$log.debug { "key: #{@key}, time: #{@time}, record: #{@record}" }
|
20
|
+
@mode = "each"
|
21
|
+
else
|
22
|
+
raise ConfigError, "Either map or 3 parameters(key, time, and record) is required "
|
23
|
+
end
|
12
24
|
end
|
13
25
|
|
14
26
|
def emit(tag, es, chain)
|
15
27
|
begin
|
16
28
|
tuples = []
|
17
29
|
es.each {|time, record|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
30
|
+
case @mode
|
31
|
+
when "tuple"
|
32
|
+
new_tuple = eval(@map)
|
33
|
+
if @multi
|
34
|
+
tuples.concat new_tuple
|
35
|
+
else
|
36
|
+
tuples << new_tuple
|
37
|
+
end
|
38
|
+
when "each"
|
39
|
+
new_key = eval(@key)
|
40
|
+
new_time = eval(@time)
|
41
|
+
new_record = eval(@record)
|
42
|
+
tuples << [new_key, new_time, new_record]
|
23
43
|
end
|
24
44
|
}
|
25
45
|
tuples.each do |tag, time, record|
|
@@ -33,7 +53,7 @@ module Fluent
|
|
33
53
|
tuples
|
34
54
|
rescue SyntaxError => e
|
35
55
|
chain.next
|
36
|
-
$log.error "
|
56
|
+
$log.error "map command is syntax error: #{@map}"
|
37
57
|
e #for test
|
38
58
|
end
|
39
59
|
end
|
data/test/plugin/test_out_map.rb
CHANGED
@@ -79,4 +79,79 @@ class MapOutputTest < Test::Unit::TestCase
|
|
79
79
|
e = d1.instance.emit(tag, es, chain)
|
80
80
|
assert e.kind_of?(SyntaxError)
|
81
81
|
end
|
82
|
+
|
83
|
+
def test_tag_convert_using_key_time_record
|
84
|
+
tag = 'tag'
|
85
|
+
time = Time.local(2012, 10, 10, 10, 10, 10)
|
86
|
+
record = {'code' => '300'}
|
87
|
+
|
88
|
+
d1 = create_driver %[
|
89
|
+
key "newtag"
|
90
|
+
time time
|
91
|
+
record record
|
92
|
+
], tag
|
93
|
+
d1.run do
|
94
|
+
d1.emit(record, time)
|
95
|
+
end
|
96
|
+
emits = d1.emits
|
97
|
+
assert_equal 1, emits.length
|
98
|
+
assert_equal ["newtag", time.to_i, record], emits[0]
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_config_error_key
|
102
|
+
tag = "tag"
|
103
|
+
time = Time.local(2012, 10, 10, 10, 10, 0)
|
104
|
+
record = {'code' => '300'}
|
105
|
+
|
106
|
+
#require time
|
107
|
+
assert_raise(Fluent::ConfigError){
|
108
|
+
create_driver %[
|
109
|
+
time time
|
110
|
+
record record
|
111
|
+
], tag
|
112
|
+
}
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_config_error_time
|
116
|
+
tag = "tag"
|
117
|
+
record = {'code' => '300'}
|
118
|
+
|
119
|
+
#require time
|
120
|
+
assert_raise(Fluent::ConfigError){
|
121
|
+
create_driver %[
|
122
|
+
key "newtag"
|
123
|
+
record record
|
124
|
+
], tag
|
125
|
+
}
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_config_error_record
|
129
|
+
tag = "tag"
|
130
|
+
time = Time.local(2012, 10, 10, 10, 10, 0)
|
131
|
+
|
132
|
+
#require record
|
133
|
+
assert_raise(Fluent::ConfigError){
|
134
|
+
create_driver %[
|
135
|
+
key "newtag"
|
136
|
+
time time
|
137
|
+
], tag
|
138
|
+
}
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_config_error_multi
|
142
|
+
tag = "tag"
|
143
|
+
time = Time.local(2012, 10, 10, 10, 10, 0)
|
144
|
+
time = Time.local(2012, 10, 10, 10, 10, 0)
|
145
|
+
record = {'code' => '300'}
|
146
|
+
|
147
|
+
#require time
|
148
|
+
assert_raise(Fluent::ConfigError){
|
149
|
+
create_driver %[
|
150
|
+
key "newtag"
|
151
|
+
time time
|
152
|
+
record record
|
153
|
+
multi true
|
154
|
+
], tag
|
155
|
+
}
|
156
|
+
end
|
82
157
|
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.3
|
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-
|
12
|
+
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: &70263359418000 !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: *70263359418000
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: fluentd
|
27
|
-
requirement: &
|
27
|
+
requirement: &70263359417460 !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: *70263359417460
|
36
36
|
description: ! 'fluent-plugin-map is the non-buffered plugin that can convert an event
|
37
37
|
log to different event log(s). '
|
38
38
|
email:
|