fluent-plugin-unit-time-filter 0.1.0 → 0.1.1

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: cb21bb8de5296e1949d37a65ae7edb5e7ac6cccb
4
- data.tar.gz: 1ac61305e86d61a953d9c56756d9731f596f4cbc
3
+ metadata.gz: 180c6e4465e1da97a1646bf9d82b9df431d363cf
4
+ data.tar.gz: 74a04b0c568bef90caff5691948abee16ed147cd
5
5
  SHA512:
6
- metadata.gz: e1eab0e7c3d5f0c351a73ef7756dcef08837c38c8e8d5edd5127324e6ca0733e541b3343966bcd77ec2c352bd2c4b5955384f6c893c8bb1b5a7ff24a3504bd37
7
- data.tar.gz: f89b7f1b131bdb410ec6908864b448fd6b9ea0d8c4d4e14c67d06d2cabf1bc97f8ccfff21ca767dde0a87a6f2837902f13e2d3f89516d43efa61fd56b0ace073
6
+ metadata.gz: b512af5d84a5593ec90d250e3eb1d4e89a8937a9b909f59bd71e831419c2e2c0454bd32924016a28e6afbf7cb9e986d48576968423ab3e8f3a183802dd8e17da
7
+ data.tar.gz: 6de88e2b63dade6980d063724ad88de35e4700b70d773709febde8fc32db77d5d5df34ea3997e8867bf54974d22d779520f1569faa8bb15643d43e1224933271
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = "fluent-plugin-unit-time-filter"
4
- spec.version = "0.1.0"
4
+ spec.version = "0.1.1"
5
5
  spec.authors = ["Genki Sugawara"]
6
6
  spec.email = ["sgwr_dts@yahoo.co.jp"]
7
7
  spec.description = %q{Plug-in to aggregate by unit time}
@@ -21,7 +21,7 @@ class Fluent::UnitTimeFilterOutput < Fluent::Output
21
21
  end
22
22
 
23
23
  begin
24
- @filter = Object.new.instance_eval(File.read(@filter_path))
24
+ @filter = Object.new.instance_eval(File.read(@filter_path), @filter_path)
25
25
  rescue => e
26
26
  raise Fluent::ConfigError, "Invalid filter: #{@filter_path}: #{e}"
27
27
  end
@@ -36,7 +36,7 @@ class Fluent::UnitTimeFilterOutput < Fluent::Output
36
36
  Thread.current[BUFFER_KEY] = nil
37
37
  end
38
38
 
39
- def buffer
39
+ def use_buffer
40
40
  buf = Thread.current[BUFFER_KEY]
41
41
 
42
42
  unless buf
@@ -53,11 +53,19 @@ class Fluent::UnitTimeFilterOutput < Fluent::Output
53
53
  Thread.current[BUFFER_KEY] = buf
54
54
  end
55
55
 
56
- return buf
56
+ begin
57
+ yield(buf)
58
+ rescue Exception => e
59
+ Thread.current[BUFFER_KEY] = nil
60
+ raise e
61
+ end
57
62
  end
58
63
 
59
64
  def emit(tag, es, chain)
60
- buffer.resume(tag, es)
65
+ use_buffer do |buffer|
66
+ buffer.resume(tag, es)
67
+ end
68
+
61
69
  chain.next
62
70
  end
63
71
  end
@@ -33,7 +33,6 @@ class Fluent::UnitTimeFilterOutput < Fluent::Output
33
33
  unit_sec = options[:unit_sec]
34
34
  prefix = options[:prefix]
35
35
  emit_each_tag = options[:emit_each_tag]
36
- pass_hash_row = options[:pass_hash_row]
37
36
 
38
37
  prev_time = nil
39
38
 
@@ -233,4 +233,26 @@ describe Fluent::UnitTimeFilterOutput do
233
233
  end
234
234
  end
235
235
  end
236
+
237
+ describe 'when an error happened' do
238
+ it 'filter name should be to be included in the error' do
239
+ filter = <<-EOS
240
+ proc {|rs|
241
+ raise 'Any error message'
242
+ }
243
+ EOS
244
+
245
+ run_driver(:filter => filter, :tempfile => 'any_filter.rb') do |d|
246
+ begin
247
+ (0...10).each do |i|
248
+ d.emit({"key#{i}" => "val#{i}"}, time + i)
249
+ d.emit({"key#{i}_" => "val#{i}_"}, time + i)
250
+ end
251
+ rescue => e
252
+ expect(e.message).to eq('Any error message')
253
+ expect(File.basename(e.backtrace.first)).to be =~ /\Aany_filter\.rb/
254
+ end
255
+ end
256
+ end
257
+ end
236
258
  end
data/spec/spec_helper.rb CHANGED
@@ -3,14 +3,19 @@ require 'fluent/plugin/out_unit_time_filter'
3
3
  require 'tempfile'
4
4
  require 'time'
5
5
 
6
+ # Disable Test::Unit
7
+ module Test::Unit::RunCount; def run(*); end; end
8
+
6
9
  RSpec.configure do |config|
7
10
  config.before(:all) do
8
11
  Fluent::Test.setup
9
12
  end
10
13
  end
11
14
 
12
- def tempfile(content)
13
- Tempfile.open("#{File.basename __FILE__}.#{$$}") do |f|
15
+ def tempfile(content, basename = nil)
16
+ basename ||= "#{File.basename __FILE__}.#{$$}"
17
+
18
+ Tempfile.open(basename) do |f|
14
19
  f << content
15
20
  f.flush
16
21
  f.rewind
@@ -47,7 +52,7 @@ proc {|rs|
47
52
 
48
53
  tag = options[:tag] || 'test.default'
49
54
 
50
- tempfile(filter) do |f|
55
+ tempfile(filter, options[:tempfile]) do |f|
51
56
  fluentd_conf = <<-EOS
52
57
  type unit_time_filter
53
58
  filter_path #{f.path}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-unit-time-filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara