log-courier 2.7.2 → 2.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/log-courier/client.rb +2 -6
- data/lib/log-courier/client_tcp.rb +12 -16
- data/lib/log-courier/rspec/spec_helper.rb +218 -0
- data/lib/log-courier/server.rb +1 -5
- data/lib/log-courier/server_tcp.rb +6 -6
- data/lib/log-courier/version.rb +7 -0
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbafa32351f4513cd8863a25bfbeeca97497d2b148f2350baf598f595205dffe
|
4
|
+
data.tar.gz: dddd5573b4d3908e0028652598ace3948bb0c516b2844c2d670940ad16f470cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ffa4c359125610432621adb716a6e25ef5c510436ff5a4d3501423815c8a5dbcf7873e4351fe30465110de37f422118f08dbd85d462f60829f4cbdcd3b5d33e
|
7
|
+
data.tar.gz: b10e56daebac839e8f320cd947ac04785154ec493e48efaa0228752412cb4e0728f75159a863fe4dbcc251dca9c8e2c7bf43e6755bb45b14436aad9b83bbcaa2
|
data/lib/log-courier/client.rb
CHANGED
@@ -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
|
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
|
-
|
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
|
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
|
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,
|
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
|
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,
|
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,
|
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,
|
275
|
+
rescue OpenSSL::SSL::SSLError, IOError, SystemCallError => e
|
280
276
|
@logger&.warn 'Connection failed', error: e.message, address: address, port: port
|
281
|
-
rescue StandardError
|
282
|
-
@logger&.warn
|
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,218 @@
|
|
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 'fileutils'
|
17
|
+
require 'log-courier/client'
|
18
|
+
require 'log-courier/server'
|
19
|
+
|
20
|
+
TEMP_PATH = File.join(File.dirname(__FILE__), 'tmp')
|
21
|
+
EVENT_WAIT_COUNT = 50
|
22
|
+
EVENT_WAIT_TIME = 0.5
|
23
|
+
|
24
|
+
# Common helpers for testing both ruby client and the courier
|
25
|
+
shared_context 'LogCourier' do
|
26
|
+
before :all do
|
27
|
+
Thread.abort_on_exception = true
|
28
|
+
|
29
|
+
FileUtils.rm_r(TEMP_PATH) if File.directory?(TEMP_PATH)
|
30
|
+
Dir.mkdir(TEMP_PATH)
|
31
|
+
|
32
|
+
@ssl_cert = File.open(File.join(TEMP_PATH, 'ssl_cert'), 'w')
|
33
|
+
@ssl_key = File.open(File.join(TEMP_PATH, 'ssl_key'), 'w')
|
34
|
+
@ssl_csr = File.open(File.join(TEMP_PATH, 'ssl_csr'), 'w')
|
35
|
+
|
36
|
+
# Generate the ssl key
|
37
|
+
cnf_path = "#{File.dirname(__FILE__)}/openssl.cnf"
|
38
|
+
system("openssl req -config #{cnf_path} -new -batch -keyout #{@ssl_key.path} -out #{@ssl_csr.path}")
|
39
|
+
system(
|
40
|
+
"openssl x509 -extfile #{cnf_path} -extensions extensions_section -req -days 365 -in #{@ssl_csr.path}" \
|
41
|
+
" -signkey #{@ssl_key.path} -out #{@ssl_cert.path}",
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
after :all do
|
46
|
+
FileUtils.rm_r(TEMP_PATH) if File.directory?(TEMP_PATH)
|
47
|
+
end
|
48
|
+
|
49
|
+
before :each do
|
50
|
+
@event_queue = SizedQueue.new 10_000
|
51
|
+
|
52
|
+
@clients = {}
|
53
|
+
@servers = {}
|
54
|
+
@server_counts = {}
|
55
|
+
@server_threads = {}
|
56
|
+
end
|
57
|
+
|
58
|
+
after :each do
|
59
|
+
unless @servers.length.zero?
|
60
|
+
id, = @servers.first
|
61
|
+
raise "Server was not shutdown: #{id}"
|
62
|
+
end
|
63
|
+
unless @clients.length.zero?
|
64
|
+
id, = @clients.first
|
65
|
+
raise "Client was not shutdown: #{id}"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def start_client(**args)
|
70
|
+
args = {
|
71
|
+
id: '__default__',
|
72
|
+
transport: 'tls',
|
73
|
+
addresses: ['127.0.0.1'],
|
74
|
+
}.merge!(**args)
|
75
|
+
|
76
|
+
args[:ssl_ca] = @ssl_cert.path if args[:transport] == 'tls'
|
77
|
+
|
78
|
+
id = args[:id]
|
79
|
+
args[:port] = server_port(id) unless args.key?(:port)
|
80
|
+
|
81
|
+
logger = Cabin::Channel.new
|
82
|
+
logger.subscribe $stdout
|
83
|
+
logger['instance'] = "Client #{id}"
|
84
|
+
logger.level = :debug
|
85
|
+
|
86
|
+
# Reset server for each test
|
87
|
+
@clients[id] = LogCourier::Client.new(
|
88
|
+
logger: logger,
|
89
|
+
**args,
|
90
|
+
)
|
91
|
+
end
|
92
|
+
|
93
|
+
def shutdown_client(which = nil)
|
94
|
+
which = if which.nil?
|
95
|
+
@clients.keys
|
96
|
+
else
|
97
|
+
[which]
|
98
|
+
end
|
99
|
+
which.each do |id|
|
100
|
+
@clients[id].shutdown
|
101
|
+
@clients.delete id
|
102
|
+
end
|
103
|
+
nil
|
104
|
+
end
|
105
|
+
|
106
|
+
def start_server(**args)
|
107
|
+
args = {
|
108
|
+
id: '__default__',
|
109
|
+
transport: 'tls',
|
110
|
+
}.merge!(**args)
|
111
|
+
|
112
|
+
if args[:transport] == 'tls'
|
113
|
+
args[:ssl_certificate] = @ssl_cert.path
|
114
|
+
args[:ssl_key] = @ssl_key.path
|
115
|
+
end
|
116
|
+
|
117
|
+
id = args[:id]
|
118
|
+
|
119
|
+
logger = Cabin::Channel.new
|
120
|
+
logger.subscribe $stdout
|
121
|
+
logger['instance'] = "Server #{id}"
|
122
|
+
logger.level = :debug
|
123
|
+
|
124
|
+
raise 'Server already initialised' if @servers.key?(id)
|
125
|
+
|
126
|
+
# Reset server for each test
|
127
|
+
@servers[id] = LogCourier::Server.new(
|
128
|
+
logger: logger,
|
129
|
+
**args,
|
130
|
+
)
|
131
|
+
|
132
|
+
@server_counts[id] = 0
|
133
|
+
@server_threads[id] = Thread.new do
|
134
|
+
@servers[id].run do |event|
|
135
|
+
@server_counts[id] += 1
|
136
|
+
@event_queue << event
|
137
|
+
end
|
138
|
+
rescue LogCourier::ShutdownSignal
|
139
|
+
0
|
140
|
+
end
|
141
|
+
@servers[id]
|
142
|
+
end
|
143
|
+
|
144
|
+
# A helper to shutdown a Log Courier server
|
145
|
+
def shutdown_server(which = nil)
|
146
|
+
which = if which.nil?
|
147
|
+
@servers.keys
|
148
|
+
else
|
149
|
+
[which]
|
150
|
+
end
|
151
|
+
which.each do |id|
|
152
|
+
@server_threads[id].raise LogCourier::ShutdownSignal
|
153
|
+
@server_threads[id].join
|
154
|
+
@server_threads.delete id
|
155
|
+
@server_counts.delete id
|
156
|
+
@servers.delete id
|
157
|
+
end
|
158
|
+
nil
|
159
|
+
end
|
160
|
+
|
161
|
+
# A helper to get the port a server is bound to
|
162
|
+
def server_port(id = '__default__')
|
163
|
+
@servers[id].port
|
164
|
+
end
|
165
|
+
|
166
|
+
# A helper to get number of events received on the server
|
167
|
+
def server_count(id = '__default__')
|
168
|
+
@server_counts[id]
|
169
|
+
end
|
170
|
+
|
171
|
+
def receive_and_check(args = {})
|
172
|
+
args = {
|
173
|
+
total: nil,
|
174
|
+
check: true,
|
175
|
+
check_file: true,
|
176
|
+
check_order: true,
|
177
|
+
host: nil,
|
178
|
+
}.merge!(args)
|
179
|
+
|
180
|
+
# Quick check of the total events we are expecting - but allow time to receive them
|
181
|
+
total = if args[:total].nil?
|
182
|
+
@files.reduce(0) do |sum, f|
|
183
|
+
sum + f.count
|
184
|
+
end
|
185
|
+
else
|
186
|
+
args[:total]
|
187
|
+
end
|
188
|
+
|
189
|
+
args.delete_if do |_, v|
|
190
|
+
v.nil?
|
191
|
+
end
|
192
|
+
|
193
|
+
orig_total = total
|
194
|
+
check = args[:check]
|
195
|
+
|
196
|
+
waited = 0
|
197
|
+
while total.positive? && waited <= EVENT_WAIT_COUNT
|
198
|
+
if @event_queue.length.zero?
|
199
|
+
sleep(EVENT_WAIT_TIME)
|
200
|
+
waited += 1
|
201
|
+
next
|
202
|
+
end
|
203
|
+
|
204
|
+
waited = 0
|
205
|
+
until @event_queue.length.zero?
|
206
|
+
e = @event_queue.pop
|
207
|
+
total -= 1
|
208
|
+
next unless check
|
209
|
+
|
210
|
+
yield e
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
# Fancy calculation to give a nice "expected" output of expected num of events
|
215
|
+
expect(orig_total - total).to eq orig_total
|
216
|
+
nil
|
217
|
+
end
|
218
|
+
end
|
data/lib/log-courier/server.rb
CHANGED
@@ -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
|
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
|
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,
|
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
|
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
|
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,
|
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,22 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: log-courier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Woods
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
+
name: cabin
|
14
15
|
requirement: !ruby/object:Gem::Requirement
|
15
16
|
requirements:
|
16
17
|
- - "~>"
|
17
18
|
- !ruby/object:Gem::Version
|
18
19
|
version: '0.6'
|
19
|
-
name: cabin
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -25,12 +25,12 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
+
name: multi_json
|
28
29
|
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
31
|
- - "~>"
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '1.10'
|
33
|
-
name: multi_json
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -49,9 +49,11 @@ 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
|
-
|
55
|
+
- lib/log-courier/version.rb
|
56
|
+
homepage: https://github.com/driskell/log-courier
|
55
57
|
licenses:
|
56
58
|
- Apache-2.0
|
57
59
|
metadata: {}
|
@@ -70,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
72
|
- !ruby/object:Gem::Version
|
71
73
|
version: '0'
|
72
74
|
requirements: []
|
73
|
-
rubygems_version: 3.
|
75
|
+
rubygems_version: 3.3.7
|
74
76
|
signing_key:
|
75
77
|
specification_version: 4
|
76
78
|
summary: Ruby implementation of the Courier protocol
|