fluent-plugin-grep 0.3.3 → 0.3.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b28e2f9df47ff5255ba541d237af0803507d0b54
4
- data.tar.gz: 6f3d5af7d9893d5cdc27a20499273f0030c507f7
3
+ metadata.gz: eba48ce3d62883ad7d06dae6a22e638478da51c0
4
+ data.tar.gz: 55a5c8078a242926b89a4f6385a60f6c0fdda048
5
5
  SHA512:
6
- metadata.gz: 6ab25c093315af58af4517eb5239765386cbbfff46822c1225c9a56467833a033d7de7f2f174cae0ca817af448292558ab80dcd35edfdad2df5d93829f463cb8
7
- data.tar.gz: 6baedc91f8bfeb856f2ac54c1473ad8f6f0a936fbd8036d462b017ef201042d809ea83a4a86cac57be5180f8026e99582159cf18510b47d49d60650aa2fedc56
6
+ metadata.gz: ae57a90ff85b1007b3530abe650fe3e6295ae217828f76669f1f83f7979a883259083ee2f458dbf08a94389297fd3ba0a155ecf733983ab7b9ff2c532ca4cdf0
7
+ data.tar.gz: 97db9377e3f230755f013b39666d93f9d67ca1622a5d18c8ef16d8a3f519b43dee79879a4e4581c560aa8170a376c232c22c1d5d918a8a76a2af5735fe8c45f4
@@ -1 +1 @@
1
- repo_token: i4DJCtdksuIwhBck1tukIjzKoMCxWIIvQ
1
+ repo_token: iomWCR9hV8xciCfpsPydDgckjaYH4dmw9
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
1
  --colour
2
- --format documentation
2
+ --format Fuubar
@@ -2,6 +2,7 @@ rvm:
2
2
  - 1.9.3
3
3
  - 2.0.0
4
4
  - 2.1.*
5
+ - 2.2.*
5
6
  gemfile:
6
7
  - Gemfile
7
- - Gemfile.fluentd.lt.0.10.43
8
+ - Gemfile.fluentd.lt.0.12
@@ -1,3 +1,14 @@
1
+ ## 0.3.4 (2015/05/10)
2
+
3
+ Fixes:
4
+
5
+ * Fix `replace_invalid_sequence` was always effective
6
+
7
+ Enhancements:
8
+
9
+ * Some log enhancements
10
+ * Support label feature of Fluentd v0.12
11
+
1
12
  ## 0.3.3 (2014/04/12)
2
13
 
3
14
  Enhancements:
@@ -1,4 +1,4 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem 'fluentd', '= 0.10.42'
3
+ gem 'fluentd', '~> 0.10.43'
4
4
  gemspec
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
- # fluent-plugin-grep [![Build Status](https://secure.travis-ci.org/sonots/fluent-plugin-grep.png?branch=master)](http://travis-ci.org/sonots/fluent-plugin-grep) [![Coverage Status](https://coveralls.io/repos/sonots/fluent-plugin-grep/badge.png?branch=master)](https://coveralls.io/r/sonots/fluent-plugin-grep)
1
+ # fluent-plugin-grep
2
+
3
+ [![Build Status](https://secure.travis-ci.org/sonots/fluent-plugin-grep.png?branch=master)](http://travis-ci.org/sonots/fluent-plugin-grep)
4
+ [![Coverage Status](https://coveralls.io/repos/sonots/fluent-plugin-grep/badge.png?branch=master)](https://coveralls.io/r/sonots/fluent-plugin-grep?branch=master)
2
5
 
3
6
  Fluentd plugin to grep messages.
4
7
 
@@ -83,9 +86,17 @@ then output bocomes as belows:
83
86
 
84
87
  Remove tag prefix for output message
85
88
 
89
+ - add_tag_suffix
90
+
91
+ Add tag suffix for output message
92
+
93
+ - remove_tag_suffix
94
+
95
+ Remove tag suffix for output message
96
+
86
97
  - replace_invalid_sequence
87
98
 
88
- Replace invalid byte sequence in UTF-8 with '?' character if `true`
99
+ Replace invalid byte sequence in UTF-8 with '?' character if `true`. Default: true
89
100
 
90
101
  ## ChangeLog
91
102
 
data/Rakefile CHANGED
@@ -1,12 +1,15 @@
1
1
  # encoding: utf-8
2
2
  require "bundler/gem_tasks"
3
3
 
4
- require 'rspec/core'
5
- require 'rspec/core/rake_task'
6
- RSpec::Core::RakeTask.new(:spec) do |spec|
7
- spec.pattern = FileList['spec/**/*_spec.rb']
4
+ require 'rake/testtask'
5
+ desc 'Run test_unit based test'
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.test_files = Dir["test/**/test_*.rb"].sort
9
+ t.verbose = true
10
+ #t.warning = true
8
11
  end
9
- task :default => :spec
12
+ task :default => :test
10
13
 
11
14
  desc 'Open an irb session preloaded with the gem library'
12
15
  task :console do
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "fluent-plugin-grep"
6
- s.version = "0.3.3"
6
+ s.version = "0.3.4"
7
7
  s.authors = ["Naotoshi Seo"]
8
8
  s.email = ["sonots@gmail.com"]
9
9
  s.homepage = "https://github.com/sonots/fluent-plugin-grep"
@@ -19,9 +19,9 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  s.add_runtime_dependency "fluentd"
22
+ s.add_runtime_dependency "string-scrub" if RUBY_VERSION.to_f < 2.1
22
23
  s.add_development_dependency "rake"
23
- s.add_development_dependency "rspec"
24
+ s.add_development_dependency "test-unit"
24
25
  s.add_development_dependency "pry"
25
26
  s.add_development_dependency "pry-nav"
26
- s.add_development_dependency 'coveralls'
27
27
  end
@@ -11,7 +11,7 @@ class Fluent::GrepOutput < Fluent::Output
11
11
  config_param :remove_tag_prefix, :string, :default => nil
12
12
  config_param :add_tag_suffix, :string, :default => nil
13
13
  config_param :remove_tag_suffix, :string, :default => nil
14
- config_param :replace_invalid_sequence, :bool, :default => false
14
+ config_param :replace_invalid_sequence, :bool, :default => true
15
15
  (1..REGEXP_MAX_NUM).each {|i| config_param :"regexp#{i}", :string, :default => nil }
16
16
  (1..REGEXP_MAX_NUM).each {|i| config_param :"exclude#{i}", :string, :default => nil }
17
17
 
@@ -24,6 +24,16 @@ class Fluent::GrepOutput < Fluent::Output
24
24
  define_method("log") { $log }
25
25
  end
26
26
 
27
+ # Define `router` method of v0.12 to support v0.10 or earlier
28
+ unless method_defined?(:router)
29
+ define_method("router") { Fluent::Engine }
30
+ end
31
+
32
+ def initialize
33
+ require 'string/scrub' if RUBY_VERSION.to_f < 2.1
34
+ super
35
+ end
36
+
27
37
  def configure(conf)
28
38
  super
29
39
 
@@ -47,7 +57,7 @@ class Fluent::GrepOutput < Fluent::Output
47
57
  @excludes[key] = Regexp.compile(exclude)
48
58
  end
49
59
 
50
- if @tag.nil? and @add_tag_prefix.nil? and @remove_tag_prefix.nil? and @add_tag_suffix.nil? and @remove_tag_suffix.nil?
60
+ if conf['@label'].nil? and @tag.nil? and @add_tag_prefix.nil? and @remove_tag_prefix.nil? and @add_tag_suffix.nil? and @remove_tag_suffix.nil?
51
61
  @add_tag_prefix = 'greped' # not ConfigError to support lower version compatibility
52
62
  end
53
63
  @tag_proc = tag_proc
@@ -64,14 +74,13 @@ class Fluent::GrepOutput < Fluent::Output
64
74
  @excludes.each do |key, exclude|
65
75
  throw :break_loop if match(exclude, record[key].to_s)
66
76
  end
67
- Fluent::Engine.emit(emit_tag, time, record)
77
+ router.emit(emit_tag, time, record)
68
78
  end
69
79
  end
70
80
 
71
81
  chain.next
72
82
  rescue => e
73
- log.warn e.message
74
- log.warn e.backtrace.join(', ')
83
+ log.warn "out_grep: #{e.class} #{e.message} #{e.backtrace.first}"
75
84
  end
76
85
 
77
86
  private
@@ -101,18 +110,12 @@ class Fluent::GrepOutput < Fluent::Output
101
110
  begin
102
111
  return regexp.match(string)
103
112
  rescue ArgumentError => e
113
+ raise e unless @replace_invalid_sequence
104
114
  raise e unless e.message.index("invalid byte sequence in") == 0
105
- string = replace_invalid_byte(string)
115
+ log.info "out_grep: invalid byte sequence is replaced in `#{string}`"
116
+ string = string.scrub('?')
106
117
  retry
107
118
  end
108
119
  return true
109
120
  end
110
-
111
- def replace_invalid_byte(string)
112
- replace_options = { invalid: :replace, undef: :replace, replace: '?' }
113
- original_encoding = string.encoding
114
- temporal_encoding = (original_encoding == Encoding::UTF_8 ? Encoding::UTF_16BE : Encoding::UTF_8)
115
- string.encode(temporal_encoding, original_encoding, replace_options).encode(original_encoding)
116
- end
117
-
118
121
  end
@@ -1,5 +1,5 @@
1
- # encoding: UTF-8
2
- require_relative 'spec_helper'
1
+ require_relative 'helper'
2
+ require 'fluent/plugin/out_grep'
3
3
 
4
4
  # setup
5
5
  Fluent::Test.setup
@@ -0,0 +1,27 @@
1
+ require 'test/unit'
2
+ require 'fluent/log'
3
+ require 'fluent/test'
4
+
5
+ unless defined?(Test::Unit::AssertionFailedError)
6
+ class Test::Unit::AssertionFailedError < StandardError
7
+ end
8
+ end
9
+
10
+ # Stop non required sleep at
11
+ # https://github.com/fluent/fluentd/blob/018791f6b1b0400b71e37df2fb3ad80e456d2c11/lib/fluent/test/base.rb#L56
12
+ module Fluent
13
+ module Test
14
+ class TestDriver
15
+ def run(&block)
16
+ @instance.start
17
+ begin
18
+ # wait until thread starts
19
+ # 10.times { sleep 0.05 }
20
+ return yield
21
+ ensure
22
+ @instance.shutdown
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,260 @@
1
+ require_relative 'helper'
2
+ require 'fluent/test'
3
+ require 'fluent/plugin/out_grep'
4
+
5
+ Fluent::Test.setup
6
+
7
+ class GrepOutputTest < Test::Unit::TestCase
8
+ setup do
9
+ @tag = 'syslog.host1'
10
+ @time = Fluent::Engine.now
11
+ end
12
+
13
+ def create_driver(conf, use_v1_config = true)
14
+ Fluent::Test::OutputTestDriver.new(Fluent::GrepOutput, @tag).configure(conf, use_v1_config)
15
+ end
16
+
17
+ def emit(config, msgs = [''])
18
+ d = create_driver(config)
19
+ d.run do
20
+ msgs.each do |msg|
21
+ d.emit({'foo' => 'bar', 'message' => msg}, @time)
22
+ end
23
+ end
24
+
25
+ @instance = d.instance
26
+ d.emits
27
+ end
28
+
29
+ sub_test_case 'configure' do
30
+ test 'check default' do
31
+ d = nil
32
+ assert_nothing_raised do
33
+ d = create_driver('')
34
+ end
35
+ assert_empty(d.instance.regexps)
36
+ assert_empty(d.instance.excludes)
37
+ end
38
+
39
+ test "regexpN can contain a space" do
40
+ d = create_driver(%[regexp1 message foo])
41
+ assert_equal(Regexp.compile(/ foo/), d.instance.regexps['message'])
42
+ end
43
+
44
+ test "excludeN can contain a space" do
45
+ d = create_driver(%[exclude1 message foo])
46
+ assert_equal(Regexp.compile(/ foo/), d.instance.excludes['message'])
47
+ end
48
+
49
+ test "regexp contains a duplicated key" do
50
+ config = %[
51
+ input_key message
52
+ regexp foo
53
+ regexp1 message foo
54
+ ]
55
+ assert_raise(Fluent::ConfigError) do
56
+ create_driver(config)
57
+ end
58
+ end
59
+
60
+ test "exclude contains a duplicated key" do
61
+ config = %[
62
+ input_key message
63
+ exclude foo
64
+ exclude1 message foo
65
+ ]
66
+ assert_raise(Fluent::ConfigError) do
67
+ create_driver(config)
68
+ end
69
+ end
70
+
71
+ if Fluent::VERSION >= "0.12"
72
+ test "@label" do
73
+ Fluent::Engine.root_agent.add_label('@foo')
74
+ d = create_driver(%[@label @foo])
75
+ label = Fluent::Engine.root_agent.find_label('@foo')
76
+ assert_equal(label.event_router, d.instance.router)
77
+
78
+ emits = emit(%[@label @foo], ['foo'])
79
+ tag, time, record = emits.first
80
+ assert_equal(@tag, tag) # tag is not modified
81
+ end
82
+ end
83
+ end
84
+
85
+ sub_test_case 'emit' do
86
+ def messages
87
+ [
88
+ "2013/01/13T07:02:11.124202 INFO GET /ping",
89
+ "2013/01/13T07:02:13.232645 WARN POST /auth",
90
+ "2013/01/13T07:02:21.542145 WARN GET /favicon.ico",
91
+ "2013/01/13T07:02:43.632145 WARN POST /login",
92
+ ]
93
+ end
94
+
95
+ test 'empty config' do
96
+ emits = emit('', messages)
97
+ assert_equal(4, emits.size)
98
+ tag, time, record = emits.first
99
+ assert_equal("greped.#{@tag}", tag)
100
+ assert_not_nil(record, 'foo')
101
+ assert_not_nil(record, 'message')
102
+ end
103
+
104
+ test 'regexp' do
105
+ emits = emit("input_key message\nregexp WARN", messages)
106
+ assert_equal(3, emits.size)
107
+ assert_block('only WARN logs') do
108
+ emits.all? { |tag, time, record|
109
+ !record['message'].include?('INFO')
110
+ }
111
+ end
112
+ end
113
+
114
+ test 'regexpN' do
115
+ emits = emit('regexp1 message WARN', messages)
116
+ assert_equal(3, emits.size)
117
+ assert_block('only WARN logs') do
118
+ emits.all? { |tag, time, record|
119
+ !record['message'].include?('INFO')
120
+ }
121
+ end
122
+ end
123
+
124
+ test 'exclude' do
125
+ emits = emit("input_key message\nexclude favicon", messages)
126
+ assert_equal(3, emits.size)
127
+ assert_block('remove favicon logs') do
128
+ emits.all? { |tag, time, record|
129
+ !record['message'].include?('favicon')
130
+ }
131
+ end
132
+ end
133
+
134
+ test 'excludeN' do
135
+ emits = emit('exclude1 message favicon', messages)
136
+ assert_equal(3, emits.size)
137
+ assert_block('remove favicon logs') do
138
+ emits.all? { |tag, time, record|
139
+ !record['message'].include?('favicon')
140
+ }
141
+ end
142
+ end
143
+
144
+ test 'tag' do
145
+ emits = emit('tag foo')
146
+ tag, time, record = emits.first
147
+ assert_equal('foo', tag)
148
+ end
149
+
150
+ test 'add_tag_prefix' do
151
+ emits = emit('add_tag_prefix foo')
152
+ tag, time, record = emits.first
153
+ assert_equal("foo.#{@tag}", tag)
154
+ end
155
+
156
+ test 'remove_tag_prefix' do
157
+ emits = emit('remove_tag_prefix syslog')
158
+ tag, time, record = emits.first
159
+ assert_equal("host1", tag)
160
+ end
161
+
162
+ test 'add_tag_suffix' do
163
+ emits = emit('add_tag_suffix foo')
164
+ tag, time, record = emits.first
165
+ assert_equal("#{@tag}.foo", tag)
166
+ end
167
+
168
+ test 'remove_tag_suffix' do
169
+ emits = emit('remove_tag_suffix host1')
170
+ tag, time, record = emits.first
171
+ assert_equal("syslog", tag)
172
+ end
173
+
174
+ test 'add_tag_prefix.' do
175
+ emits = emit('add_tag_prefix foo.')
176
+ tag, time, record = emits.first
177
+ assert_equal("foo.#{@tag}", tag)
178
+ end
179
+
180
+ test 'remove_tag_prefix.' do
181
+ emits = emit('remove_tag_prefix syslog.')
182
+ tag, time, record = emits.first
183
+ assert_equal("host1", tag)
184
+ end
185
+
186
+ test '.add_tag_suffix' do
187
+ emits = emit('add_tag_suffix .foo')
188
+ tag, time, record = emits.first
189
+ assert_equal("#{@tag}.foo", tag)
190
+ end
191
+
192
+ test '.remove_tag_suffix' do
193
+ emits = emit('remove_tag_suffix .host1')
194
+ tag, time, record = emits.first
195
+ assert_equal("syslog", tag)
196
+ end
197
+
198
+ test 'all tag options' do
199
+ @tag = 'syslog.foo.host1'
200
+ config = %[
201
+ add_tag_prefix foo
202
+ remove_tag_prefix syslog
203
+ add_tag_suffix foo
204
+ remove_tag_suffix host1
205
+ ]
206
+ emits = emit(config)
207
+ tag, time, record = emits.first
208
+ assert_equal("foo.foo.foo", tag)
209
+ end
210
+
211
+ test 'with invalid sequence' do
212
+ assert_nothing_raised {
213
+ emit(%[regexp1 message WARN], ["\xff".force_encoding('UTF-8')])
214
+ }
215
+ end
216
+ end
217
+
218
+ sub_test_case 'grep non-string jsonable values' do
219
+ data(
220
+ 'array' => ["0"],
221
+ 'hash' => ["0" => "0"],
222
+ 'integer' => 0,
223
+ 'float' => 0.1)
224
+ test "value" do |data|
225
+ emits = emit('regexp1 message 0', [data])
226
+ assert_equal(1, emits.size)
227
+ end
228
+
229
+ test "value boolean" do
230
+ emits = emit('regexp1 message true', [true])
231
+ assert_equal(1, emits.size)
232
+ end
233
+ end
234
+
235
+ sub_test_case 'test log' do
236
+ def capture_log(log)
237
+ tmp = log.out
238
+ log.out = StringIO.new
239
+ yield log
240
+ return log.out.string
241
+ ensure
242
+ log.out = tmp
243
+ end
244
+
245
+ if Fluent::VERSION >= "0.10.43"
246
+ test "log_level info" do
247
+ d = create_driver('log_level info')
248
+ log = d.instance.log
249
+ assert_equal("", capture_log(log) {|log| log.debug "foobar" })
250
+ assert_include(capture_log(log) {|log| log.info "foobar" }, "foobar")
251
+ end
252
+ end
253
+
254
+ test "should work" do
255
+ d = create_driver('')
256
+ log = d.instance.log
257
+ assert_include(capture_log(log) {|log| log.info "foobar" }, "foobar")
258
+ end
259
+ end
260
+ end
metadata CHANGED
@@ -1,97 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-grep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-11 00:00:00.000000000 Z
11
+ date: 2015-05-09 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
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: test-unit
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pry-nav
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: coveralls
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
- - - '>='
80
+ - - ">="
95
81
  - !ruby/object:Gem::Version
96
82
  version: '0'
97
83
  description: fluentd plugin to grep messages
@@ -101,22 +87,21 @@ executables: []
101
87
  extensions: []
102
88
  extra_rdoc_files: []
103
89
  files:
104
- - .coveralls.yml
105
- - .gitignore
106
- - .rdebugrc
107
- - .rspec
108
- - .travis.yml
90
+ - ".coveralls.yml"
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
109
94
  - CHANGELOG.md
110
95
  - Gemfile
111
- - Gemfile.fluentd.lt.0.10.43
96
+ - Gemfile.fluentd.lt.0.12
112
97
  - LICENSE
113
98
  - README.md
114
99
  - Rakefile
115
100
  - fluent-plugin-grep.gemspec
116
101
  - lib/fluent/plugin/out_grep.rb
117
- - spec/out_grep_bench.rb
118
- - spec/out_grep_spec.rb
119
- - spec/spec_helper.rb
102
+ - test/bench_out_grep.rb
103
+ - test/helper.rb
104
+ - test/test_out_grep.rb
120
105
  homepage: https://github.com/sonots/fluent-plugin-grep
121
106
  licenses:
122
107
  - MIT
@@ -127,21 +112,21 @@ require_paths:
127
112
  - lib
128
113
  required_ruby_version: !ruby/object:Gem::Requirement
129
114
  requirements:
130
- - - '>='
115
+ - - ">="
131
116
  - !ruby/object:Gem::Version
132
117
  version: '0'
133
118
  required_rubygems_version: !ruby/object:Gem::Requirement
134
119
  requirements:
135
- - - '>='
120
+ - - ">="
136
121
  - !ruby/object:Gem::Version
137
122
  version: '0'
138
123
  requirements: []
139
124
  rubyforge_project: fluent-plugin-grep
140
- rubygems_version: 2.0.3
125
+ rubygems_version: 2.2.2
141
126
  signing_key:
142
127
  specification_version: 4
143
128
  summary: fluentd plugin to grep messages
144
129
  test_files:
145
- - spec/out_grep_bench.rb
146
- - spec/out_grep_spec.rb
147
- - spec/spec_helper.rb
130
+ - test/bench_out_grep.rb
131
+ - test/helper.rb
132
+ - test/test_out_grep.rb
data/.rdebugrc DELETED
@@ -1,4 +0,0 @@
1
- set autolist
2
- set autoeval
3
- set autoreload
4
-
@@ -1,381 +0,0 @@
1
- # encoding: UTF-8
2
- require_relative 'spec_helper'
3
-
4
- describe Fluent::GrepOutput do
5
- before { Fluent::Test.setup }
6
- CONFIG = %[
7
- input_key message
8
- ]
9
- let(:tag) { 'syslog.host1' }
10
- let(:driver) { Fluent::Test::OutputTestDriver.new(Fluent::GrepOutput, tag).configure(config) }
11
-
12
- describe 'test configure' do
13
- describe 'bad configuration' do
14
- context 'regexp contains a duplicated key' do
15
- let(:config) { CONFIG + %[
16
- input_key message
17
- regexp foo
18
- regexp1 message foo
19
- ]}
20
- it { expect { driver }.to raise_error(Fluent::ConfigError) }
21
- end
22
- context 'exclude contains a duplicated key' do
23
- let(:config) { CONFIG + %[
24
- input_key message
25
- exclude foo
26
- exclude1 message foo
27
- ]}
28
- it { expect { driver }.to raise_error(Fluent::ConfigError) }
29
- end
30
- end
31
-
32
- describe 'good configuration' do
33
- subject { driver.instance }
34
-
35
- context "check default" do
36
- let(:config) { CONFIG }
37
- its(:input_key) { should == "message" }
38
- its(:regexp) { should be_nil }
39
- its(:exclude) { should be_nil }
40
- its(:tag) { should be_nil }
41
- its(:add_tag_prefix) { should == 'greped' }
42
- end
43
-
44
- context "regexpN can contain a space" do
45
- let(:config) { CONFIG + %[regexp1 message foo] }
46
- it { subject.regexps['message'].should == Regexp.compile(/ foo/) }
47
- end
48
-
49
- context "excludeN can contain a space" do
50
- let(:config) { CONFIG + %[exclude1 message foo] }
51
- it { subject.excludes['message'].should == Regexp.compile(/ foo/) }
52
- end
53
- end
54
- end
55
-
56
- describe 'test emit' do
57
- let(:time) { Time.now.to_i }
58
- let(:messages) do
59
- [
60
- "2013/01/13T07:02:11.124202 INFO GET /ping",
61
- "2013/01/13T07:02:13.232645 WARN POST /auth",
62
- "2013/01/13T07:02:21.542145 WARN GET /favicon.ico",
63
- "2013/01/13T07:02:43.632145 WARN POST /login",
64
- ]
65
- end
66
- let(:emit) do
67
- driver.run { messages.each {|message| driver.emit({'foo'=>'bar', 'message' => message}, time) } }
68
- end
69
-
70
- context 'default' do
71
- let(:config) { CONFIG }
72
- before do
73
- Fluent::Engine.stub(:now).and_return(time)
74
- Fluent::Engine.should_receive(:emit).with("greped.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:11.124202 INFO GET /ping"})
75
- Fluent::Engine.should_receive(:emit).with("greped.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:13.232645 WARN POST /auth"})
76
- Fluent::Engine.should_receive(:emit).with("greped.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:21.542145 WARN GET /favicon.ico"})
77
- Fluent::Engine.should_receive(:emit).with("greped.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:43.632145 WARN POST /login"})
78
- end
79
- it { emit }
80
- end
81
-
82
- context 'regexp' do
83
- let(:config) do
84
- CONFIG + %[
85
- regexp WARN
86
- ]
87
- end
88
- before do
89
- Fluent::Engine.stub(:now).and_return(time)
90
- Fluent::Engine.should_receive(:emit).with("greped.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:13.232645 WARN POST /auth"})
91
- Fluent::Engine.should_receive(:emit).with("greped.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:21.542145 WARN GET /favicon.ico"})
92
- Fluent::Engine.should_receive(:emit).with("greped.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:43.632145 WARN POST /login"})
93
- end
94
- it { emit }
95
- end
96
-
97
- context 'regexpN' do
98
- let(:config) do
99
- CONFIG + %[
100
- regexp1 message WARN
101
- ]
102
- end
103
- before do
104
- Fluent::Engine.stub(:now).and_return(time)
105
- Fluent::Engine.should_receive(:emit).with("greped.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:13.232645 WARN POST /auth"})
106
- Fluent::Engine.should_receive(:emit).with("greped.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:21.542145 WARN GET /favicon.ico"})
107
- Fluent::Engine.should_receive(:emit).with("greped.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:43.632145 WARN POST /login"})
108
- end
109
- it { emit }
110
- end
111
-
112
- context 'exclude' do
113
- let(:config) do
114
- CONFIG + %[
115
- exclude favicon
116
- ]
117
- end
118
- before do
119
- Fluent::Engine.stub(:now).and_return(time)
120
- Fluent::Engine.should_receive(:emit).with("greped.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:11.124202 INFO GET /ping"})
121
- Fluent::Engine.should_receive(:emit).with("greped.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:13.232645 WARN POST /auth"})
122
- Fluent::Engine.should_receive(:emit).with("greped.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:43.632145 WARN POST /login"})
123
- end
124
- it { emit }
125
- end
126
-
127
- context 'excludeN' do
128
- let(:config) do
129
- CONFIG + %[
130
- exclude1 message favicon
131
- ]
132
- end
133
- before do
134
- Fluent::Engine.stub(:now).and_return(time)
135
- Fluent::Engine.should_receive(:emit).with("greped.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:11.124202 INFO GET /ping"})
136
- Fluent::Engine.should_receive(:emit).with("greped.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:13.232645 WARN POST /auth"})
137
- Fluent::Engine.should_receive(:emit).with("greped.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:43.632145 WARN POST /login"})
138
- end
139
- it { emit }
140
- end
141
-
142
- context 'tag' do
143
- let(:config) do
144
- CONFIG + %[
145
- regexp ping
146
- tag foo
147
- ]
148
- end
149
- before do
150
- Fluent::Engine.stub(:now).and_return(time)
151
- Fluent::Engine.should_receive(:emit).with("foo", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:11.124202 INFO GET /ping"})
152
- end
153
- it { emit }
154
- end
155
-
156
- context 'add_tag_prefix' do
157
- let(:config) do
158
- CONFIG + %[
159
- regexp ping
160
- add_tag_prefix foo
161
- ]
162
- end
163
- let(:tag) { 'syslog.host1' }
164
- before do
165
- Fluent::Engine.stub(:now).and_return(time)
166
- Fluent::Engine.should_receive(:emit).with("foo.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:11.124202 INFO GET /ping"})
167
- end
168
- it { emit }
169
- end
170
-
171
- context 'remove_tag_prefix' do
172
- let(:config) do
173
- CONFIG + %[
174
- regexp ping
175
- remove_tag_prefix syslog
176
- ]
177
- end
178
- let(:tag) { 'syslog.host1' }
179
- before do
180
- Fluent::Engine.stub(:now).and_return(time)
181
- Fluent::Engine.should_receive(:emit).with("host1", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:11.124202 INFO GET /ping"})
182
- end
183
- it { emit }
184
- end
185
-
186
- context 'add_tag_suffix' do
187
- let(:config) do
188
- CONFIG + %[
189
- regexp ping
190
- add_tag_suffix foo
191
- ]
192
- end
193
- let(:tag) { 'syslog.host1' }
194
- before do
195
- Fluent::Engine.stub(:now).and_return(time)
196
- Fluent::Engine.should_receive(:emit).with("#{tag}.foo", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:11.124202 INFO GET /ping"})
197
- end
198
- it { emit }
199
- end
200
-
201
- context 'remove_tag_suffix' do
202
- let(:config) do
203
- CONFIG + %[
204
- regexp ping
205
- remove_tag_suffix host1
206
- ]
207
- end
208
- let(:tag) { 'syslog.host1' }
209
- before do
210
- Fluent::Engine.stub(:now).and_return(time)
211
- Fluent::Engine.should_receive(:emit).with("syslog", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:11.124202 INFO GET /ping"})
212
- end
213
- it { emit }
214
- end
215
-
216
- context 'all tag options' do
217
- let(:config) do
218
- CONFIG + %[
219
- regexp ping
220
- add_tag_prefix foo
221
- remove_tag_prefix syslog
222
- add_tag_suffix foo
223
- remove_tag_suffix host1
224
- ]
225
- end
226
- let(:tag) { 'syslog.foo.host1' }
227
- before do
228
- Fluent::Engine.stub(:now).and_return(time)
229
- Fluent::Engine.should_receive(:emit).with("foo.foo.foo", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:11.124202 INFO GET /ping"})
230
- end
231
- it { emit }
232
- end
233
-
234
- context 'add_tag_prefix.' do
235
- let(:config) do
236
- CONFIG + %[
237
- regexp ping
238
- add_tag_prefix foo.
239
- ]
240
- end
241
- let(:tag) { 'syslog.host1' }
242
- before do
243
- Fluent::Engine.stub(:now).and_return(time)
244
- Fluent::Engine.should_receive(:emit).with("foo.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:11.124202 INFO GET /ping"})
245
- end
246
- it { emit }
247
- end
248
-
249
- context 'remove_tag_prefix.' do
250
- let(:config) do
251
- CONFIG + %[
252
- regexp ping
253
- remove_tag_prefix syslog.
254
- ]
255
- end
256
- let(:tag) { 'syslog.host1' }
257
- before do
258
- Fluent::Engine.stub(:now).and_return(time)
259
- Fluent::Engine.should_receive(:emit).with("host1", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:11.124202 INFO GET /ping"})
260
- end
261
- it { emit }
262
- end
263
-
264
- context '.add_tag_suffix' do
265
- let(:config) do
266
- CONFIG + %[
267
- regexp ping
268
- add_tag_suffix .foo
269
- ]
270
- end
271
- let(:tag) { 'syslog.host1' }
272
- before do
273
- Fluent::Engine.stub(:now).and_return(time)
274
- Fluent::Engine.should_receive(:emit).with("#{tag}.foo", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:11.124202 INFO GET /ping"})
275
- end
276
- it { emit }
277
- end
278
-
279
- context '.remove_tag_suffix' do
280
- let(:config) do
281
- CONFIG + %[
282
- regexp ping
283
- remove_tag_suffix .host1
284
- ]
285
- end
286
- let(:tag) { 'syslog.host1' }
287
- before do
288
- Fluent::Engine.stub(:now).and_return(time)
289
- Fluent::Engine.should_receive(:emit).with("syslog", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:11.124202 INFO GET /ping"})
290
- end
291
- it { emit }
292
- end
293
-
294
- context 'replace_invalid_sequence' do
295
- let(:config) do
296
- CONFIG + %[
297
- regexp WARN
298
- replace_invalid_sequence true
299
- ]
300
- end
301
- let(:messages) do
302
- [
303
- "\xff".force_encoding('UTF-8'),
304
- ]
305
- end
306
- before do
307
- Fluent::Engine.stub(:now).and_return(time)
308
- end
309
- it { expect { emit }.not_to raise_error }
310
- end
311
- end
312
-
313
- describe 'grep non-string jsonable values' do
314
- let(:config) { CONFIG + %[regexp 0] }
315
- let(:message) { 0 }
316
- let(:time) { Time.now.to_i }
317
- let(:emit) { driver.run { driver.emit({'foo'=>'bar', 'message' => message}, time) } }
318
- before do
319
- Fluent::Engine.stub(:now).and_return(time)
320
- Fluent::Engine.should_receive(:emit).with("greped.#{tag}", time, {'foo'=>'bar', 'message'=>message})
321
- end
322
-
323
- context "array" do
324
- let(:message) { ["0"] }
325
- it { emit }
326
- end
327
-
328
- context "hash" do
329
- let(:message) { ["0"=>"0"] }
330
- it { emit }
331
- end
332
-
333
- context "integer" do
334
- let(:message) { 0 }
335
- it { emit }
336
- end
337
-
338
- context "float" do
339
- let(:message) { 0.1 }
340
- it { emit }
341
- end
342
-
343
- context "boolean" do
344
- let(:config) { CONFIG + %[regexp true] }
345
- let(:message) { true }
346
- it { emit }
347
- end
348
- end
349
-
350
- describe 'test log' do
351
- let(:log) { driver.instance.log }
352
-
353
- def capture_log(log)
354
- tmp = log.instance_variable_get(:@out)
355
- out = StringIO.new
356
- log.instance_variable_set(:@out, out)
357
- yield log
358
- return out.string
359
- ensure
360
- log.instance_variable_set(:@out, tmp)
361
- end
362
-
363
- if Fluent::VERSION >= "0.10.43"
364
- context "log_level info" do
365
- let(:config) { CONFIG + %[log_level info] }
366
-
367
- it "should not contain debug level" do
368
- capture_log(log) {|log| log.debug "foobar" }.should == ""
369
- end
370
- end
371
- end
372
-
373
- context "log" do
374
- let(:config) { CONFIG }
375
- it "should work" do
376
- capture_log(log) {|log| log.info "foobar" }.should include("foobar")
377
- end
378
- end
379
- end
380
-
381
- end
@@ -1,16 +0,0 @@
1
- # encoding: UTF-8
2
- require 'rubygems'
3
- require 'bundler'
4
- Bundler.setup(:default, :test)
5
- Bundler.require(:default, :test)
6
-
7
- require 'coveralls'
8
- Coveralls.wear!
9
-
10
- require 'fluent/test'
11
- require 'rspec'
12
- require 'pry'
13
-
14
- $TESTING=true
15
- $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
16
- require 'fluent/plugin/out_grep'