fluent-plugin-flatten-hash 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/fluent-plugin-flatten-hash.gemspec +2 -2
- data/lib/fluent/plugin/filter_flatten_hash.rb +7 -5
- data/lib/fluent/plugin/out_flatten_hash.rb +8 -5
- data/test/plugin/test_filter_flatten_array.rb +10 -10
- data/test/plugin/test_filter_flatten_hash.rb +13 -13
- data/test/plugin/test_out_flatten_hash.rb +29 -28
- metadata +13 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc9aa975dd6c6a5ae056a1ade23882751d3cb9a7
|
4
|
+
data.tar.gz: b076a3184513e59221f1dd2dcc8ead6099052406
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 580e9e5392a343865bf8849cceaca44d67fb6eea4ecc805d6f4b0cfc5d305cd09446808e3a5bb37d55bc5f770af5c3459b42fc7651cbace91690a5ae1d2bbbac
|
7
|
+
data.tar.gz: f194a77a00a8473921ae3465dd7e7505829814c29438cf511dc7c230405a04f68a679e3b3df6fb60c27e571be4c740022780d8943db8fc707279526a88c658ad
|
data/.travis.yml
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "fluent-plugin-flatten-hash"
|
7
|
-
spec.version = "0.
|
7
|
+
spec.version = "0.5.0"
|
8
8
|
spec.authors = ["Masahiro Sano"]
|
9
9
|
spec.email = ["sabottenda@gmail.com"]
|
10
10
|
spec.description = %q{A fluentd plugin to flatten nested hash structure as a flat record}
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.add_dependency "fluentd", ["
|
20
|
+
spec.add_dependency "fluentd", [">= 0.14.8", "< 2"]
|
21
21
|
spec.add_development_dependency "rake"
|
22
22
|
spec.add_development_dependency "test-unit"
|
23
23
|
end
|
@@ -1,13 +1,15 @@
|
|
1
|
-
|
1
|
+
require 'fluent/plugin/filter'
|
2
|
+
|
3
|
+
module Fluent::Plugin
|
2
4
|
class FlattenHashFilter < Filter
|
3
|
-
Plugin.register_filter('flatten_hash', self)
|
5
|
+
Fluent::Plugin.register_filter('flatten_hash', self)
|
4
6
|
|
5
7
|
require_relative 'flatten_hash_util'
|
6
|
-
include FlattenHashUtil
|
8
|
+
include Fluent::FlattenHashUtil
|
7
9
|
|
8
10
|
config_param :separator, :string, :default => '.'
|
9
11
|
config_param :flatten_array, :bool, :default => true
|
10
|
-
|
12
|
+
|
11
13
|
def configure(conf)
|
12
14
|
super
|
13
15
|
end
|
@@ -15,5 +17,5 @@ module Fluent
|
|
15
17
|
def filter(tag, time, record)
|
16
18
|
flatten_record(record, [])
|
17
19
|
end
|
18
|
-
end
|
20
|
+
end
|
19
21
|
end
|
@@ -1,10 +1,14 @@
|
|
1
|
-
|
1
|
+
require 'fluent/plugin/output'
|
2
|
+
|
3
|
+
module Fluent::Plugin
|
2
4
|
class FlattenHashOutput < Output
|
3
5
|
include Fluent::HandleTagNameMixin
|
4
6
|
Fluent::Plugin.register_output('flatten_hash', self)
|
5
7
|
|
8
|
+
helpers :event_emitter
|
9
|
+
|
6
10
|
require_relative 'flatten_hash_util'
|
7
|
-
include FlattenHashUtil
|
11
|
+
include Fluent::FlattenHashUtil
|
8
12
|
|
9
13
|
config_param :tag, :string, :default => nil
|
10
14
|
config_param :separator, :string, :default => '.'
|
@@ -21,11 +25,11 @@ module Fluent
|
|
21
25
|
!remove_tag_suffix &&
|
22
26
|
!add_tag_prefix &&
|
23
27
|
!add_tag_suffix )
|
24
|
-
raise ConfigError, "out_flatten_hash: No tag parameters are set"
|
28
|
+
raise Fluent::ConfigError, "out_flatten_hash: No tag parameters are set"
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
28
|
-
def
|
32
|
+
def process(tag, es)
|
29
33
|
tag = @tag || tag
|
30
34
|
es.each do |time, record|
|
31
35
|
record = flatten_record(record, [])
|
@@ -33,7 +37,6 @@ module Fluent
|
|
33
37
|
filter_record(t, time, record)
|
34
38
|
router.emit(t, time, record)
|
35
39
|
end
|
36
|
-
chain.next
|
37
40
|
end
|
38
41
|
end
|
39
42
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'helper'
|
2
|
+
require 'fluent/test/driver/filter'
|
2
3
|
require 'fluent/plugin/filter_flatten_hash'
|
3
4
|
|
4
5
|
class FlattenHashFlattenArrayFilterTest < Test::Unit::TestCase
|
5
|
-
include Fluent
|
6
6
|
|
7
7
|
BASE_CONFIG = %[
|
8
8
|
type flatten_hash
|
@@ -18,7 +18,7 @@ class FlattenHashFlattenArrayFilterTest < Test::Unit::TestCase
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def create_driver(conf = '')
|
21
|
-
Test::
|
21
|
+
Fluent::Test::Driver::Filter.new(Fluent::Plugin::FlattenHashFilter).configure(conf, syntax: :v1)
|
22
22
|
end
|
23
23
|
|
24
24
|
def test_flatten_record_flatten_array_false
|
@@ -26,13 +26,13 @@ class FlattenHashFlattenArrayFilterTest < Test::Unit::TestCase
|
|
26
26
|
es = Fluent::MultiEventStream.new
|
27
27
|
now = Fluent::Engine.now
|
28
28
|
|
29
|
-
d.run do
|
30
|
-
d.
|
31
|
-
d.
|
32
|
-
d.
|
33
|
-
d.
|
34
|
-
d.
|
35
|
-
d.
|
29
|
+
d.run(default_tag: 'test') do
|
30
|
+
d.feed({'message' => {'foo' => 'bar'}})
|
31
|
+
d.feed({"message" => {'foo' => 'bar', 'hoge' => 'fuga'}})
|
32
|
+
d.feed({"message" => {'nest' => {'foo' => 'bar'}}})
|
33
|
+
d.feed({"message" => {'nest' => {'nest' => {'foo' => 'bar'}}}})
|
34
|
+
d.feed({"message" => {'array' => ['foo', 'bar']}})
|
35
|
+
d.feed({"message" => {'array' => [{'foo' => 'bar'}, {'hoge' => 'fuga'}]}})
|
36
36
|
end
|
37
37
|
|
38
38
|
assert_equal [
|
@@ -42,6 +42,6 @@ class FlattenHashFlattenArrayFilterTest < Test::Unit::TestCase
|
|
42
42
|
{"message.nest.nest.foo" => "bar"},
|
43
43
|
{"message.array"=>["foo", "bar"]},
|
44
44
|
{"message.array"=>[{"foo"=>"bar"}, {"hoge"=>"fuga"}]},
|
45
|
-
], d.
|
45
|
+
], d.filtered.map{|x| x[1]}
|
46
46
|
end
|
47
47
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'helper'
|
2
|
+
require 'fluent/test/driver/filter'
|
2
3
|
require 'fluent/plugin/filter_flatten_hash'
|
3
4
|
|
4
5
|
class FlattenHashFilterTest < Test::Unit::TestCase
|
5
|
-
include Fluent
|
6
6
|
|
7
7
|
BASE_CONFIG = %[
|
8
8
|
type flatten_hash
|
@@ -17,7 +17,7 @@ class FlattenHashFilterTest < Test::Unit::TestCase
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def create_driver(conf = '')
|
20
|
-
Test::
|
20
|
+
Fluent::Test::Driver::Filter.new(Fluent::Plugin::FlattenHashFilter).configure(conf, syntax: :v1)
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_flatten_record
|
@@ -25,13 +25,13 @@ class FlattenHashFilterTest < Test::Unit::TestCase
|
|
25
25
|
es = Fluent::MultiEventStream.new
|
26
26
|
now = Fluent::Engine.now
|
27
27
|
|
28
|
-
d.run do
|
29
|
-
d.
|
30
|
-
d.
|
31
|
-
d.
|
32
|
-
d.
|
33
|
-
d.
|
34
|
-
d.
|
28
|
+
d.run(default_tag: 'test') do
|
29
|
+
d.feed({'message' => {'foo' => 'bar'}})
|
30
|
+
d.feed({"message" => {'foo' => 'bar', 'hoge' => 'fuga'}})
|
31
|
+
d.feed({"message" => {'nest' => {'foo' => 'bar'}}})
|
32
|
+
d.feed({"message" => {'nest' => {'nest' => {'foo' => 'bar'}}}})
|
33
|
+
d.feed({"message" => {'array' => ['foo', 'bar']}})
|
34
|
+
d.feed({"message" => {'array' => [{'foo' => 'bar'}, {'hoge' => 'fuga'}]}})
|
35
35
|
end
|
36
36
|
|
37
37
|
assert_equal [
|
@@ -41,17 +41,17 @@ class FlattenHashFilterTest < Test::Unit::TestCase
|
|
41
41
|
{"message.nest.nest.foo" => "bar"},
|
42
42
|
{"message.array.0" => "foo", "message.array.1" => "bar"},
|
43
43
|
{"message.array.0.foo" => "bar", "message.array.1.hoge" => "fuga"},
|
44
|
-
], d.
|
44
|
+
], d.filtered.map{|x| x[1]}
|
45
45
|
end
|
46
46
|
|
47
47
|
def test_separator
|
48
48
|
d = create_driver CONFIG + %[separator /]
|
49
49
|
|
50
|
-
d.run do
|
51
|
-
d.
|
50
|
+
d.run(default_tag: 'test') do
|
51
|
+
d.feed({"message" => {'nest' => {'foo' => 'bar'}}})
|
52
52
|
end
|
53
53
|
assert_equal [
|
54
54
|
{"message/nest/foo" => "bar"},
|
55
|
-
], d.
|
55
|
+
], d.filtered.map{|x| x[1]}
|
56
56
|
end
|
57
57
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'helper'
|
2
|
+
require 'fluent/test/driver/output'
|
2
3
|
require 'fluent/plugin/out_flatten_hash'
|
3
4
|
|
4
5
|
class FlattenHashOutputTest < Test::Unit::TestCase
|
@@ -13,8 +14,8 @@ class FlattenHashOutputTest < Test::Unit::TestCase
|
|
13
14
|
add_tag_prefix flattened
|
14
15
|
]
|
15
16
|
|
16
|
-
def create_driver(conf = CONFIG
|
17
|
-
Fluent::Test::
|
17
|
+
def create_driver(conf = CONFIG)
|
18
|
+
Fluent::Test::Driver::Output.new(Fluent::Plugin::FlattenHashOutput).configure(conf)
|
18
19
|
end
|
19
20
|
|
20
21
|
def test_configure
|
@@ -51,13 +52,13 @@ class FlattenHashOutputTest < Test::Unit::TestCase
|
|
51
52
|
def test_flatten_record
|
52
53
|
d = create_driver
|
53
54
|
|
54
|
-
d.run do
|
55
|
-
d.
|
56
|
-
d.
|
57
|
-
d.
|
58
|
-
d.
|
59
|
-
d.
|
60
|
-
d.
|
55
|
+
d.run(default_tag: 'test') do
|
56
|
+
d.feed({'message' => {'foo' => 'bar'}})
|
57
|
+
d.feed({"message" => {'foo' => 'bar', 'hoge' => 'fuga'}})
|
58
|
+
d.feed({"message" => {'nest' => {'foo' => 'bar'}}})
|
59
|
+
d.feed({"message" => {'nest' => {'nest' => {'foo' => 'bar'}}}})
|
60
|
+
d.feed({"message" => {'array' => ['foo', 'bar']}})
|
61
|
+
d.feed({"message" => {'array' => [{'foo' => 'bar'}, {'hoge' => 'fuga'}]}})
|
61
62
|
end
|
62
63
|
|
63
64
|
assert_equal [
|
@@ -67,53 +68,53 @@ class FlattenHashOutputTest < Test::Unit::TestCase
|
|
67
68
|
{"message.nest.nest.foo" => "bar"},
|
68
69
|
{"message.array.0" => "foo", "message.array.1" => "bar"},
|
69
70
|
{"message.array.0.foo" => "bar", "message.array.1.hoge" => "fuga"},
|
70
|
-
], d.
|
71
|
+
], d.events.map{|e| e[2]}
|
71
72
|
end
|
72
73
|
|
73
74
|
def test_separator
|
74
75
|
d = create_driver CONFIG + %[separator /]
|
75
76
|
|
76
|
-
d.run do
|
77
|
-
d.
|
77
|
+
d.run(default_tag: 'test') do
|
78
|
+
d.feed({"message" => {'nest' => {'foo' => 'bar'}}})
|
78
79
|
end
|
79
80
|
|
80
81
|
assert_equal [
|
81
82
|
{"message/nest/foo" => "bar"},
|
82
|
-
], d.
|
83
|
+
], d.events.map{|e| e[2]}
|
83
84
|
end
|
84
85
|
|
85
86
|
def test_emit_with_add_tag_prefix
|
86
87
|
d = create_driver BASE_CONFIG + %[
|
87
88
|
add_tag_prefix flattened.
|
88
89
|
]
|
89
|
-
d.run do
|
90
|
-
d.
|
91
|
-
d.
|
92
|
-
d.
|
90
|
+
d.run(default_tag: 'test') do
|
91
|
+
d.feed({'message' => {'foo' => 'bar'}})
|
92
|
+
d.feed({'message' => {'foo' => 'bar'}})
|
93
|
+
d.feed({'message' => {'foo' => 'bar'}})
|
93
94
|
end
|
94
|
-
|
95
|
-
|
95
|
+
events = d.events
|
96
|
+
events.each do |e|
|
96
97
|
assert_equal 'flattened.test', e[0]
|
97
98
|
assert_equal 'bar', e[2]["message.foo"]
|
98
99
|
end
|
99
|
-
assert_equal 3,
|
100
|
+
assert_equal 3, events.count
|
100
101
|
end
|
101
102
|
|
102
103
|
def test_emit_with_remove_tag_prefix
|
103
104
|
tag = 'prefix.prefix.test'
|
104
105
|
d = create_driver BASE_CONFIG + %[
|
105
106
|
remove_tag_prefix prefix.
|
106
|
-
]
|
107
|
-
d.run do
|
108
|
-
d.
|
109
|
-
d.
|
110
|
-
d.
|
107
|
+
]
|
108
|
+
d.run(default_tag: tag) do
|
109
|
+
d.feed({'message' => {'foo' => 'bar'}})
|
110
|
+
d.feed({'message' => {'foo' => 'bar'}})
|
111
|
+
d.feed({'message' => {'foo' => 'bar'}})
|
111
112
|
end
|
112
|
-
|
113
|
-
|
113
|
+
events = d.events
|
114
|
+
events.each do |e|
|
114
115
|
assert_equal 'prefix.test', e[0]
|
115
116
|
assert_equal 'bar', e[2]["message.foo"]
|
116
117
|
end
|
117
|
-
assert_equal 3,
|
118
|
+
assert_equal 3, events.count
|
118
119
|
end
|
119
120
|
end
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-flatten-hash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masahiro Sano
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.14.8
|
20
|
+
- - "<"
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
22
|
+
version: '2'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.14.8
|
30
|
+
- - "<"
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
32
|
+
version: '2'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: rake
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -93,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
99
|
version: '0'
|
94
100
|
requirements: []
|
95
101
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.
|
102
|
+
rubygems_version: 2.5.1
|
97
103
|
signing_key:
|
98
104
|
specification_version: 4
|
99
105
|
summary: A fluentd plugin to flatten nested hash structure as a flat record
|