fluent-logger 0.8.0 → 0.8.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
- SHA1:
3
- metadata.gz: eb07188f881f645087ed46e08dcb033abd3e78f3
4
- data.tar.gz: c5e7715e87ebf4bb7ca5f5a0afb6297d4772011b
2
+ SHA256:
3
+ metadata.gz: 24cb776c1db25b7c798ad762556f420eb345721c93832e6b40f38d7e67b49c09
4
+ data.tar.gz: bd6dc210af643d76189a5c3a2d86f953c9c68e49a2c4e037a3bd96b5d45e5a91
5
5
  SHA512:
6
- metadata.gz: 44b031f5063e83cac44e704f8a3fe95d1fa8bdf732f68dad096bd6da73b41c31c480412c00c1fe006f9b2bd6285e626f6ab6bc3096115ac559c3961ffd3c9a59
7
- data.tar.gz: d3929bbf74cc3e77fc76149f98a0cd001f34213a715c807290cdc7bdc88df35d4d11d07d963a6a765ad144552ee99fb8cb191d7dce8f28e91e4e4c5c053ef37c
6
+ metadata.gz: c9eaec15cd63b3ceb83190c2748b23763f73f9a202c584011189c4f1941704830ac4cc04db317d49549748645a40a092f075be99601710ba1c1f659e0d4e91aa
7
+ data.tar.gz: 238c085430cce8cad552598e3e5be31b14747b669831d427aab03d13b1fb9256ee68fb9fd1a0d8f9a3d6d813eb458317867c017403a87bc7ffbf1a65002275d8
data/ChangeLog CHANGED
@@ -1,3 +1,7 @@
1
+ Release 0.8.1 - 2019/05/30
2
+
3
+ * Improve non-blocking write handling
4
+
1
5
  Release 0.8.0 - 2019/01/25
2
6
 
3
7
  * Add use_nonblock and wait_writeable parameters
data/README.md CHANGED
@@ -27,6 +27,7 @@ require 'fluent-logger'
27
27
 
28
28
  log = Fluent::Logger::FluentLogger.new(nil, :socket_path => "/tmp/fluent.sock")
29
29
  unless log.post("myapp.access", {"agent" => "foo"})
30
+ # Passed records are stored into logger's internal buffer so don't re-post same event.
30
31
  p log.last_error # You can get last error object via last_error method
31
32
  end
32
33
 
@@ -49,10 +50,17 @@ log.post("access", {"agent" => "foo"})
49
50
  require 'fluent-logger'
50
51
 
51
52
  log = Fluent::Logger::FluentLogger.new(nil, :host => 'localhost', :port => 24224, :use_nonblock => true, :wait_writeable => false)
53
+ # When wait_writeable is false
52
54
  begin
53
55
  log.post("myapp.access", {"agent" => "foo"})
54
56
  rescue IO::EAGAINWaitWritable => e
55
57
  # wait code for avoding "Resource temporarily unavailable"
58
+ # Passed records are stored into logger's internal buffer so don't re-post same event.
59
+ end
60
+
61
+ # When wait_writeable is true
62
+ unless log.post("myapp.access", {"agent" => "foo"})
63
+ # same as other example
56
64
  end
57
65
 
58
66
  # output: myapp.access {"agent":"foo"}
@@ -88,11 +96,11 @@ Use nano second event time instead of epoch. See also "Tips" section.
88
96
 
89
97
  #### use_nonblock (Bool)
90
98
 
91
- Use nonblocking write(`IO#write_nonblock`) instead of normal write(`IO#write`). If `Logger#post` stuck on your environment, specify `true`.
99
+ Use nonblocking write(`IO#write_nonblock`) instead of normal write(`IO#write`). If `Logger#post` stuck on your environment, specify `true`. Default: `false`
92
100
 
93
101
  #### wait_writeable (Bool)
94
102
 
95
- If `true`, `Logger#post` raises an error when nonblocking write gets `EAGAIN`.
103
+ If `false`, `Logger#post` raises an error when nonblocking write gets `EAGAIN` (i.e. `use_nonblock` must be `true`, otherwise this will have no effect). Default: `true`
96
104
 
97
105
  #### buffer_overflow_handler (Proc)
98
106
 
@@ -126,7 +126,6 @@ module Fluent
126
126
  end
127
127
 
128
128
  attr_accessor :limit, :logger, :log_reconnect_error_threshold
129
- attr_reader :last_error
130
129
 
131
130
  def last_error
132
131
  @last_error[Thread.current.object_id]
@@ -230,7 +229,11 @@ module Fluent
230
229
  end
231
230
 
232
231
  begin
233
- send_data(@pending)
232
+ written = send_data(@pending)
233
+ if @pending.bytesize != written
234
+ raise "Actual written data size(#{written} bytes) is different from the received data size(#{@pending.bytesize} bytes)."
235
+ end
236
+
234
237
  @pending = nil
235
238
  true
236
239
  rescue => e
@@ -255,7 +258,7 @@ module Fluent
255
258
  connect!
256
259
  end
257
260
  if @use_nonblock
258
- @con.write_nonblock data
261
+ send_data_nonblock(data)
259
262
  else
260
263
  @con.write data
261
264
  end
@@ -272,7 +275,19 @@ module Fluent
272
275
  # end
273
276
  # data = data[n..-1]
274
277
  #end
275
- true
278
+ end
279
+
280
+ def send_data_nonblock(data)
281
+ written = @con.write_nonblock(data)
282
+ remaining = data.bytesize - written
283
+
284
+ while remaining > 0
285
+ len = @con.write_nonblock(data.byteslice(written, remaining))
286
+ remaining -= len
287
+ written += len
288
+ end
289
+
290
+ written
276
291
  end
277
292
 
278
293
  def connect!
@@ -1,5 +1,5 @@
1
1
  module Fluent
2
2
  module Logger
3
- VERSION = '0.8.0'
3
+ VERSION = '0.8.1'
4
4
  end
5
5
  end
@@ -58,6 +58,57 @@ describe Fluent::Logger::FluentLogger do
58
58
  @serverengine.shutdown
59
59
  end
60
60
 
61
+ describe('testing interaction of use_nonblock and wait_writeable') do
62
+ before(:example) do
63
+ allow_any_instance_of(TCPSocket).to receive(:write_nonblock).and_raise(IO::EAGAINWaitWritable)
64
+ allow_any_instance_of(TCPSocket).to receive(:write) { |_, buf| buf.size }
65
+ end
66
+
67
+ context('use_nonblock is false') do
68
+ let(:block_config) { logger_config.merge(use_nonblock: false) }
69
+
70
+ it('post returns true when wait_writeable is false') {
71
+ cfg = block_config.merge(wait_writeable: false)
72
+ l = Fluent::Logger::FluentLogger.new('logger-test', cfg)
73
+ expect(l.post('hello', foo: 'bar')).to eq true
74
+ }
75
+
76
+ it('post returns true when wait_writeable is true') {
77
+ cfg = block_config.merge(wait_writeable: true)
78
+ l = Fluent::Logger::FluentLogger.new('logger-test', cfg)
79
+ expect(l.post('hello', {foo: 'bar'})).to eq true
80
+ }
81
+ end
82
+
83
+ context('use_nonblock is true') do
84
+ let(:nonblock_config) { logger_config.merge(use_nonblock: true) }
85
+
86
+ it('post raises IO::EAGAINWaitWritable when wait_writeable is false') {
87
+ cfg = nonblock_config.merge(wait_writeable: false)
88
+ l = Fluent::Logger::FluentLogger.new('logger-test', cfg)
89
+ expect { l.post('hello', foo: 'bar') }.to raise_error(IO::EAGAINWaitWritable)
90
+ }
91
+
92
+ it('post returns false when wait_writeable is true') {
93
+ cfg = nonblock_config.merge(wait_writeable: true)
94
+ l = Fluent::Logger::FluentLogger.new('logger-test', cfg)
95
+ expect(l.post('hello', {foo: 'bar'})).to eq false
96
+ }
97
+
98
+ context 'when write_nonblock returns the size less than received data' do
99
+ before do
100
+ allow_any_instance_of(TCPSocket).to receive(:write_nonblock).and_return(1) # write 1 bytes per call
101
+ end
102
+
103
+ it 'buffering data and flush at closed time' do
104
+ logger = Fluent::Logger::FluentLogger.new('logger-test', nonblock_config)
105
+ expect(logger.post('hello', foo: 'bar')).to eq(true)
106
+ expect(logger.pending_bytesize).to eq(0)
107
+ end
108
+ end
109
+ end
110
+ end
111
+
61
112
  context('Post by CUI') do
62
113
  it('post') {
63
114
  args = %W(-h localhost -p #{fluentd.port} -t logger-test.tag -v a=b -v foo=bar)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadayuki Furuhashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-25 00:00:00.000000000 Z
11
+ date: 2019-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -161,8 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
161
  - !ruby/object:Gem::Version
162
162
  version: '0'
163
163
  requirements: []
164
- rubyforge_project:
165
- rubygems_version: 2.6.14.1
164
+ rubygems_version: 3.0.3
166
165
  signing_key:
167
166
  specification_version: 4
168
167
  summary: fluent logger for ruby