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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 44fed39bc14936c3c382922850cf38ce9f88b0ab
4
- data.tar.gz: 4d596b67719906871a23265501742fd4e5fdf1b1
3
+ metadata.gz: 5f89bacd8f75c114993634731bce29093a182fe7
4
+ data.tar.gz: 58defd52ece87e48bfeffa339591a10d79b256d8
5
5
  SHA512:
6
- metadata.gz: 212995f7b1bc5c5e9d44b4f52d192151b862ce6cf0d5514bf682f7834774d1c540e1f07b960fa169355a41de8462da9c902e1deef777881d62eb010cf4162f8a
7
- data.tar.gz: 42d74c0a6f831607c0e73636d1973f7975077c8f54776bc5b942bf8d9a308c91c4d8d2797d5982de37aba0069469e2519c5a9f5209e54381a68a943e7d2e1dac
6
+ metadata.gz: 4c13ccffa9ee50538ce8ac06448e2f5f1cb56b7d413d254964dd17ee6f42984e5038741230eee8e282a3ac90012d1973866df291442f01d084e41dc927e8a283
7
+ data.tar.gz: a10848bb4ec3b8e4ee37a90634a7b1e7e05255110c952210edd59ec0127e1ac21f351b58ef4c9aec153a8b70e4b56f3c7870407203caa6012c90bfb6501694ab
data/.gitignore CHANGED
@@ -8,6 +8,7 @@ InstalledFiles
8
8
  _yardoc
9
9
  coverage
10
10
  doc/
11
+ gemfiles/*.lock
11
12
  lib/bundler/man
12
13
  pkg
13
14
  rdoc
@@ -0,0 +1,13 @@
1
+ sudo: false
2
+ language: ruby
3
+
4
+ rvm:
5
+ - 2.1.10
6
+ - 2.2.5
7
+ - 2.3.1
8
+
9
+ gemfile:
10
+ - gemfiles/fluentd_v0.14.gemfile
11
+
12
+ script:
13
+ - bundle exec rake test
@@ -0,0 +1,3 @@
1
+ appraise "fluentd v0.14" do
2
+ gem "fluentd", "~> 0.14.0"
3
+ end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'fluent-plugin-flatten'
3
- gem.version = '0.0.10'
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.1.0'
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
-
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "fluentd", "~> 0.14.0"
6
+
7
+ gemspec :path => "../"
@@ -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
- # Define `router` method of v0.12 to support v0.10 or earlier
11
- unless method_defined?(:router)
12
- define_method("router") { Fluent::Engine }
13
- end
10
+ helpers :event_emitter
14
11
 
15
- config_param :key, :string,
16
- :desc => <<-DESC
17
- The key is used to point a key whose value contains JSON-formatted string.
18
- DESC
19
- config_param :inner_key, :string, :default => 'value',
20
- :desc => <<-DESC
21
- This plugin sets `value` for this option as a default if it's not set.
22
- DESC
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 emit(tag, es, chain)
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, tag = 'test')
15
- Fluent::Test::OutputTestDriver.new(Fluent::FlattenOutput, tag).configure(conf)
14
+ def create_driver(conf = DEFAULT_CONFIG)
15
+ Fluent::Test::Driver::Output.new(Fluent::Plugin::FlattenOutput).configure(conf)
16
16
  end
17
17
 
18
- def test_configure
19
- # when `inner_key` option is not set
20
- d1 = create_driver
21
-
22
- assert_equal 'foo', d1.instance.key
23
- assert_equal 'flattened.', d1.instance.add_tag_prefix
24
- assert_equal /^test\./, d1.instance.remove_tag_prefix
25
- assert_equal 'value', d1.instance.inner_key # default value
26
-
27
- # when `inner_key` is set
28
- d2 = create_driver(%[
29
- key foo
30
- add_tag_prefix flattened.
31
- remove_tag_prefix test.
32
- inner_key value_for_flat_key
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
- def test_flatten
65
- d = create_driver
68
+ sub_test_case "flatten" do
69
+ test "plain" do
70
+ d = create_driver
66
71
 
67
- flattened = d.instance.flatten({ 'foo' => '{"bar" : "baz"}', 'hoge' => 'fuga' })
68
- assert_equal({ 'foo.bar' => { 'value' => 'baz' } }, flattened)
72
+ flattened = d.instance.flatten({ 'foo' => '{"bar" : "baz"}', 'hoge' => 'fuga' })
73
+ assert_equal({ 'foo.bar' => { 'value' => 'baz' } }, flattened)
74
+ end
69
75
 
70
- # XXX work-around
71
- # fluentd seems to escape json value excessively
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
- # when empty value is passed
76
- flattened = d.instance.flatten({ 'foo' => '' })
77
- assert_equal({}, flattened)
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
- # when invalid json value is passed
80
- flattened = d.instance.flatten({ 'foo' => '-' })
81
- assert_equal({}, flattened)
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
- def test_emit
85
- # test1 default config
86
- d1 = create_driver
98
+ sub_test_case "emit" do
99
+ test "default config" do
100
+ # test1 default config
101
+ d = create_driver
87
102
 
88
- d1.run do
89
- d1.emit( 'foo' => '{"bar" : "baz"}', 'hoge' => 'fuga' )
90
- d1.emit( 'foo' => '{"bar" : {"qux" : "quux", "hoe" : "poe" }, "baz" : "bazz" }', 'hoge' => 'fuga' )
91
- end
92
- emits1 = d1.emits
93
-
94
- assert_equal 4, emits1.count
95
-
96
- # ["flattened.foo.bar", 1354689632, {"value"=>"baz"}]
97
- assert_equal 'flattened.foo.bar', emits1[0][0]
98
- assert_equal 'baz', emits1[0][2]['value']
99
-
100
- # ["flattened.foo.bar.qux", 1354689632, {"value"=>"quux"}]
101
- assert_equal 'flattened.foo.bar.qux', emits1[1][0]
102
- assert_equal 'quux', emits1[1][2]['value']
103
-
104
- # ["flattened.foo.bar.hoe", 1354689632, {"value"=>"poe"}]
105
- assert_equal 'flattened.foo.bar.hoe', emits1[2][0]
106
- assert_equal 'poe', emits1[2][2]['value']
107
-
108
- # ["flattened.foo.bar.baz", 1354689632, {"value"=>"bazz"}]
109
- assert_equal 'flattened.foo.baz', emits1[3][0]
110
- assert_equal 'bazz', emits1[3][2]['value']
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
- assert_equal 6, emits2.count
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
- # ["flattened.foo.bar", 1354689632, {"value"=>"baz"}]
131
- assert_equal 'flattened.foo.bar', emits2[0][0]
132
- assert_equal 'baz', emits2[0][2]['value']
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
- # ["flattened.foo.bar.qux_qux", 1354689632, {"value"=>"quux"}]
135
- assert_equal 'flattened.foo.bar.qux', emits2[1][0]
136
- assert_equal 'quux', emits2[1][2]['value']
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
- # ["flattened.foo.bar.hoe", 1354689632, {"value"=>"poe"}]
139
- assert_equal 'flattened.foo.bar.hoe', emits2[2][0]
140
- assert_equal 'poe', emits2[2][2]['value']
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
- # ["flattened.foo.bar.baz", 1354689632, {"value"=>"bazz"}]
143
- assert_equal 'flattened.foo.baz', emits2[3][0]
144
- assert_equal 'bazz', emits2[3][2]['value']
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
- # ["flattened.foo.bar_hoge", 1354689632, {"value"=>"baz"}]
147
- assert_equal 'flattened.foo.bar_hoge', emits2[4][0]
148
- assert_equal 'baz', emits2[4][2]['value']
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
- # ["flattened.foo.hoe_baz", 1354689632, {"value"=>"baz"}]
151
- assert_equal 'flattened.foo.hoe_baz', emits2[5][0]
152
- assert_equal 'poe', emits2[5][2]['value']
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
@@ -1,32 +1,9 @@
1
- require 'rubygems'
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(File.dirname(__FILE__), '..', 'lib'))
15
- $LOAD_PATH.unshift(File.dirname(__FILE__))
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.10
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-07-05 00:00:00.000000000 Z
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.1.0
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.1.0
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: '0'
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: '0'
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