fluent-plugin-flatten 0.0.10 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +13 -0
- data/Appraisals +3 -0
- data/fluent-plugin-flatten.gemspec +4 -4
- data/gemfiles/fluentd_v0.14.gemfile +7 -0
- data/lib/fluent/plugin/out_flatten.rb +13 -22
- data/test/plugin/test_out_flatten.rb +135 -118
- data/test/test_helper.rb +4 -27
- metadata +29 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f89bacd8f75c114993634731bce29093a182fe7
|
4
|
+
data.tar.gz: 58defd52ece87e48bfeffa339591a10d79b256d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c13ccffa9ee50538ce8ac06448e2f5f1cb56b7d413d254964dd17ee6f42984e5038741230eee8e282a3ac90012d1973866df291442f01d084e41dc927e8a283
|
7
|
+
data.tar.gz: a10848bb4ec3b8e4ee37a90634a7b1e7e05255110c952210edd59ec0127e1ac21f351b58ef4c9aec153a8b70e4b56f3c7870407203caa6012c90bfb6501694ab
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Appraisals
ADDED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = 'fluent-plugin-flatten'
|
3
|
-
gem.version = '0.0
|
3
|
+
gem.version = '0.1.0'
|
4
4
|
gem.authors = ['Kentaro Kuribayashi']
|
5
5
|
gem.email = ['kentarok@gmail.com']
|
6
6
|
gem.homepage = 'http://github.com/kentaro/fluent-plugin-flatten'
|
@@ -13,8 +13,8 @@ Gem::Specification.new do |gem|
|
|
13
13
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
14
|
gem.require_paths = ['lib']
|
15
15
|
|
16
|
+
gem.add_development_dependency 'appraisal'
|
16
17
|
gem.add_development_dependency 'rake'
|
17
|
-
gem.add_development_dependency 'test-unit', '~> 3.
|
18
|
-
gem.add_runtime_dependency 'fluentd'
|
18
|
+
gem.add_development_dependency 'test-unit', '~> 3.0'
|
19
|
+
gem.add_runtime_dependency 'fluentd', ['>= 0.14.8', '< 2']
|
19
20
|
end
|
20
|
-
|
@@ -1,29 +1,22 @@
|
|
1
1
|
require 'json'
|
2
2
|
|
3
|
-
module Fluent
|
4
|
-
class FlattenOutput < Output
|
3
|
+
module Fluent::Plugin
|
4
|
+
class FlattenOutput < Fluent::Plugin::Output
|
5
5
|
include Fluent::HandleTagNameMixin
|
6
6
|
class Error < StandardError; end
|
7
7
|
|
8
8
|
Fluent::Plugin.register_output('flatten', self)
|
9
9
|
|
10
|
-
|
11
|
-
unless method_defined?(:router)
|
12
|
-
define_method("router") { Fluent::Engine }
|
13
|
-
end
|
10
|
+
helpers :event_emitter
|
14
11
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
config_param :parse_json, :bool, :default => true,
|
24
|
-
:desc => "Parse json record."
|
25
|
-
config_param :replace_space_in_tag, :string, :default => nil,
|
26
|
-
:desc => "Replaces spaces in the resulting tag with the key passed"
|
12
|
+
desc "The key is used to point a key whose value contains JSON-formatted string."
|
13
|
+
config_param :key, :string
|
14
|
+
desc "This plugin sets `value` for this option as a default if it's not set."
|
15
|
+
config_param :inner_key, :string, default: 'value'
|
16
|
+
desc "Parse json record."
|
17
|
+
config_param :parse_json, :bool, default: true
|
18
|
+
desc "Replaces spaces in the resulting tag with the key passed"
|
19
|
+
config_param :replace_space_in_tag, :string, default: nil
|
27
20
|
|
28
21
|
def configure(conf)
|
29
22
|
super
|
@@ -34,11 +27,11 @@ DESC
|
|
34
27
|
!add_tag_prefix &&
|
35
28
|
!add_tag_suffix
|
36
29
|
)
|
37
|
-
raise ConfigError, "out_flatten: At least one of remove_tag_prefix/remove_tag_suffix/add_tag_prefix/add_tag_suffix is required to be set"
|
30
|
+
raise Fluent::ConfigError, "out_flatten: At least one of remove_tag_prefix/remove_tag_suffix/add_tag_prefix/add_tag_suffix is required to be set"
|
38
31
|
end
|
39
32
|
end
|
40
33
|
|
41
|
-
def
|
34
|
+
def process(tag, es)
|
42
35
|
es.each do |time, record|
|
43
36
|
flattened = flatten(record)
|
44
37
|
|
@@ -52,8 +45,6 @@ DESC
|
|
52
45
|
end
|
53
46
|
end
|
54
47
|
end
|
55
|
-
|
56
|
-
chain.next
|
57
48
|
end
|
58
49
|
|
59
50
|
def flatten(record)
|
@@ -11,144 +11,161 @@ class FlattenOutputTest < Test::Unit::TestCase
|
|
11
11
|
remove_tag_prefix test.
|
12
12
|
]
|
13
13
|
|
14
|
-
def create_driver(conf = DEFAULT_CONFIG
|
15
|
-
Fluent::Test::
|
14
|
+
def create_driver(conf = DEFAULT_CONFIG)
|
15
|
+
Fluent::Test::Driver::Output.new(Fluent::Plugin::FlattenOutput).configure(conf)
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
assert_equal 'foo', d2.instance.key
|
36
|
-
assert_equal 'flattened.', d2.instance.add_tag_prefix
|
37
|
-
assert_equal /^test\./, d2.instance.remove_tag_prefix
|
38
|
-
assert_equal 'value_for_flat_key', d2.instance.inner_key
|
39
|
-
|
40
|
-
# when `parse_json` is false
|
41
|
-
d3 = create_driver(%[
|
42
|
-
key foo
|
43
|
-
add_tag_prefix flattened.
|
44
|
-
remove_tag_prefix test.
|
45
|
-
inner_key value_for_flat_key
|
46
|
-
parse_json false
|
47
|
-
])
|
48
|
-
|
49
|
-
assert_equal 'foo', d3.instance.key
|
50
|
-
assert_equal 'flattened.', d3.instance.add_tag_prefix
|
51
|
-
assert_equal /^test\./, d3.instance.remove_tag_prefix
|
52
|
-
assert_equal 'value_for_flat_key', d3.instance.inner_key
|
53
|
-
assert_equal false, d3.instance.parse_json
|
54
|
-
|
55
|
-
# when mandatory keys not set
|
56
|
-
assert_raise(Fluent::ConfigError) do
|
57
|
-
create_driver(%[
|
58
|
-
key foo
|
59
|
-
inner_key value_for_keypath
|
18
|
+
sub_test_case "configure" do
|
19
|
+
test "when `inner_key` option is not set" do
|
20
|
+
d = create_driver
|
21
|
+
|
22
|
+
assert_equal 'foo', d.instance.key
|
23
|
+
assert_equal 'flattened.', d.instance.add_tag_prefix
|
24
|
+
assert_equal /^test\./, d.instance.remove_tag_prefix
|
25
|
+
assert_equal 'value', d.instance.inner_key # default value
|
26
|
+
end
|
27
|
+
|
28
|
+
test "when `inner_key` is set" do
|
29
|
+
d = create_driver(%[
|
30
|
+
key foo
|
31
|
+
add_tag_prefix flattened.
|
32
|
+
remove_tag_prefix test.
|
33
|
+
inner_key value_for_flat_key
|
60
34
|
])
|
35
|
+
|
36
|
+
assert_equal 'foo', d.instance.key
|
37
|
+
assert_equal 'flattened.', d.instance.add_tag_prefix
|
38
|
+
assert_equal /^test\./, d.instance.remove_tag_prefix
|
39
|
+
assert_equal 'value_for_flat_key', d.instance.inner_key
|
40
|
+
end
|
41
|
+
|
42
|
+
test "when `parse_json` is false" do
|
43
|
+
d = create_driver(%[
|
44
|
+
key foo
|
45
|
+
add_tag_prefix flattened.
|
46
|
+
remove_tag_prefix test.
|
47
|
+
inner_key value_for_flat_key
|
48
|
+
parse_json false
|
49
|
+
])
|
50
|
+
|
51
|
+
assert_equal 'foo', d.instance.key
|
52
|
+
assert_equal 'flattened.', d.instance.add_tag_prefix
|
53
|
+
assert_equal /^test\./, d.instance.remove_tag_prefix
|
54
|
+
assert_equal 'value_for_flat_key', d.instance.inner_key
|
55
|
+
assert_equal false, d.instance.parse_json
|
56
|
+
end
|
57
|
+
|
58
|
+
test "mandatory parameters are missing" do
|
59
|
+
assert_raise(Fluent::ConfigError) do
|
60
|
+
create_driver(%[
|
61
|
+
key foo
|
62
|
+
inner_key value_for_keypath
|
63
|
+
])
|
64
|
+
end
|
61
65
|
end
|
62
66
|
end
|
63
67
|
|
64
|
-
|
65
|
-
|
68
|
+
sub_test_case "flatten" do
|
69
|
+
test "plain" do
|
70
|
+
d = create_driver
|
66
71
|
|
67
|
-
|
68
|
-
|
72
|
+
flattened = d.instance.flatten({ 'foo' => '{"bar" : "baz"}', 'hoge' => 'fuga' })
|
73
|
+
assert_equal({ 'foo.bar' => { 'value' => 'baz' } }, flattened)
|
74
|
+
end
|
69
75
|
|
70
|
-
|
71
|
-
|
72
|
-
flattened = d.instance.flatten({ 'foo' => '{\"bar\" : \"baz\"}' })
|
73
|
-
assert_equal({ 'foo.bar' => { 'value' => 'baz' } }, flattened)
|
76
|
+
test "excessively escaped json value" do
|
77
|
+
d = create_driver
|
74
78
|
|
75
|
-
|
76
|
-
|
77
|
-
|
79
|
+
# XXX work-around
|
80
|
+
# fluentd seems to escape json value excessively
|
81
|
+
flattened = d.instance.flatten({ 'foo' => '{\"bar\" : \"baz\"}' })
|
82
|
+
assert_equal({ 'foo.bar' => { 'value' => 'baz' } }, flattened)
|
83
|
+
end
|
78
84
|
|
79
|
-
|
80
|
-
|
81
|
-
|
85
|
+
test "empty" do
|
86
|
+
d = create_driver
|
87
|
+
flattened = d.instance.flatten({ 'foo' => '' })
|
88
|
+
assert_equal({}, flattened)
|
89
|
+
end
|
90
|
+
|
91
|
+
test "invalid json" do
|
92
|
+
d = create_driver
|
93
|
+
flattened = d.instance.flatten({ 'foo' => '-' })
|
94
|
+
assert_equal({}, flattened)
|
95
|
+
end
|
82
96
|
end
|
83
97
|
|
84
|
-
|
85
|
-
|
86
|
-
|
98
|
+
sub_test_case "emit" do
|
99
|
+
test "default config" do
|
100
|
+
# test1 default config
|
101
|
+
d = create_driver
|
87
102
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
# test2 parse_json is set false
|
113
|
-
d2 = create_driver(%[
|
114
|
-
key foo
|
115
|
-
add_tag_prefix flattened.
|
116
|
-
remove_tag_prefix test.
|
117
|
-
parse_json false
|
118
|
-
replace_space_in_tag _
|
119
|
-
])
|
120
|
-
|
121
|
-
d2.run do
|
122
|
-
d2.emit( 'foo' => {'bar' => 'baz'}, 'hoge' => 'fuga' )
|
123
|
-
d2.emit( 'foo' => {'bar' => {'qux' => 'quux', 'hoe' => 'poe' }, 'baz' => 'bazz' }, 'hoge' => 'fuga' )
|
124
|
-
d2.emit( 'foo' => {'bar hoge' => 'baz', 'hoe baz' => 'poe'}, 'hoge' => 'fuga' )
|
103
|
+
d.run(default_tag: "test") do
|
104
|
+
d.feed( 'foo' => '{"bar" : "baz"}', 'hoge' => 'fuga' )
|
105
|
+
d.feed( 'foo' => '{"bar" : {"qux" : "quux", "hoe" : "poe" }, "baz" : "bazz" }', 'hoge' => 'fuga' )
|
106
|
+
end
|
107
|
+
events = d.events
|
108
|
+
|
109
|
+
assert_equal 4, events.count
|
110
|
+
|
111
|
+
# ["flattened.foo.bar", 1354689632, {"value"=>"baz"}]
|
112
|
+
assert_equal 'flattened.foo.bar', events[0][0]
|
113
|
+
assert_equal 'baz', events[0][2]['value']
|
114
|
+
|
115
|
+
# ["flattened.foo.bar.qux", 1354689632, {"value"=>"quux"}]
|
116
|
+
assert_equal 'flattened.foo.bar.qux', events[1][0]
|
117
|
+
assert_equal 'quux', events[1][2]['value']
|
118
|
+
|
119
|
+
# ["flattened.foo.bar.hoe", 1354689632, {"value"=>"poe"}]
|
120
|
+
assert_equal 'flattened.foo.bar.hoe', events[2][0]
|
121
|
+
assert_equal 'poe', events[2][2]['value']
|
122
|
+
|
123
|
+
# ["flattened.foo.bar.baz", 1354689632, {"value"=>"bazz"}]
|
124
|
+
assert_equal 'flattened.foo.baz', events[3][0]
|
125
|
+
assert_equal 'bazz', events[3][2]['value']
|
125
126
|
end
|
126
|
-
emits2 = d2.emits
|
127
127
|
|
128
|
-
|
128
|
+
test "parse_json is set false" do
|
129
|
+
d = create_driver(%[
|
130
|
+
key foo
|
131
|
+
add_tag_prefix flattened.
|
132
|
+
remove_tag_prefix test.
|
133
|
+
parse_json false
|
134
|
+
replace_space_in_tag _
|
135
|
+
])
|
136
|
+
|
137
|
+
d.run(default_tag: "test") do
|
138
|
+
d.feed( 'foo' => {'bar' => 'baz'}, 'hoge' => 'fuga' )
|
139
|
+
d.feed( 'foo' => {'bar' => {'qux' => 'quux', 'hoe' => 'poe' }, 'baz' => 'bazz' }, 'hoge' => 'fuga' )
|
140
|
+
d.feed( 'foo' => {'bar hoge' => 'baz', 'hoe baz' => 'poe'}, 'hoge' => 'fuga' )
|
141
|
+
end
|
142
|
+
events = d.events
|
143
|
+
|
144
|
+
assert_equal 6, events.count
|
129
145
|
|
130
|
-
|
131
|
-
|
132
|
-
|
146
|
+
# ["flattened.foo.bar", 1354689632, {"value"=>"baz"}]
|
147
|
+
assert_equal 'flattened.foo.bar', events[0][0]
|
148
|
+
assert_equal 'baz', events[0][2]['value']
|
133
149
|
|
134
|
-
|
135
|
-
|
136
|
-
|
150
|
+
# ["flattened.foo.bar.qux_qux", 1354689632, {"value"=>"quux"}]
|
151
|
+
assert_equal 'flattened.foo.bar.qux', events[1][0]
|
152
|
+
assert_equal 'quux', events[1][2]['value']
|
137
153
|
|
138
|
-
|
139
|
-
|
140
|
-
|
154
|
+
# ["flattened.foo.bar.hoe", 1354689632, {"value"=>"poe"}]
|
155
|
+
assert_equal 'flattened.foo.bar.hoe', events[2][0]
|
156
|
+
assert_equal 'poe', events[2][2]['value']
|
141
157
|
|
142
|
-
|
143
|
-
|
144
|
-
|
158
|
+
# ["flattened.foo.bar.baz", 1354689632, {"value"=>"bazz"}]
|
159
|
+
assert_equal 'flattened.foo.baz', events[3][0]
|
160
|
+
assert_equal 'bazz', events[3][2]['value']
|
145
161
|
|
146
|
-
|
147
|
-
|
148
|
-
|
162
|
+
# ["flattened.foo.bar_hoge", 1354689632, {"value"=>"baz"}]
|
163
|
+
assert_equal 'flattened.foo.bar_hoge', events[4][0]
|
164
|
+
assert_equal 'baz', events[4][2]['value']
|
149
165
|
|
150
|
-
|
151
|
-
|
152
|
-
|
166
|
+
# ["flattened.foo.hoe_baz", 1354689632, {"value"=>"baz"}]
|
167
|
+
assert_equal 'flattened.foo.hoe_baz', events[5][0]
|
168
|
+
assert_equal 'poe', events[5][2]['value']
|
169
|
+
end
|
153
170
|
end
|
154
171
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,32 +1,9 @@
|
|
1
|
-
require '
|
2
|
-
require 'bundler'
|
3
|
-
|
4
|
-
begin
|
5
|
-
Bundler.setup(:default, :development)
|
6
|
-
rescue Bundler::BundlerError => e
|
7
|
-
$stderr.puts e.message
|
8
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
-
exit e.status_code
|
10
|
-
end
|
11
|
-
|
1
|
+
require 'bundler/setup'
|
12
2
|
require 'test/unit'
|
13
3
|
|
14
|
-
$LOAD_PATH.unshift(File.join(
|
15
|
-
$LOAD_PATH.unshift(
|
4
|
+
$LOAD_PATH.unshift(File.join(__dir__, '..', 'lib'))
|
5
|
+
$LOAD_PATH.unshift(__dir__)
|
16
6
|
|
17
7
|
require 'fluent/test'
|
18
|
-
|
19
|
-
unless ENV.has_key?('VERBOSE')
|
20
|
-
nulllogger = Object.new
|
21
|
-
nulllogger.instance_eval {|obj|
|
22
|
-
def method_missing(method, *args)
|
23
|
-
# pass
|
24
|
-
end
|
25
|
-
}
|
26
|
-
$log = nulllogger
|
27
|
-
end
|
28
|
-
|
8
|
+
require 'fluent/test/driver/output'
|
29
9
|
require 'fluent/plugin/out_flatten'
|
30
|
-
|
31
|
-
class Test::Unit::TestCase
|
32
|
-
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-flatten
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kentaro Kuribayashi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: appraisal
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rake
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -30,28 +44,34 @@ dependencies:
|
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: 3.
|
47
|
+
version: '3.0'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: 3.
|
54
|
+
version: '3.0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: fluentd
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - ">="
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
61
|
+
version: 0.14.8
|
62
|
+
- - "<"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '2'
|
48
65
|
type: :runtime
|
49
66
|
prerelease: false
|
50
67
|
version_requirements: !ruby/object:Gem::Requirement
|
51
68
|
requirements:
|
52
69
|
- - ">="
|
53
70
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
71
|
+
version: 0.14.8
|
72
|
+
- - "<"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '2'
|
55
75
|
description: Fluentd plugin to extract values for nested key paths and re-emit them
|
56
76
|
as flat tag/record pairs.
|
57
77
|
email:
|
@@ -61,11 +81,14 @@ extensions: []
|
|
61
81
|
extra_rdoc_files: []
|
62
82
|
files:
|
63
83
|
- ".gitignore"
|
84
|
+
- ".travis.yml"
|
85
|
+
- Appraisals
|
64
86
|
- Gemfile
|
65
87
|
- LICENSE
|
66
88
|
- README.md
|
67
89
|
- Rakefile
|
68
90
|
- fluent-plugin-flatten.gemspec
|
91
|
+
- gemfiles/fluentd_v0.14.gemfile
|
69
92
|
- lib/fluent/plugin/out_flatten.rb
|
70
93
|
- test/plugin/test_out_flatten.rb
|
71
94
|
- test/test_helper.rb
|