fluent-logger 0.8.2 → 0.9.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
  SHA256:
3
- metadata.gz: 7be5ae39c39ebb27bdeeaa66b1d103cb6e7d8f7d6f0f5073ff5320c333345c37
4
- data.tar.gz: 6f226c613086aff26729786e088a2923552fd02a8e28ebe88654d1dda068b98f
3
+ metadata.gz: 460c4365ba58c7558db145e551b806ee8b2afb764454bfbba35e6f6290093317
4
+ data.tar.gz: 5166f31570a03e934c217464a2d16706f82bd650581f43d83ee87c53e0952da8
5
5
  SHA512:
6
- metadata.gz: 53da0192645010cd5fe3ddc739ff4a6c5784ceb5ddbb8216b25ccd562a176606abfeeb5a9e164d0734e53467b69de749075136c07aebfa02e1da9babfb3f5e1b
7
- data.tar.gz: db4c2283dc26641cdf4ac727ebb8815fa0e9ce3c0672b0e5bb98030aa83538005d653547551fa1ac954e591013ff1aaefbf1556905e5e4445479492e5b07b6a0
6
+ metadata.gz: 443b59cb242dc22e0d7ec6e711aefc2274452b5ea19d04af73db8250683f27da15b731af24b137213d91ea1f9c91873e7c5b85302c461c3f312b5d19e4bed2b7
7
+ data.tar.gz: 3e1d99bb86d51e2e589621e73ad763de5928e19aa1a15d470fa7adc616a749674df69356b8bd431d07804a8f5925bcb8742c98a560e99f6ff35abf2f423c439e
@@ -0,0 +1,30 @@
1
+ name: linux
2
+ on:
3
+ - push
4
+ - pull_request
5
+ jobs:
6
+ build:
7
+ runs-on: ${{ matrix.os }}
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ ruby:
12
+ - '2.7'
13
+ - '3.0'
14
+ - '3.1'
15
+ - '3.2'
16
+ os:
17
+ - ubuntu-latest
18
+ name: Ruby ${{ matrix.ruby }} unit testing on ${{ matrix.os }}
19
+ steps:
20
+ - uses: actions/checkout@v3
21
+ - uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby }}
24
+ - name: unit testing
25
+ env:
26
+ CI: true
27
+ run: |
28
+ gem install bundler rake
29
+ bundle install --jobs 4 --retry 3
30
+ bundle exec rake spec
data/ChangeLog CHANGED
@@ -1,3 +1,11 @@
1
+ Release 0.9.1 - 2023/12/20
2
+
3
+ * Fix invalid message polluting subsequent message
4
+
5
+ Release 0.9.0 - 2020/09/04
6
+
7
+ * FluentLogger supports TLS
8
+
1
9
  Release 0.8.2 - 2019/08/21
2
10
 
3
11
  * Block timeout during IO#write to avoid writing invalid bytes
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Fluent logger
2
2
 
3
- [![Build Status](https://travis-ci.org/fluent/fluent-logger-ruby.svg?branch=master)](https://travis-ci.org/fluent/fluent-logger-ruby)
3
+ [![Build Status](https://github.com/fluent/fluent-logger-ruby/actions/workflows/linux.yml/badge.svg?branch=master)](https://github.com/fluent/fluent-logger-ruby/actions/workflows/linux.yml)
4
4
 
5
5
  A structured event logger
6
6
 
@@ -82,6 +82,36 @@ end
82
82
  # output: myapp.access {"agent":"foo"}
83
83
  ```
84
84
 
85
+ ### TLS setting
86
+
87
+ ```ruby
88
+ require 'fluent-logger'
89
+
90
+ tls_opts = {
91
+ :ca => '/path/to/cacert.pem',
92
+ :cert => '/path/to/client-cert.pem',
93
+ :key => '/path/to/client-key.pem',
94
+ :key_passphrase => 'test'
95
+ }
96
+ log = Fluent::Logger::FluentLogger.new(nil, :host => 'localhost', :port => 24224, :tls_options => tls_opts)
97
+ ```
98
+
99
+ `in_forward` config example:
100
+
101
+ ```
102
+ <source>
103
+ @type forward
104
+ <transport tls>
105
+ version TLS1_2
106
+ ca_path /path/to/cacert.pem
107
+ cert_path /path/to/server-cert.pem
108
+ private_key_path /path/to/server-key.pem
109
+ private_key_passphrase test
110
+ client_cert_auth true
111
+ </transport>
112
+ </source>
113
+ ```
114
+
85
115
  ### Singleton
86
116
  ```ruby
87
117
  require 'fluent-logger'
@@ -122,6 +152,19 @@ If `false`, `Logger#post` raises an error when nonblocking write gets `EAGAIN` (
122
152
 
123
153
  Pass callback for handling buffer overflow with pending data. See "Buffer overflow" section.
124
154
 
155
+ #### tls_options (Hash)
156
+
157
+ Pass TLS related options.
158
+
159
+ - use_default_ca: Set `true` if you want to use default CA
160
+ - ca: CA file path
161
+ - cert: Certificate file path
162
+ - key: Private key file path
163
+ - key_passphrase: Private key passphrase
164
+ - version: TLS version. Default is `OpenSSL::SSL::TLS1_2_VERSION`
165
+ - ciphers: The list of cipher suites. Default is `ALL:!aNULL:!eNULL:!SSLv2`
166
+ - insecure: Set `true` when `in_forward` uses `insecure true`
167
+
125
168
  ### Standard ::Logger compatible interface
126
169
 
127
170
  #### Example1
@@ -202,7 +245,7 @@ Fluent::Logger::NullLogger.open
202
245
 
203
246
  To send events with nanosecond-precision time (Fluent 0.14 and up), specify `nanosecond_precision` to `FluentLogger` constructor.
204
247
 
205
- ```rb
248
+ ```ruby
206
249
  log = Fluent::Logger::FluentLogger.new(nil, :host => 'localhost', :port => 24224, :nanosecond_precision => true)
207
250
  # Use nanosecond time instead
208
251
  log.post("myapp.access", {"agent" => "foo"})
@@ -216,7 +259,7 @@ You can inject your own custom proc to handle buffer overflow in the event of co
216
259
  Your proc must accept a single argument, which will be the internal buffer of messages from the logger. A typical use-case for this would be writing to disk or possibly writing to Redis.
217
260
 
218
261
  ##### Example
219
- ```
262
+ ```ruby
220
263
  class BufferOverflowHandler
221
264
  attr_accessor :buffer
222
265
 
@@ -27,4 +27,5 @@ Gem::Specification.new do |gem|
27
27
  gem.add_development_dependency 'rspec-its', '>= 1.1.0'
28
28
  gem.add_development_dependency 'simplecov', '>= 0.5.4'
29
29
  gem.add_development_dependency 'timecop', '>= 0.3.0'
30
+ gem.add_development_dependency 'webrick'
30
31
  end
@@ -18,6 +18,7 @@
18
18
  require 'timeout'
19
19
  require 'msgpack'
20
20
  require 'socket'
21
+ require 'openssl'
21
22
  require 'monitor'
22
23
  require 'logger'
23
24
  require 'json'
@@ -84,6 +85,7 @@ module Fluent
84
85
  @socket_path = options[:socket_path]
85
86
  @nanosecond_precision = options[:nanosecond_precision]
86
87
  @use_nonblock = options[:use_nonblock]
88
+ @tls_options = options[:tls_options]
87
89
 
88
90
  @factory = MessagePack::Factory.new
89
91
  if @nanosecond_precision
@@ -169,6 +171,33 @@ module Fluent
169
171
  @con = UNIXSocket.new(@socket_path)
170
172
  else
171
173
  @con = TCPSocket.new(@host, @port)
174
+ if @tls_options
175
+ context = OpenSSL::SSL::SSLContext.new
176
+ if @tls_options[:insecure]
177
+ context.verify_mode = OpenSSL::SSL::VERIFY_NONE
178
+ else
179
+ context.set_params({})
180
+ context.verify_mode = OpenSSL::SSL::VERIFY_PEER
181
+ cert_store = OpenSSL::X509::Store.new
182
+ if @tls_options[:use_default_ca]
183
+ cert_store.set_default_paths
184
+ end
185
+ if @tls_options[:ca]
186
+ cert_store.add_file(@tls_options[:ca])
187
+ end
188
+
189
+ context.cert = OpenSSL::X509::Certificate.new(File.read(@tls_options[:cert])) if @tls_options[:cert]
190
+ context.key = OpenSSL::PKey::read(File.read(@tls_options[:key]), @tls_options[:key_passphrase]) if @tls_options[:key]
191
+ context.ciphers = @tls_options[:ciphers] || "ALL:!aNULL:!eNULL:!SSLv2".freeze
192
+ context.cert_store = cert_store
193
+ end
194
+ set_tls_version(context)
195
+
196
+ @con = OpenSSL::SSL::SSLSocket.new(@con, context)
197
+ @con.sync_close = true
198
+ @con.connect
199
+ end
200
+ @con
172
201
  end
173
202
  end
174
203
 
@@ -186,14 +215,25 @@ module Fluent
186
215
 
187
216
  private
188
217
 
218
+ def set_tls_version(context)
219
+ if context.respond_to?(:min_version=)
220
+ ver = @tls_options[:version] || OpenSSL::SSL::TLS1_2_VERSION
221
+ context.min_version = ver
222
+ context.max_version = ver
223
+ else
224
+ context.ssl_version = @tls_options[:version] || :'TLSv1_2'
225
+ end
226
+ end
227
+
189
228
  def to_msgpack(msg)
190
229
  @mon.synchronize {
191
230
  res = begin
192
231
  @packer.pack(msg).to_s
193
232
  rescue NoMethodError
194
233
  JSON.parse(JSON.generate(msg)).to_msgpack
234
+ ensure
235
+ @packer.clear
195
236
  end
196
- @packer.clear
197
237
  res
198
238
  }
199
239
  end
@@ -1,5 +1,5 @@
1
1
  module Fluent
2
2
  module Logger
3
- VERSION = '0.8.2'
3
+ VERSION = '0.9.1'
4
4
  end
5
5
  end
@@ -205,6 +205,10 @@ describe Fluent::Logger::FluentLogger do
205
205
  expect(fluentd.queue.last).to be_nil
206
206
  logger_io.rewind
207
207
  logger_io.read =~ /FluentLogger: Can't convert to msgpack:/
208
+
209
+ logger.post('tag', { 'a' => 'b' })
210
+ fluentd.wait_transfer
211
+ expect(fluentd.queue.last).to eq ['logger-test.tag', { 'a' => 'b' }]
208
212
  }
209
213
 
210
214
  it ('should raise an error when second argument is non hash object') {
@@ -373,4 +377,61 @@ describe Fluent::Logger::FluentLogger do
373
377
  end
374
378
  end
375
379
  end
380
+
381
+ context "running fluentd with TLS" do
382
+ before(:all) do
383
+ @serverengine = DummyServerengine.new
384
+ @serverengine.startup
385
+ end
386
+
387
+ before(:each) do
388
+ fluentd.startup(true)
389
+ # Make sure to wait TLS server since preparing it takes longer time than
390
+ # non-TLS so that it might be too early especially on CI environment
391
+ 3.times do
392
+ begin
393
+ TCPSocket.open('localhost', fluentd.port) {}
394
+ break
395
+ rescue
396
+ fluentd.wait_transfer
397
+ end
398
+ end
399
+ end
400
+
401
+ after(:each) do
402
+ fluentd.shutdown
403
+ end
404
+
405
+ after(:all) do
406
+ @serverengine.shutdown
407
+ end
408
+
409
+ let(:logger_config) {
410
+ {
411
+ :host => 'localhost',
412
+ :port => fluentd.port,
413
+ :logger => internal_logger,
414
+ :buffer_overflow_handler => buffer_overflow_handler,
415
+ :tls_options => {:insecure => true}
416
+ }
417
+ }
418
+
419
+ context('post') do
420
+ it ('success') {
421
+ expect(logger.pending_bytesize).to eq 0
422
+ expect(logger.post('tag', {'a' => 'b'})).to be true
423
+ fluentd.wait_transfer
424
+ expect(fluentd.queue.last).to eq ['logger-test.tag', {'a' => 'b'}]
425
+ expect(logger.pending_bytesize).to eq 0
426
+ }
427
+
428
+ it ('success with nanosecond') {
429
+ expect(logger_with_nanosec.pending_bytesize).to eq 0
430
+ expect(logger_with_nanosec.post('tag', {'a' => 'b'})).to be true
431
+ fluentd.wait_transfer
432
+ expect(fluentd.queue.last).to eq ['logger-test.tag', {'a' => 'b'}]
433
+ expect(fluentd.output.emits.first[1]).to be_a_kind_of(Fluent::EventTime)
434
+ }
435
+ end
436
+ end
376
437
  end
@@ -51,8 +51,22 @@ class DummyFluentd
51
51
  queue
52
52
  end
53
53
 
54
- def startup
55
- config = Fluent::Config.parse(<<EOF, '(logger-spec)', '(logger-spec-dir)', true)
54
+ def startup(with_tls = false)
55
+ if with_tls
56
+ config = Fluent::Config.parse(<<EOF, '(logger-spec)', '(logger-spec-dir)', true)
57
+ <source>
58
+ type forward
59
+ port #{port}
60
+ <transport tls>
61
+ insecure true
62
+ </transport>
63
+ </source>
64
+ <match logger-test.**>
65
+ type test
66
+ </match>
67
+ EOF
68
+ else
69
+ config = Fluent::Config.parse(<<EOF, '(logger-spec)', '(logger-spec-dir)', true)
56
70
  <source>
57
71
  type forward
58
72
  port #{port}
@@ -61,6 +75,8 @@ class DummyFluentd
61
75
  type test
62
76
  </match>
63
77
  EOF
78
+ end
79
+
64
80
  Fluent::Test.setup
65
81
  Fluent::Engine.run_configure(config)
66
82
  @coolio_default_loop = nil
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.2
4
+ version: 0.9.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-08-21 00:00:00.000000000 Z
11
+ date: 2023-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -100,6 +100,20 @@ dependencies:
100
100
  - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: 0.3.0
103
+ - !ruby/object:Gem::Dependency
104
+ name: webrick
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
103
117
  description: fluent logger for ruby
104
118
  email: frsyuki@gmail.com
105
119
  executables:
@@ -107,9 +121,9 @@ executables:
107
121
  extensions: []
108
122
  extra_rdoc_files: []
109
123
  files:
124
+ - ".github/workflows/linux.yml"
110
125
  - ".gitignore"
111
126
  - ".rspec"
112
- - ".travis.yml"
113
127
  - AUTHORS
114
128
  - COPYING
115
129
  - ChangeLog
@@ -161,20 +175,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
175
  - !ruby/object:Gem::Version
162
176
  version: '0'
163
177
  requirements: []
164
- rubygems_version: 3.0.3
178
+ rubygems_version: 3.4.1
165
179
  signing_key:
166
180
  specification_version: 4
167
181
  summary: fluent logger for ruby
168
- test_files:
169
- - spec/console_logger_spec.rb
170
- - spec/fluent_logger_spec.rb
171
- - spec/level_fluent_logger_spec.rb
172
- - spec/logger_base_spec.rb
173
- - spec/logger_spec.rb
174
- - spec/null_logger_spec.rb
175
- - spec/plugin/out_test.rb
176
- - spec/spec_helper.rb
177
- - spec/support/dummy_fluentd.rb
178
- - spec/support/dummy_serverengine.rb
179
- - spec/support/timecop.rb
180
- - spec/test_logger_spec.rb
182
+ test_files: []
data/.travis.yml DELETED
@@ -1,34 +0,0 @@
1
- rvm:
2
- - 2.1
3
- - 2.2
4
- - 2.3.7
5
- - 2.4.5
6
- - 2.5.3
7
- - 2.6.0
8
- - ruby-head
9
-
10
- gemfile:
11
- - Gemfile
12
- - Gemfile.v0.12
13
-
14
- before_install: gem update bundler
15
- script: bundle exec rake spec
16
-
17
- sudo: false
18
-
19
- matrix:
20
- allow_failures:
21
- - rvm: ruby-head
22
- exclude:
23
- - rvm: 2.2
24
- gemfile: Gemfile.v0.12
25
- - rvm: 2.3.7
26
- gemfile: Gemfile.v0.12
27
- - rvm: 2.4.5
28
- gemfile: Gemfile.v0.12
29
- - rvm: 2.5.3
30
- gemfile: Gemfile.v0.12
31
- - rvm: 2.6.0
32
- gemfile: Gemfile.v0.12
33
- - rvm: ruby-head
34
- gemfile: Gemfile.v0.12