fluent-plugin-parse_multiple_value_query 1.0.0 → 2.0.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
  SHA256:
3
- metadata.gz: 777fb2b20859695a9110bc3712300ba10ec7762db895f9bc24e26ea4e4d21300
4
- data.tar.gz: 3e116c03893bb58809d0714017aa6e325a4aa591be06f020e88a5f55fec33c6f
3
+ metadata.gz: 1caa0fa710443594e6a2385bb30a422e85cb4305af1cc115bff9d6e53311261e
4
+ data.tar.gz: 1fb5ee77848f0f8d40bc5ab270680a5616df4ba2a630b504843fda823d988c03
5
5
  SHA512:
6
- metadata.gz: d49c2ab0eaf6746e0219ae15004188ac80ca43e539f58c9ffb5075734e40c24e42cf20a4d9e4870e03b86fb7af1f743c167a726e0544a5af3e1feee3b588f865
7
- data.tar.gz: aacc95d2384d51f78867043dff540c7a647d4aa201007f89c0563aa696131909001417e42e6686c22b144f0593fe415e9af8769c4aebf62df36f2a74ed395ed3
6
+ metadata.gz: b8a05d553c8dc5c8ab2f5d4b71423e4cf4a97fcbc824db6c3edb84a569a4efb64d0933f20f9b5a97f527973e44c387e53ac5a521c6ec9738af6ed466fb1bc6eb
7
+ data.tar.gz: 74f4abf2d266de1d074d2249e1fe6c660fe4c2da565559da838408ce022f77f53898ed8bea5d5714992d439f3017ebb7337f7ba70c22711d2452fb628072efa6
data/README.md CHANGED
@@ -19,6 +19,12 @@ output
19
19
  "key3": [""]
20
20
  }
21
21
  ```
22
+ ## Requirements
23
+
24
+ | fluent-plugin-parse_multiple_value_query | Fluentd | Ruby |
25
+ |---------------------------|-------------|--------|
26
+ | >= 2.0.0 | >= v0.14.0 | >= 2.1 |
27
+ | < 2.0.0 | >= v0.12.0 | >= 1.9 |
22
28
 
23
29
  ## Installation
24
30
 
@@ -16,12 +16,11 @@ Gem::Specification.new do |spec|
16
16
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
17
  spec.require_paths = ['lib']
18
18
 
19
- spec.add_dependency 'fluentd', '~> 0.12.0'
19
+ spec.add_dependency 'fluentd', ['>= 0.14.0', '< 2']
20
20
  spec.add_dependency 'rack', '>= 1.6.11'
21
21
  spec.add_development_dependency 'bundler'
22
22
  spec.add_development_dependency 'pry'
23
23
  spec.add_development_dependency 'pry-byebug'
24
- spec.add_development_dependency 'pry-nav'
25
24
  spec.add_development_dependency 'rake'
26
25
  spec.add_development_dependency 'rr'
27
26
  spec.add_development_dependency 'rubocop'
@@ -1,5 +1,7 @@
1
- module Fluent
2
- class ParseMultipleValueQueryOutput < Output
1
+ require 'fluent/plugin/output'
2
+
3
+ module Fluent::Plugin
4
+ class ParseMultipleValueQueryOutput < Fluent::Plugin::Output
3
5
  Fluent::Plugin.register_output('parse_multiple_value_query', self)
4
6
 
5
7
  config_param :key, :string
@@ -9,6 +11,8 @@ module Fluent
9
11
  config_param :sub_key, :string, default: nil
10
12
  config_param :without_host, :bool, default: false
11
13
 
14
+ helpers :event_emitter
15
+
12
16
  def initialize
13
17
  super
14
18
  require 'rack'
@@ -29,14 +33,18 @@ module Fluent
29
33
  super
30
34
  end
31
35
 
32
- def emit(tag, es, chain)
36
+ def multi_workers_ready?
37
+ true
38
+ end
39
+
40
+ def process(tag, es)
33
41
  es.each do |time, record|
34
42
  t = tag.dup
35
43
  new_record = parse_uri(record)
36
44
 
37
45
  t = @tag_prefix + t unless @tag_prefix.nil?
38
46
 
39
- Engine.emit(t, time, new_record)
47
+ router.emit(t, time, new_record)
40
48
  end
41
49
  chain.next
42
50
  rescue StandardError => e
@@ -1,5 +1,5 @@
1
1
  module Fluent
2
2
  module ParseMultipleValueQuery
3
- VERSION = '1.0.0'.freeze
3
+ VERSION = '2.0.0'.freeze
4
4
  end
5
5
  end
@@ -1,28 +1,5 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- warn e.message
7
- warn '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.key?('VERBOSE')
16
- nulllogger = Object.new
17
- nulllogger.instance_eval do |_obj|
18
- def method_missing(method, *args)
19
- # pass
20
- end
21
- end
22
- $log = nulllogger
23
- end
24
-
25
- require 'fluent/plugin/out_parse_multiple_value_query'
26
-
27
- class Test::Unit::TestCase
28
- end
1
+ require "bundler/setup"
2
+ require "test/unit"
3
+ $LOAD_PATH.unshift(File.join(__dir__, "..", "lib"))
4
+ $LOAD_PATH.unshift(__dir__)
5
+ require "fluent/test"
@@ -1,184 +1,178 @@
1
1
  require 'helper'
2
2
  require 'rr'
3
+ require 'pry-byebug'
3
4
  require 'fluent/plugin/out_parse_multiple_value_query'
5
+ require 'fluent/test/driver/output'
6
+ require 'fluent/test/helpers'
7
+
8
+ class ParseMultipleValueQueryOutputTest < Test::Unit::TestCase
9
+ include Fluent::Test::Helpers
4
10
 
5
- class ParseMultipleValueQueryOutTest < Test::Unit::TestCase
6
11
  URL = 'http://example.com:80/?foo=bar&baz=qux&multiple[]=1&multiple[]=2&multiple[]=3&multiple2[]='.freeze
7
12
  URL_INCLUDE_JP = 'http://example.com:80/?foo=bar&baz=qux&%E3%81%BE%E3%81%84%E3%81%91%E3%82%8B%5B%5D=%E3%82%AD%E3%82%B9%E3%82%AF&%E3%81%BE%E3%81%84%E3%81%91%E3%82%8B%5B%5D=%E3%82%B7%E3%82%A7%E3%83%B3%E3%82%AB%E3%83%BC&%E3%81%BE%E3%81%84%E3%81%91%E3%82%8B%5B%5D=%E3%82%B8%E3%83%A3%E3%82%AF%E3%82%BD%E3%83%B3'.freeze
8
13
  ONLY_QUERY_STRING_TEST = 'foo=bar&baz=qux&multiple[]=1&multiple[]=2&multiple[]=3&%E3%81%BE%E3%81%84%E3%81%91%E3%82%8B%5B%5D=%E3%82%AD%E3%82%B9%E3%82%AF&%E3%81%BE%E3%81%84%E3%81%91%E3%82%8B%5B%5D=%E3%82%B7%E3%82%A7%E3%83%B3%E3%82%AB%E3%83%BC&%E3%81%BE%E3%81%84%E3%81%91%E3%82%8B%5B%5D=%E3%82%B8%E3%83%A3%E3%82%AF%E3%82%BD%E3%83%B3'.freeze
9
14
  REMOVE_EMPTY_KEY = 'http://example.com:80/?foo=bar&baz=qux&multiple[]=&%E3%81%BE%E3%81%84%E3%81%91%E3%82%8B%5B%5D=%E3%82%AD%E3%82%B9%E3%82%AF&%E3%81%BE%E3%81%84%E3%81%91%E3%82%8B%5B%5D=%E3%82%B7%E3%82%A7%E3%83%B3%E3%82%AB%E3%83%BC&%E3%81%BE%E3%81%84%E3%81%91%E3%82%8B%5B%5D=%E3%82%B8%E3%83%A3%E3%82%AF%E3%82%BD%E3%83%B3&multiple2[]'.freeze
10
15
  WITHOUT_HOST = '/test/url?foo=bar&baz=qux&multiple[]=1&multiple[]=2&multiple[]=3&multiple2[]='.freeze
11
16
 
12
- def setup
13
- Fluent::Test.setup
14
- end
15
-
16
- def create_driver(conf, tag)
17
- Fluent::Test::OutputTestDriver.new(
18
- Fluent::ParseMultipleValueQueryOutput, tag
19
- ).configure(conf)
20
- end
21
-
22
- def emit(conf, record, tag = 'test')
23
- d = create_driver(conf, tag)
24
- d.run { d.emit(record) }
25
- d.emits
17
+ def create_driver(conf)
18
+ Fluent::Test::Driver::Output.new(Fluent::Plugin::ParseMultipleValueQueryOutput).configure(conf)
26
19
  end
27
20
 
28
- def test_configure
29
- d = create_driver(%(
30
- key url
31
- only_query_string true
32
- ), 'test')
33
-
34
- assert_equal 'url', d.instance.key
35
- assert_equal true, d.instance.only_query_string
21
+ def setup
22
+ Fluent::Test.setup
36
23
  end
37
24
 
38
- def test_filter_record
39
- conf = %(
40
- key url
41
- )
42
-
43
- record = {
44
- 'url' => URL
45
- }
46
-
47
- emits = emit(conf, record)
25
+ sub_test_case 'configure' do
26
+ test 'configure' do
27
+ d = create_driver(%(
28
+ key url
29
+ only_query_string true
30
+ ))
48
31
 
49
- emits.each_with_index do |(tag, _time, emit_record), _i|
50
- assert_equal 'parsed.test', tag
51
- assert_equal URL, emit_record['url']
52
- assert_equal 'bar', emit_record['foo']
53
- assert_equal 'qux', emit_record['baz']
54
- assert_equal %w[1 2 3], emit_record['multiple']
55
- assert_equal [''], emit_record['multiple2']
32
+ assert_equal 'url', d.instance.key
33
+ assert_equal true, d.instance.only_query_string
56
34
  end
57
35
  end
58
36
 
59
- def test_jp_filter_record
60
- conf = %(
61
- key url
62
- )
63
-
64
- record = {
65
- 'url' => URL_INCLUDE_JP
66
- }
67
-
68
- emits = emit(conf, record)
69
-
70
- emits.each_with_index do |(tag, _time, emit_record), _i|
71
- assert_equal 'parsed.test', tag
72
- assert_equal URL_INCLUDE_JP, emit_record['url']
73
- assert_equal 'bar', emit_record['foo']
74
- assert_equal 'qux', emit_record['baz']
75
- assert_equal %w[キスク シェンカー ジャクソン], emit_record['まいける']
37
+ sub_test_case 'emit events' do
38
+ test 'filter record' do
39
+ d = create_driver(%(
40
+ key url
41
+ ))
42
+ time = event_time
43
+
44
+ d.run(default_tag: 'test') do
45
+ d.feed(time, { 'url' => URL })
46
+ end
47
+ events = d.events
48
+ event = events.first
49
+
50
+ assert_equal 'parsed.test', event.first
51
+ assert_equal URL, event[2]['url']
52
+ assert_equal 'bar', event[2]['foo']
53
+ assert_equal 'qux', event[2]['baz']
54
+ assert_equal %w[1 2 3], event[2]['multiple']
55
+ assert_equal [''], event[2]['multiple2']
76
56
  end
77
- end
78
57
 
79
- def test_only_query_string_filter_record
80
- conf = %(
81
- key query_string
82
- only_query_string true
83
- )
84
-
85
- record = {
86
- 'query_string' => ONLY_QUERY_STRING_TEST
87
- }
88
-
89
- emits = emit(conf, record)
90
-
91
- emits.each_with_index do |(tag, _time, emit_record), _i|
92
- assert_equal 'parsed.test', tag
93
- assert_equal ONLY_QUERY_STRING_TEST, emit_record['query_string']
94
- assert_equal 'bar', emit_record['foo']
95
- assert_equal 'qux', emit_record['baz']
96
- assert_equal %w[1 2 3], emit_record['multiple']
97
- assert_equal %w[キスク シェンカー ジャクソン], emit_record['まいける']
58
+ test 'jp filter record' do
59
+ d = create_driver(%(
60
+ key url
61
+ ))
62
+ time = event_time
63
+
64
+ d.run(default_tag: 'test') do
65
+ d.feed(time, { 'url' => URL_INCLUDE_JP })
66
+ end
67
+ events = d.events
68
+ event = events.first
69
+
70
+ assert_equal 'parsed.test', event.first
71
+ assert_equal URL_INCLUDE_JP, event[2]['url']
72
+ assert_equal 'bar', event[2]['foo']
73
+ assert_equal 'qux', event[2]['baz']
74
+ assert_equal %w[キスク シェンカー ジャクソン], event[2]['まいける']
98
75
  end
99
- end
100
76
 
101
- def test_remove_empty_array
102
- conf = %(
103
- key url
104
- remove_empty_array true
105
- )
106
-
107
- record = {
108
- 'url' => REMOVE_EMPTY_KEY
109
- }
110
-
111
- emits = emit(conf, record)
112
-
113
- emits.each_with_index do |(tag, _time, emit_record), _i|
114
- assert_equal 'parsed.test', tag
115
- assert_equal REMOVE_EMPTY_KEY, emit_record['url']
116
- assert_equal 'bar', emit_record['foo']
117
- assert_equal 'qux', emit_record['baz']
118
- assert_equal nil, emit_record['multiple']
119
- assert_equal nil, emit_record['multiple2']
77
+ test 'only query string filter record' do
78
+ d = create_driver(%(
79
+ key query_string
80
+ only_query_string true
81
+ ))
82
+ time = event_time
83
+
84
+ d.run(default_tag: 'test') do
85
+ d.feed(time, { 'query_string' => ONLY_QUERY_STRING_TEST })
86
+ end
87
+ events = d.events
88
+ event = events.first
89
+
90
+ assert_equal 'parsed.test', event.first
91
+ assert_equal ONLY_QUERY_STRING_TEST, event[2]['query_string']
92
+ assert_equal 'bar', event[2]['foo']
93
+ assert_equal 'qux', event[2]['baz']
94
+ assert_equal %w[1 2 3], event[2]['multiple']
95
+ assert_equal %w[キスク シェンカー ジャクソン], event[2]['まいける']
120
96
  end
121
- end
122
-
123
- def test_tag_prefix
124
- conf = %(
125
- key url
126
- tag_prefix prefix.
127
- )
128
97
 
129
- record = {
130
- 'url' => URL
131
- }
132
-
133
- emits = emit(conf, record)
134
-
135
- emits.each_with_index do |(tag, _time, emit_record), _i|
136
- assert_equal 'prefix.test', tag
137
- assert_equal URL, emit_record['url']
138
- assert_equal 'bar', emit_record['foo']
139
- assert_equal 'qux', emit_record['baz']
140
- assert_equal %w[1 2 3], emit_record['multiple']
98
+ test 'remove empty array' do
99
+ d = create_driver(%(
100
+ key url
101
+ remove_empty_array true
102
+ ))
103
+ time = event_time
104
+
105
+ d.run(default_tag: 'test') do
106
+ d.feed(time, { 'url' => REMOVE_EMPTY_KEY })
107
+ end
108
+ events = d.events
109
+ event = events.first
110
+
111
+ assert_equal 'parsed.test', event.first
112
+ assert_equal REMOVE_EMPTY_KEY, event[2]['url']
113
+ assert_equal 'bar', event[2]['foo']
114
+ assert_equal 'qux', event[2]['baz']
115
+ assert_equal nil, event[2]['multiple']
116
+ assert_equal nil, event[2]['multiple2']
141
117
  end
142
- end
143
118
 
144
- def test_sub_key
145
- conf = %(
146
- key url
147
- sub_key url_parsed
148
- )
149
-
150
- record = {
151
- 'url' => URL
152
- }
153
-
154
- emits = emit(conf, record)
155
-
156
- emits.each_with_index do |(_tag, _time, emit_record), _i|
157
- assert_equal URL, emit_record['url']
158
- assert_equal 'bar', emit_record['url_parsed']['foo']
159
- assert_equal 'qux', emit_record['url_parsed']['baz']
160
- assert_equal %w[1 2 3], emit_record['url_parsed']['multiple']
119
+ test 'tag prefix' do
120
+ d = create_driver(%(
121
+ key url
122
+ tag_prefix prefix.
123
+ ))
124
+ time = event_time
125
+
126
+ d.run(default_tag: 'test') do
127
+ d.feed(time, { 'url' => URL })
128
+ end
129
+ events = d.events
130
+ event = events.first
131
+
132
+ assert_equal 'prefix.test', event.first
133
+ assert_equal URL, event[2]['url']
134
+ assert_equal 'bar', event[2]['foo']
135
+ assert_equal 'qux', event[2]['baz']
136
+ assert_equal %w[1 2 3], event[2]['multiple']
161
137
  end
162
- end
163
138
 
164
- def test_without_host
165
- conf = %(
166
- key url
167
- without_host true
168
- )
169
-
170
- record = {
171
- 'url' => WITHOUT_HOST
172
- }
173
-
174
- emits = emit(conf, record)
139
+ test 'sub key' do
140
+ d = create_driver(%(
141
+ key url
142
+ sub_key url_parsed
143
+ ))
144
+ time = event_time
145
+
146
+ d.run(default_tag: 'test') do
147
+ d.feed(time, { 'url' => URL })
148
+ end
149
+ events = d.events
150
+ event = events.first
151
+
152
+ assert_equal URL, event[2]['url']
153
+ assert_equal 'bar', event[2]['url_parsed']['foo']
154
+ assert_equal 'qux', event[2]['url_parsed']['baz']
155
+ assert_equal %w[1 2 3], event[2]['url_parsed']['multiple']
156
+ end
175
157
 
176
- emits.each_with_index do |(tag, _time, emit_record), _i|
177
- assert_equal 'parsed.test', tag
178
- assert_equal 'bar', emit_record['foo']
179
- assert_equal 'qux', emit_record['baz']
180
- assert_equal %w[1 2 3], emit_record['multiple']
181
- assert_equal [''], emit_record['multiple2']
158
+ test 'without host' do
159
+ d = create_driver(%(
160
+ key url
161
+ without_host true
162
+ ))
163
+ time = event_time
164
+
165
+ d.run(default_tag: 'test') do
166
+ d.feed(time, { 'url' => WITHOUT_HOST })
167
+ end
168
+ events = d.events
169
+ event = events.first
170
+
171
+ assert_equal 'parsed.test', event.first
172
+ assert_equal 'bar', event[2]['foo']
173
+ assert_equal 'qux', event[2]['baz']
174
+ assert_equal %W[1 2 3], event[2]['multiple']
175
+ assert_equal [''], event[2]['multiple2']
182
176
  end
183
177
  end
184
178
  end
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-parse_multiple_value_query
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hirokazu Hata
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-21 00:00:00.000000000 Z
11
+ date: 2018-11-22 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.0
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
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: 0.12.0
29
+ version: 0.14.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: rack
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -80,20 +86,6 @@ dependencies:
80
86
  - - ">="
81
87
  - !ruby/object:Gem::Version
82
88
  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
89
  - !ruby/object:Gem::Dependency
98
90
  name: rake
99
91
  requirement: !ruby/object:Gem::Requirement