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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b43a1bd48124ebae2cdfda2410712b64d997392
4
- data.tar.gz: dc2a4abef6d63a83aaf219fc3e8954b7c710d101
3
+ metadata.gz: fc9aa975dd6c6a5ae056a1ade23882751d3cb9a7
4
+ data.tar.gz: b076a3184513e59221f1dd2dcc8ead6099052406
5
5
  SHA512:
6
- metadata.gz: debb2ff1e583180759ffc8a2919f271dfc602cc461a9ed5d18b105490aa2c791dfbe262ea024495599250e215efd34125d6afd69b7e621c9ef4d6d08c1dbabd1
7
- data.tar.gz: d271c774d81be375b0e6c0c43b4ef528cc5cb26910f928b757f0d21f95e8e86decd9518c0e665f4ec920ecaceb7491fa38ec3f7922a5768618895b6e8fc11f99
6
+ metadata.gz: 580e9e5392a343865bf8849cceaca44d67fb6eea4ecc805d6f4b0cfc5d305cd09446808e3a5bb37d55bc5f770af5c3459b42fc7651cbace91690a5ae1d2bbbac
7
+ data.tar.gz: f194a77a00a8473921ae3465dd7e7505829814c29438cf511dc7c230405a04f68a679e3b3df6fb60c27e571be4c740022780d8943db8fc707279526a88c658ad
@@ -3,6 +3,7 @@ language: ruby
3
3
  rvm:
4
4
  - 2.1
5
5
  - 2.2
6
+ - 2.3.1
6
7
 
7
8
  script:
8
9
  - bundle exec rake test
@@ -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.4.1"
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", ["~> 0.12.0"]
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
- module Fluent
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 if defined?(Filter)
20
+ end
19
21
  end
@@ -1,10 +1,14 @@
1
- module Fluent
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 emit(tag, es, chain)
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::FilterTestDriver.new(FlattenHashFilter).configure(conf, true)
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.emit({'message' => {'foo' => 'bar'}})
31
- d.emit({"message" => {'foo' => 'bar', 'hoge' => 'fuga'}})
32
- d.emit({"message" => {'nest' => {'foo' => 'bar'}}})
33
- d.emit({"message" => {'nest' => {'nest' => {'foo' => 'bar'}}}})
34
- d.emit({"message" => {'array' => ['foo', 'bar']}})
35
- d.emit({"message" => {'array' => [{'foo' => 'bar'}, {'hoge' => 'fuga'}]}})
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.filtered_as_array.map{|x| x[2]}
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::FilterTestDriver.new(FlattenHashFilter).configure(conf, true)
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.emit({'message' => {'foo' => 'bar'}})
30
- d.emit({"message" => {'foo' => 'bar', 'hoge' => 'fuga'}})
31
- d.emit({"message" => {'nest' => {'foo' => 'bar'}}})
32
- d.emit({"message" => {'nest' => {'nest' => {'foo' => 'bar'}}}})
33
- d.emit({"message" => {'array' => ['foo', 'bar']}})
34
- d.emit({"message" => {'array' => [{'foo' => 'bar'}, {'hoge' => 'fuga'}]}})
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.filtered_as_array.map{|x| x[2]}
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.emit({"message" => {'nest' => {'foo' => 'bar'}}})
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.filtered_as_array.map{|x| x[2]}
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, tag='test')
17
- Fluent::Test::OutputTestDriver.new(Fluent::FlattenHashOutput, tag).configure(conf)
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.emit({'message' => {'foo' => 'bar'}})
56
- d.emit({"message" => {'foo' => 'bar', 'hoge' => 'fuga'}})
57
- d.emit({"message" => {'nest' => {'foo' => 'bar'}}})
58
- d.emit({"message" => {'nest' => {'nest' => {'foo' => 'bar'}}}})
59
- d.emit({"message" => {'array' => ['foo', 'bar']}})
60
- d.emit({"message" => {'array' => [{'foo' => 'bar'}, {'hoge' => 'fuga'}]}})
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.records
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.emit({"message" => {'nest' => {'foo' => 'bar'}}})
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.records
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.emit({'message' => {'foo' => 'bar'}})
91
- d.emit({'message' => {'foo' => 'bar'}})
92
- d.emit({'message' => {'foo' => 'bar'}})
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
- emits = d.emits
95
- emits.each do |e|
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, emits.count
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
- ], tag
107
- d.run do
108
- d.emit({'message' => {'foo' => 'bar'}})
109
- d.emit({'message' => {'foo' => 'bar'}})
110
- d.emit({'message' => {'foo' => 'bar'}})
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
- emits = d.emits
113
- emits.each do |e|
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, emits.count
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.1
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-12 00:00:00.000000000 Z
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: 0.12.0
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: 0.12.0
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.4.5
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