fluent-plugin-add_empty_array 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 30ec5539884ad9010c521c18e264387f5bb89980
4
+ data.tar.gz: bb6f7a37359d21b953a687216b1c049c7d0e704b
5
+ SHA512:
6
+ metadata.gz: 51c90cfbe7d12db391117a32be84b66b375b39fb2f2a2faea2b25167a0dc7218e208635998bcc94455702aba4e177e6f59b1f17fdc5a81ebb79e446a959f110c
7
+ data.tar.gz: bc4629091ea9bfc08b885340602ccddc6e048514089da69a1f0ba5234a3b681d1b0c6390df04fb8cbb748b6c96def9bf04ceb28d6801b546b66cb1f06820931f
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ ## 0.0.1 (2015/03/04)
2
+ First release
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 h-michael-z
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,112 @@
1
+ ## Fluent::Plugin::AddEmptyArray, a plugin for [Fluentd](http://fluentd.org)
2
+
3
+ Fluentd plugin to add empty array.
4
+
5
+ ## Use case
6
+ When using Google Bigquery with schema include "repeated" mode columns and insert record without "repeated" mode columns key, failed insert.
7
+ So this plugin support this case according to add such keys complement with "[]".
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'fluent-plugin-add_empty_array'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install fluent-plugin-add_empty_array
24
+
25
+ ## Usage
26
+
27
+ default usage
28
+ ```
29
+ <match test>
30
+ type add_empty_array
31
+ array_type_key test3,test4
32
+ </match>
33
+
34
+ input
35
+ "test" {
36
+ "test1": "foo",
37
+ "test2": "bar"
38
+ }
39
+
40
+ output
41
+ "add_empty_array.test" {
42
+ "test1": "foo",
43
+ "test2": "bar",
44
+ "test3": [],
45
+ "test4": []
46
+ }
47
+ ```
48
+
49
+ change tag prefix (default tag prefix is "add_empty_array.")
50
+ ```
51
+ <match test>
52
+ type add_empty_array
53
+ array_type_key test3,test4
54
+ tag_prefix prefix_test.
55
+ </match>
56
+
57
+ input
58
+ "test" {
59
+ "test1": "foo",
60
+ "test2": "bar"
61
+ }
62
+
63
+ output
64
+ "prefix_test.test" {
65
+ "test1": "foo",
66
+ "test2": "bar",
67
+ "test3": [],
68
+ "test4": []
69
+ }
70
+ ```
71
+
72
+ ## Option Parameters
73
+
74
+ ### array_type_key :keys delimited by commas
75
+ array_type_key points to keys which you want complement with "[]" if there are no those keys.
76
+ You should set value to array_type_key like this.
77
+ Default value is 'nil'.
78
+ Require option.
79
+
80
+ ```
81
+ array_type_key foo
82
+ ```
83
+ ```
84
+ array_type_key foo,bar,baz
85
+ ```
86
+
87
+ If you use this plugin with key include commas, you must use delimiter option like this.
88
+ This example, use '.' as delimiter.
89
+
90
+ ```
91
+ type add_empty_array
92
+ array_type_key test,3.test,4
93
+ delimiter .
94
+ ```
95
+
96
+ ### delimiter :String
97
+ Default value is ','.
98
+
99
+ ### tag_prefix :String
100
+ Added tag prefix.
101
+ Default value is "parsed."
102
+
103
+ ## Change log
104
+ See [CHANGELOG.md](https://github.com/h-michael-z/fluent-plugin-add_empty_array/blob/master/CHANGELOG.md) for details.
105
+
106
+ ## Contributing
107
+
108
+ 1. Fork it ( https://github.com/h-michael-z/fluent-plugin-add_empty_array/fork )
109
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
110
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
111
+ 4. Push to the branch (`git push origin my-new-feature`)
112
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:test) do |test|
6
+ test.libs << 'lib' << 'test'
7
+ test.pattern = 'test/**/test_*.rb'
8
+ test.verbose = true
9
+ end
@@ -0,0 +1,30 @@
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+ require 'fluent/plugin/add_empty_array/version'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "fluent-plugin-add_empty_array"
6
+ spec.version = Fluent::ParseCookie::VERSION
7
+ spec.authors = ["Hirokazu Hata"]
8
+ spec.email = ["h.hata.ai.t@gmail.com"]
9
+ spec.summary = %q{Fluentd plugin to add empty array}
10
+ spec.description = %q{
11
+ We can't add record has nil value which target repeated mode column to google bigquery.
12
+ So this plugin add empty array if record has nil value or don't have key and value which target repeated mode column.
13
+ }
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "fluentd"
23
+ spec.add_development_dependency "bundler"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "pry"
26
+ spec.add_development_dependency "pry-byebug"
27
+ spec.add_development_dependency "pry-nav"
28
+ spec.add_development_dependency "test-unit"
29
+ spec.add_development_dependency "timecop"
30
+ end
@@ -0,0 +1,5 @@
1
+ module Fluent
2
+ module ParseCookie
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,60 @@
1
+ module Fluent
2
+ class AddEmptyArrayOutput < Output
3
+ Fluent::Plugin.register_output('add_empty_array', self)
4
+ config_param :array_type_key, :string, :default => nil
5
+ config_param :delimiter, :string, :default => ','
6
+ config_param :tag_prefix, :string, :default => 'add_empty_array.'
7
+
8
+ def initialize
9
+ super
10
+ end
11
+
12
+ # Define `log` method for v0.10.42 or earlier
13
+ unless method_defined?(:log)
14
+ define_method("log") { $log }
15
+ end
16
+
17
+ def configure(conf)
18
+ super
19
+
20
+ if @array_type_key
21
+ @array_type_key = @array_type_key.split(@delimiter)
22
+ end
23
+
24
+ unless @array_type_key
25
+ raise ConfigError, "'array_type_key' parameter is required on 'fluent-plugin-add_empty_array'"
26
+ end
27
+ end
28
+
29
+ def start
30
+ super
31
+ end
32
+
33
+ def shutdown
34
+ super
35
+ end
36
+
37
+ def emit(tag, es, chain)
38
+ es.each {|time, record|
39
+ t = tag.dup
40
+ new_record = add_empty_array(record)
41
+
42
+ t = @tag_prefix + t unless @tag_prefix.nil?
43
+
44
+ Engine.emit(t, time, new_record)
45
+ }
46
+ chain.next
47
+ rescue => e
48
+ log.warn("out_add_empty_array: error_class:#{e.class} error_message:#{e.message} tag:#{tag} es:#{es} record:#{record} bactrace:#{e.backtrace.first}")
49
+ end
50
+
51
+ def add_empty_array(record)
52
+ @array_type_key.each do |key|
53
+ record[key] = [] unless record.has_key?(key)
54
+ end
55
+ return record
56
+ rescue => e
57
+ log.warn("out_add_empty_array: error_class:#{e.class} error_message:#{e.message} tag:#{tag} record:#{record} bactrace:#{e.backtrace.first}")
58
+ end
59
+ end
60
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+
12
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+ require 'fluent/test'
15
+ unless ENV.has_key?('VERBOSE')
16
+ nulllogger = Object.new
17
+ nulllogger.instance_eval {|obj|
18
+ def method_missing(method, *args)
19
+ # pass
20
+ end
21
+ }
22
+ $log = nulllogger
23
+ end
24
+
25
+ require 'fluent/plugin/out_add_empty_array'
26
+
27
+ class Test::Unit::TestCase
28
+ end
@@ -0,0 +1,109 @@
1
+ require 'helper'
2
+ require 'pry-byebug'
3
+ require 'timecop'
4
+ require 'fluent/plugin/out_add_empty_array'
5
+
6
+ class AddEmptyArrayOutputTest < Test::Unit::TestCase
7
+
8
+ TEST_RECORD = {
9
+ "abc" => "edf",
10
+ "123" => "456"
11
+ }
12
+
13
+ def setup
14
+ Fluent::Test.setup
15
+ Timecop.freeze(@time)
16
+ end
17
+
18
+ def create_driver(conf, tag)
19
+ Fluent::Test::OutputTestDriver.new(
20
+ Fluent::AddEmptyArrayOutput, tag
21
+ ).configure(conf)
22
+ end
23
+
24
+ def emit(conf, record, tag='test')
25
+ d = create_driver(conf, tag)
26
+ d.run {d.emit(record)}
27
+ emits = d.emits
28
+ end
29
+
30
+ def test_configure_default_tag_prefix
31
+ d = create_driver(%[array_type_key a,b,c,1,2,3], "test")
32
+ assert_equal ["a", "b", "c" , "1" , "2" , "3"], d.instance.array_type_key
33
+ assert_equal 'add_empty_array.', d.instance.tag_prefix
34
+ end
35
+
36
+ def test_configure_array_type_key_eq_nil
37
+ assert_raise(Fluent::ConfigError) do
38
+ create_driver(%[], "test")
39
+ end
40
+ end
41
+
42
+ def test_configure
43
+ d = create_driver(%[
44
+ array_type_key a.b.c.1.2.3
45
+ delimiter .
46
+ tag_prefix michael.
47
+ ], "test")
48
+
49
+ assert_equal ["a", "b", "c" , "1" , "2" , "3"], d.instance.array_type_key
50
+ assert_equal '.', d.instance.delimiter
51
+ assert_equal 'michael.', d.instance.tag_prefix
52
+ end
53
+
54
+ def test_add_empty_array
55
+ conf = %[
56
+ array_type_key test_array
57
+ ]
58
+
59
+ record = TEST_RECORD
60
+
61
+ emits = emit(conf, record)
62
+
63
+ emits.each_with_index do |(tag, time, record), i|
64
+ assert_equal 'add_empty_array.test', tag
65
+ assert_equal 'edf', record['abc']
66
+ assert_equal '456', record['123']
67
+ assert_equal [], record['test_array']
68
+ end
69
+ end
70
+
71
+ def test_add_empty_array_with_multiple_keys
72
+ conf = %[
73
+ array_type_key test_array1,test_array2,test_array3
74
+ ]
75
+
76
+ record = TEST_RECORD
77
+
78
+ emits = emit(conf, record)
79
+
80
+ emits.each_with_index do |(tag, time, record), i|
81
+ assert_equal 'add_empty_array.test', tag
82
+ assert_equal 'edf', record['abc']
83
+ assert_equal '456', record['123']
84
+ assert_equal [], record['test_array1']
85
+ assert_equal [], record['test_array2']
86
+ assert_equal [], record['test_array3']
87
+ end
88
+ end
89
+
90
+ def test_add_empty_array_with_delimiter
91
+ conf = %[
92
+ array_type_key test_array1.test_array2.test_array3
93
+ delimiter .
94
+ ]
95
+
96
+ record = TEST_RECORD
97
+
98
+ emits = emit(conf, record)
99
+
100
+ emits.each_with_index do |(tag, time, record), i|
101
+ assert_equal 'add_empty_array.test', tag
102
+ assert_equal 'edf', record['abc']
103
+ assert_equal '456', record['123']
104
+ assert_equal [], record['test_array1']
105
+ assert_equal [], record['test_array2']
106
+ assert_equal [], record['test_array3']
107
+ end
108
+ end
109
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-add_empty_array
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Hirokazu Hata
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-nav
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: test-unit
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: timecop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: "\n We can't add record has nil value which
126
+ target repeated mode column to google bigquery.\n So
127
+ this plugin add empty array if record has nil value or don't have key and value
128
+ which target repeated mode column.\n "
129
+ email:
130
+ - h.hata.ai.t@gmail.com
131
+ executables: []
132
+ extensions: []
133
+ extra_rdoc_files: []
134
+ files:
135
+ - ".gitignore"
136
+ - CHANGELOG.md
137
+ - Gemfile
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - fluent-plugin-add_empty_array.gemspec
142
+ - lib/fluent/plugin/add_empty_array/version.rb
143
+ - lib/fluent/plugin/out_add_empty_array.rb
144
+ - test/helper.rb
145
+ - test/plugin/test_add_empty_array.rb
146
+ homepage: ''
147
+ licenses:
148
+ - MIT
149
+ metadata: {}
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 2.2.2
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: Fluentd plugin to add empty array
170
+ test_files:
171
+ - test/helper.rb
172
+ - test/plugin/test_add_empty_array.rb
173
+ has_rdoc: