log-courier 2.7.2 → 2.7.3

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: c318bee7d97ff215d852e8980301665d48d8b81a17f6806e2ecbaaa596d9e43f
4
- data.tar.gz: ad52cced8f9dad919a2521395db9fb442bb0535fed9b54ac555f9c140e70f917
3
+ metadata.gz: 3aa4bc695758102c35a9bc74cb856ec456b92715cb6f133592bfdeaa0a8a6a30
4
+ data.tar.gz: c5f67b639fca236f884f01f3054dc6e4b3292826051f1696cff324f80e6878ec
5
5
  SHA512:
6
- metadata.gz: 200421b7dae625c4cdd88bc08197a32db9f50248a2e661af785ebae47d84fdacde97413d8c67189fa3047c2611786e0a3fdc28d56547cc87c047c4e644f38cea
7
- data.tar.gz: 9ca5c1ef8145659c92a17d9ff0671ac2cc14900ef8d0a052f330055c1c4c55595065a37e0be045642fcd061c029206302f716df2e48012584720fd3622abac60
6
+ metadata.gz: e0826718c6e075b731d04f7f8c825aa0fd59b9d0045b58183009f42516e1f1a7b8465cd72af7d04603d8946e3240acba91101fe41cdb6bcc609856a8b50d171d
7
+ data.tar.gz: 372bbefcfd75d6de6139fc6b0d1901a77cb77609c104fe897d156b29c83edca6994abb9bf8a44a718d963e0b20a3127fe8d91615f0ae4aaff05cea1de31bbbf8
@@ -17,14 +17,10 @@
17
17
 
18
18
  require 'log-courier/event_queue'
19
19
  require 'log-courier/protocol'
20
+ require 'log-courier/version'
20
21
  require 'multi_json'
21
22
  require 'zlib'
22
23
 
23
- # Dummy until its no longer needed
24
- class NativeException
25
- def dummy; end
26
- end
27
-
28
24
  module LogCourier
29
25
  class TimeoutError < StandardError; end
30
26
 
@@ -349,7 +345,7 @@ module LogCourier
349
345
  @logger&.warn 'Timeout occurred'
350
346
  rescue ShutdownSignal
351
347
  raise
352
- rescue StandardError, NativeException => e
348
+ rescue StandardError => e
353
349
  # Unknown error occurred
354
350
  @logger&.warn e, hint: 'Unknown error'
355
351
  end
@@ -35,12 +35,12 @@ module LogCourier
35
35
 
36
36
  @logger = @options[:logger]
37
37
 
38
- [:port, :ssl_ca].each do |k|
39
- raise "output/courier: '#{k}' is required" if @options[k].nil?
40
- end
38
+ raise "output/courier: 'port' is required" if @options[:port].nil?
41
39
 
42
40
  return unless @options[:transport] == 'tls'
43
41
 
42
+ raise "output/courier: 'ssl_ca' is required if 'transport' is 'tls'" if @options[:ssl_ca].nil?
43
+
44
44
  c = 0
45
45
  [:ssl_certificate, :ssl_key].each do
46
46
  c += 1
@@ -71,7 +71,7 @@ module LogCourier
71
71
  run_send io_control
72
72
  rescue ShutdownSignal
73
73
  # Shutdown
74
- rescue StandardError, NativeException => e # Can remove NativeException after 9.2.14.0 JRuby
74
+ rescue StandardError => e
75
75
  @logger&.warn e, hint: 'Unknown write error'
76
76
  io_control << ['F']
77
77
  end
@@ -79,7 +79,7 @@ module LogCourier
79
79
  run_recv io_control
80
80
  rescue ShutdownSignal
81
81
  # Shutdown
82
- rescue StandardError, NativeException => e # Can remove NativeException after 9.2.14.0 JRuby
82
+ rescue StandardError => e
83
83
  @logger&.warn e, hint: 'Unknown read error'
84
84
  io_control << ['F']
85
85
  end
@@ -125,7 +125,7 @@ module LogCourier
125
125
  def handshake(io_control)
126
126
  return true if @options[:disable_handshake]
127
127
 
128
- @socket.write ['HELO', 20, 0, 2, 7, 2, 'RYLC'].pack('A4NNNNNA4')
128
+ @socket.write ['HELO', 20, 0, MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION, 'RYLC'].pack('A4NNNNNA4')
129
129
 
130
130
  signature, data = receive
131
131
  if signature != 'VERS'
@@ -140,7 +140,7 @@ module LogCourier
140
140
  @logger&.info 'Remote identified', server_version: @vers[:client_version]
141
141
 
142
142
  true
143
- rescue StandardError, NativeException => e # Can remove NativeException after 9.2.14.0 JRuby
143
+ rescue StandardError => e
144
144
  @logger&.warn e, hint: 'Unknown write error'
145
145
  io_control << ['F']
146
146
  false
@@ -177,7 +177,7 @@ module LogCourier
177
177
  rescue OpenSSL::SSL::SSLError => e
178
178
  @logger&.warn 'SSL write error', error: e.message
179
179
  io_control << ['F']
180
- rescue IOError, Errno::ECONNRESET => e
180
+ rescue IOError, SystemCallError => e
181
181
  @logger&.warn 'Write error', error: e.message
182
182
  io_control << ['F']
183
183
  end
@@ -195,7 +195,7 @@ module LogCourier
195
195
  rescue EOFError
196
196
  @logger&.warn 'Connection closed by server'
197
197
  io_control << ['F']
198
- rescue IOError, Errno::ECONNRESET => e
198
+ rescue IOError, SystemCallError => e
199
199
  @logger&.warn 'Read error', error: e.message
200
200
  io_control << ['F']
201
201
  end
@@ -271,15 +271,11 @@ module LogCourier
271
271
  @logger&.info 'Connected successfully', address: address, port: port
272
272
  end
273
273
 
274
- # Add extra logging data now we're connected
275
- @logger['address'] = address
276
- @logger['port'] = port
277
-
278
274
  return true
279
- rescue OpenSSL::SSL::SSLError, IOError, Errno::ECONNRESET => e
275
+ rescue OpenSSL::SSL::SSLError, IOError, SystemCallError => e
280
276
  @logger&.warn 'Connection failed', error: e.message, address: address, port: port
281
- rescue StandardError, NativeException => e # Can remove NativeException after 9.2.14.0 JRuby
282
- @logger&.warn e, hint: 'Unknown connection failure', address: address, port: port
277
+ rescue StandardError => e
278
+ @logger&.warn 'Unknown connection failure', hint: e.message, address: address, port: port
283
279
  end
284
280
 
285
281
  false
@@ -0,0 +1,217 @@
1
+ # Copyright 2014-2021 Jason Woods.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'cabin'
16
+ require 'log-courier/client'
17
+ require 'log-courier/server'
18
+
19
+ TEMP_PATH = File.join(File.dirname(__FILE__), 'tmp')
20
+ EVENT_WAIT_COUNT = 50
21
+ EVENT_WAIT_TIME = 0.5
22
+
23
+ # Common helpers for testing both ruby client and the courier
24
+ shared_context 'LogCourier' do
25
+ before :all do
26
+ Thread.abort_on_exception = true
27
+
28
+ FileUtils.rm_r(TEMP_PATH) if File.directory?(TEMP_PATH)
29
+ Dir.mkdir(TEMP_PATH)
30
+
31
+ @ssl_cert = File.open(File.join(TEMP_PATH, 'ssl_cert'), 'w')
32
+ @ssl_key = File.open(File.join(TEMP_PATH, 'ssl_key'), 'w')
33
+ @ssl_csr = File.open(File.join(TEMP_PATH, 'ssl_csr'), 'w')
34
+
35
+ # Generate the ssl key
36
+ cnf_path = "#{File.dirname(__FILE__)}/openssl.cnf"
37
+ system("openssl req -config #{cnf_path} -new -batch -keyout #{@ssl_key.path} -out #{@ssl_csr.path}")
38
+ system(
39
+ "openssl x509 -extfile #{cnf_path} -extensions extensions_section -req -days 365 -in #{@ssl_csr.path}" \
40
+ " -signkey #{@ssl_key.path} -out #{@ssl_cert.path}",
41
+ )
42
+ end
43
+
44
+ after :all do
45
+ FileUtils.rm_r(TEMP_PATH) if File.directory?(TEMP_PATH)
46
+ end
47
+
48
+ before :each do
49
+ @event_queue = SizedQueue.new 10_000
50
+
51
+ @clients = {}
52
+ @servers = {}
53
+ @server_counts = {}
54
+ @server_threads = {}
55
+ end
56
+
57
+ after :each do
58
+ unless @servers.length.zero?
59
+ id, = @servers.first
60
+ raise "Server was not shutdown: #{id}"
61
+ end
62
+ unless @clients.length.zero?
63
+ id, = @clients.first
64
+ raise "Client was not shutdown: #{id}"
65
+ end
66
+ end
67
+
68
+ def start_client(**args)
69
+ args = {
70
+ id: '__default__',
71
+ transport: 'tls',
72
+ addresses: ['127.0.0.1'],
73
+ }.merge!(**args)
74
+
75
+ args[:ssl_ca] = @ssl_cert.path if args[:transport] == 'tls'
76
+
77
+ id = args[:id]
78
+ args[:port] = server_port(id) unless args.key?(:port)
79
+
80
+ logger = Cabin::Channel.new
81
+ logger.subscribe $stdout
82
+ logger['instance'] = "Client #{id}"
83
+ logger.level = :debug
84
+
85
+ # Reset server for each test
86
+ @clients[id] = LogCourier::Client.new(
87
+ logger: logger,
88
+ **args,
89
+ )
90
+ end
91
+
92
+ def shutdown_client(which = nil)
93
+ which = if which.nil?
94
+ @clients.keys
95
+ else
96
+ [which]
97
+ end
98
+ which.each do |id|
99
+ @clients[id].shutdown
100
+ @clients.delete id
101
+ end
102
+ nil
103
+ end
104
+
105
+ def start_server(**args)
106
+ args = {
107
+ id: '__default__',
108
+ transport: 'tls',
109
+ }.merge!(**args)
110
+
111
+ if args[:transport] == 'tls'
112
+ args[:ssl_certificate] = @ssl_cert.path
113
+ args[:ssl_key] = @ssl_key.path
114
+ end
115
+
116
+ id = args[:id]
117
+
118
+ logger = Cabin::Channel.new
119
+ logger.subscribe $stdout
120
+ logger['instance'] = "Server #{id}"
121
+ logger.level = :debug
122
+
123
+ raise 'Server already initialised' if @servers.key?(id)
124
+
125
+ # Reset server for each test
126
+ @servers[id] = LogCourier::Server.new(
127
+ logger: logger,
128
+ **args,
129
+ )
130
+
131
+ @server_counts[id] = 0
132
+ @server_threads[id] = Thread.new do
133
+ @servers[id].run do |event|
134
+ @server_counts[id] += 1
135
+ @event_queue << event
136
+ end
137
+ rescue LogCourier::ShutdownSignal
138
+ 0
139
+ end
140
+ @servers[id]
141
+ end
142
+
143
+ # A helper to shutdown a Log Courier server
144
+ def shutdown_server(which = nil)
145
+ which = if which.nil?
146
+ @servers.keys
147
+ else
148
+ [which]
149
+ end
150
+ which.each do |id|
151
+ @server_threads[id].raise LogCourier::ShutdownSignal
152
+ @server_threads[id].join
153
+ @server_threads.delete id
154
+ @server_counts.delete id
155
+ @servers.delete id
156
+ end
157
+ nil
158
+ end
159
+
160
+ # A helper to get the port a server is bound to
161
+ def server_port(id = '__default__')
162
+ @servers[id].port
163
+ end
164
+
165
+ # A helper to get number of events received on the server
166
+ def server_count(id = '__default__')
167
+ @server_counts[id]
168
+ end
169
+
170
+ def receive_and_check(args = {})
171
+ args = {
172
+ total: nil,
173
+ check: true,
174
+ check_file: true,
175
+ check_order: true,
176
+ host: nil,
177
+ }.merge!(args)
178
+
179
+ # Quick check of the total events we are expecting - but allow time to receive them
180
+ total = if args[:total].nil?
181
+ @files.reduce(0) do |sum, f|
182
+ sum + f.count
183
+ end
184
+ else
185
+ args[:total]
186
+ end
187
+
188
+ args.delete_if do |_, v|
189
+ v.nil?
190
+ end
191
+
192
+ orig_total = total
193
+ check = args[:check]
194
+
195
+ waited = 0
196
+ while total.positive? && waited <= EVENT_WAIT_COUNT
197
+ if @event_queue.length.zero?
198
+ sleep(EVENT_WAIT_TIME)
199
+ waited += 1
200
+ next
201
+ end
202
+
203
+ waited = 0
204
+ until @event_queue.length.zero?
205
+ e = @event_queue.pop
206
+ total -= 1
207
+ next unless check
208
+
209
+ yield e
210
+ end
211
+ end
212
+
213
+ # Fancy calculation to give a nice "expected" output of expected num of events
214
+ expect(orig_total - total).to eq orig_total
215
+ nil
216
+ end
217
+ end
@@ -17,14 +17,10 @@
17
17
 
18
18
  require 'log-courier/event_queue'
19
19
  require 'log-courier/protocol'
20
+ require 'log-courier/version'
20
21
  require 'multi_json'
21
22
  require 'zlib'
22
23
 
23
- # NativeException in case it is missing
24
- class NativeException
25
- def dummy; end
26
- end
27
-
28
24
  module LogCourier
29
25
  class TimeoutError < StandardError; end
30
26
 
@@ -137,7 +137,7 @@ module LogCourier
137
137
  end
138
138
 
139
139
  @logger&.warn 'Ephemeral port allocated', transport: @options[:transport], port: @port if @options[:port].zero?
140
- rescue StandardError, NativeException => e # Until Jruby updated we need NativeException
140
+ rescue StandardError => e
141
141
  raise "input/courier: Failed to initialise: #{e}"
142
142
  end
143
143
  end
@@ -178,7 +178,7 @@ module LogCourier
178
178
  nil
179
179
  rescue ShutdownSignal
180
180
  nil
181
- rescue StandardError, NativeException => e # Can remove NativeException after 9.2.14.0 JRuby
181
+ rescue StandardError => e
182
182
  # Some other unknown problem
183
183
  @logger&.warn e.message, hint: 'Unknown error, shutting down'
184
184
  nil
@@ -275,7 +275,7 @@ module LogCourier
275
275
  # Read errors, only action is to shutdown which we'll do in ensure
276
276
  @logger&.warn 'SSL error, connection aborted', error: e.message, peer: @peer
277
277
  nil
278
- rescue IOError, Errno::ECONNRESET => e
278
+ rescue IOError, SystemCallError => e
279
279
  # Read errors, only action is to shutdown which we'll do in ensure
280
280
  @logger&.warn 'Connection aborted', error: e.message, peer: @peer
281
281
  nil
@@ -287,14 +287,14 @@ module LogCourier
287
287
  # Shutting down
288
288
  @logger&.info 'Server shutting down, closing connection', peer: @peer
289
289
  nil
290
- rescue StandardError, NativeException => e # Can remove NativeException after 9.2.14.0 JRuby
290
+ rescue StandardError => e
291
291
  # Some other unknown problem
292
292
  @logger&.warn e.message, hint: 'Unknown error, connection aborted', peer: @peer
293
293
  nil
294
294
  ensure
295
295
  begin
296
296
  @fd.close
297
- rescue OpenSSL::SSL::SSLError, IOError, NativeException
297
+ rescue OpenSSL::SSL::SSLError, IOError
298
298
  # Ignore during close
299
299
  end
300
300
  end
@@ -376,7 +376,7 @@ module LogCourier
376
376
  # Minor Version 4 bytes
377
377
  # Patch Version 4 bytes
378
378
  # Client String 4 bytes
379
- data = [0, 2, 7, 2, 'RYLC'].pack('NNNNA4')
379
+ data = [0, MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION, 'RYLC'].pack('NNNNA4')
380
380
  send 'VERS', data
381
381
  end
382
382
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log-courier
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.2
4
+ version: 2.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Woods
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-21 00:00:00.000000000 Z
11
+ date: 2021-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -49,9 +49,10 @@ files:
49
49
  - lib/log-courier/client_tcp.rb
50
50
  - lib/log-courier/event_queue.rb
51
51
  - lib/log-courier/protocol.rb
52
+ - lib/log-courier/rspec/spec_helper.rb
52
53
  - lib/log-courier/server.rb
53
54
  - lib/log-courier/server_tcp.rb
54
- homepage: https://github.com/driskell/ruby-log-courier
55
+ homepage: https://github.com/driskell/log-courier
55
56
  licenses:
56
57
  - Apache-2.0
57
58
  metadata: {}