log-courier 1.7 → 1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/log-courier/client.rb +12 -2
- data/lib/log-courier/client_tcp.rb +9 -13
- data/lib/log-courier/server.rb +28 -8
- data/lib/log-courier/server_tcp.rb +30 -21
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a5972c2f6899a0d26511058691ed121394b6291
|
4
|
+
data.tar.gz: 53f55e097ba17fc459287af1665def25abee39df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c9a0a52422e2604018625abb2b5af6b47ffcce01d9e5288b99fae0c077da13a45890af868a99347ea98f596abcbe8d1cdfd3622cc82914150093a858e13cc50
|
7
|
+
data.tar.gz: 20ba9debdee92a7375bfc92a7863a93e3836b1a1013948088d50315cfdf8e1158e6976a9793f44e8600d674c4fa7a2a56bb9d2eada680b1d6ed658ca0f9bb39b
|
data/lib/log-courier/client.rb
CHANGED
@@ -31,11 +31,21 @@ module LogCourier
|
|
31
31
|
|
32
32
|
# Describes a pending payload
|
33
33
|
class PendingPayload
|
34
|
+
# TODO(driskell): Consolidate singleton into another file
|
34
35
|
class << self
|
35
36
|
@json_adapter
|
37
|
+
@json_parseerror
|
38
|
+
|
36
39
|
def get_json_adapter
|
37
40
|
@json_adapter = MultiJson.adapter.instance if @json_adapter.nil?
|
38
|
-
|
41
|
+
@json_adapter
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_json_parseerror
|
45
|
+
if @json_parseerror.nil?
|
46
|
+
@json_parseerror = get_json_adapter.class::ParseError
|
47
|
+
end
|
48
|
+
@json_parseerror
|
39
49
|
end
|
40
50
|
end
|
41
51
|
|
@@ -66,7 +76,7 @@ module LogCourier
|
|
66
76
|
end
|
67
77
|
|
68
78
|
# Generate and store the payload
|
69
|
-
@payload = nonce + buffer.
|
79
|
+
@payload = nonce + buffer.finish()
|
70
80
|
@last_sequence = 0
|
71
81
|
@sequence_len = @events.length
|
72
82
|
end
|
@@ -68,12 +68,20 @@ module LogCourier
|
|
68
68
|
begin
|
69
69
|
run_send io_control
|
70
70
|
rescue ShutdownSignal
|
71
|
+
rescue StandardError, NativeException => e
|
72
|
+
@logger.warn e, :hint => 'Unknown write error' unless @logger.nil?
|
73
|
+
io_control << ['F']
|
74
|
+
return
|
71
75
|
end
|
72
76
|
end
|
73
77
|
@recv_thread = Thread.new do
|
74
78
|
begin
|
75
79
|
run_recv io_control
|
76
80
|
rescue ShutdownSignal
|
81
|
+
rescue StandardError, NativeException => e
|
82
|
+
@logger.warn e, :hint => 'Unknown read error' unless @logger.nil?
|
83
|
+
io_control << ['F']
|
84
|
+
return
|
77
85
|
end
|
78
86
|
end
|
79
87
|
return
|
@@ -151,12 +159,6 @@ module LogCourier
|
|
151
159
|
@logger.warn 'Write error', :error => e.message unless @logger.nil?
|
152
160
|
io_control << ['F']
|
153
161
|
return
|
154
|
-
rescue ShutdownSignal
|
155
|
-
raise
|
156
|
-
rescue StandardError, NativeException => e
|
157
|
-
@logger.warn e, :hint => 'Unknown write error' unless @logger.nil?
|
158
|
-
io_control << ['F']
|
159
|
-
return
|
160
162
|
end
|
161
163
|
|
162
164
|
def run_recv(io_control)
|
@@ -194,12 +196,6 @@ module LogCourier
|
|
194
196
|
@logger.warn 'Connection closed by server' unless @logger.nil?
|
195
197
|
io_control << ['F']
|
196
198
|
return
|
197
|
-
rescue ShutdownSignal
|
198
|
-
raise
|
199
|
-
rescue StandardError, NativeException => e
|
200
|
-
@logger.warn e, :hint => 'Unknown read error' unless @logger.nil?
|
201
|
-
io_control << ['F']
|
202
|
-
return
|
203
199
|
end
|
204
200
|
|
205
201
|
def tls_connect
|
@@ -234,7 +230,7 @@ module LogCourier
|
|
234
230
|
ssl.cert_store = cert_store
|
235
231
|
ssl.verify_mode = OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT
|
236
232
|
|
237
|
-
@ssl_client = OpenSSL::SSL::SSLSocket.new(tcp_socket)
|
233
|
+
@ssl_client = OpenSSL::SSL::SSLSocket.new(tcp_socket, ssl)
|
238
234
|
|
239
235
|
socket = @ssl_client.connect
|
240
236
|
|
data/lib/log-courier/server.rb
CHANGED
@@ -33,6 +33,24 @@ module LogCourier
|
|
33
33
|
class Server
|
34
34
|
attr_reader :port
|
35
35
|
|
36
|
+
# TODO(driskell): Consolidate singleton into another file
|
37
|
+
class << self
|
38
|
+
@json_adapter
|
39
|
+
@json_parseerror
|
40
|
+
|
41
|
+
def get_json_adapter
|
42
|
+
@json_adapter = MultiJson.adapter.instance if @json_adapter.nil?
|
43
|
+
@json_adapter
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_json_parseerror
|
47
|
+
if @json_parseerror.nil?
|
48
|
+
@json_parseerror = get_json_adapter.class::ParseError
|
49
|
+
end
|
50
|
+
@json_parseerror
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
36
54
|
def initialize(options = {})
|
37
55
|
@options = {
|
38
56
|
logger: nil,
|
@@ -54,10 +72,6 @@ module LogCourier
|
|
54
72
|
|
55
73
|
# Grab the port back and update the logger context
|
56
74
|
@port = @server.port
|
57
|
-
|
58
|
-
# Load the json adapter
|
59
|
-
@json_adapter = MultiJson.adapter.instance
|
60
|
-
@json_options = { raw: true }
|
61
75
|
end
|
62
76
|
|
63
77
|
def run(&block)
|
@@ -165,17 +179,23 @@ module LogCourier
|
|
165
179
|
data_buf.force_encoding('utf-8')
|
166
180
|
|
167
181
|
# Ensure valid encoding
|
182
|
+
invalid_encodings = 0
|
168
183
|
unless data_buf.valid_encoding?
|
169
184
|
data_buf.chars.map do |c|
|
170
|
-
c.valid_encoding?
|
185
|
+
if c.valid_encoding?
|
186
|
+
c
|
187
|
+
else
|
188
|
+
invalid_encodings += 1
|
189
|
+
"\xEF\xBF\xBD"
|
190
|
+
end
|
171
191
|
end
|
172
192
|
end
|
173
193
|
|
174
194
|
# Decode the JSON
|
175
195
|
begin
|
176
|
-
event =
|
177
|
-
rescue
|
178
|
-
@logger.warn e, :hint => 'JSON parse failure, falling back to plain-text' unless @logger.nil?
|
196
|
+
event = self.class.get_json_adapter.load(data_buf, :raw => true)
|
197
|
+
rescue self.class.get_json_parseerror => e
|
198
|
+
@logger.warn e, :invalid_encodings => invalid_encodings, :hint => 'JSON parse failure, falling back to plain-text' unless @logger.nil?
|
179
199
|
event = { 'message' => data_buf }
|
180
200
|
end
|
181
201
|
|
@@ -188,19 +188,25 @@ module LogCourier
|
|
188
188
|
private
|
189
189
|
|
190
190
|
def run_thread(client, peer, &block)
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
191
|
+
begin
|
192
|
+
# Perform the handshake inside the new thread so we don't block TCP accept
|
193
|
+
if @options[:transport] == 'tls'
|
194
|
+
begin
|
195
|
+
client.accept
|
196
|
+
rescue EOFError, OpenSSL::SSL::SSLError, IOError => e
|
197
|
+
# Handshake failure or other issue
|
198
|
+
@logger.warn 'Connection failed to initialise', :error => e.message, :peer => peer unless @logger.nil?
|
199
|
+
client.close
|
200
|
+
return
|
201
|
+
end
|
200
202
|
end
|
201
|
-
end
|
202
203
|
|
203
|
-
|
204
|
+
ConnectionTcp.new(@logger, client, peer, @options).run(&block)
|
205
|
+
rescue ShutdownSignal
|
206
|
+
# Shutting down
|
207
|
+
@logger.info 'Server shutting down, connection closed', :peer => peer unless @logger.nil?
|
208
|
+
return
|
209
|
+
end
|
204
210
|
end
|
205
211
|
end
|
206
212
|
|
@@ -228,7 +234,19 @@ module LogCourier
|
|
228
234
|
event.merge! @peer_fields if @peer_fields.length != 0
|
229
235
|
end
|
230
236
|
|
231
|
-
def run
|
237
|
+
def run(&block)
|
238
|
+
process_messages &block
|
239
|
+
rescue ShutdownSignal
|
240
|
+
# Shutting down
|
241
|
+
@logger.info 'Server shutting down, closing connection', :peer => @peer unless @logger.nil?
|
242
|
+
return
|
243
|
+
rescue StandardError, NativeException => e
|
244
|
+
# Some other unknown problem
|
245
|
+
@logger.warn e, :hint => 'Unknown error, connection aborted', :peer => @peer unless @logger.nil?
|
246
|
+
return
|
247
|
+
end
|
248
|
+
|
249
|
+
def process_messages
|
232
250
|
loop do
|
233
251
|
# Read messages
|
234
252
|
# Each message begins with a header
|
@@ -258,7 +276,6 @@ module LogCourier
|
|
258
276
|
# If we EOF next it's a graceful close
|
259
277
|
@in_progress = false
|
260
278
|
end
|
261
|
-
return
|
262
279
|
rescue TimeoutError
|
263
280
|
# Timeout of the connection, we were idle too long without a ping/pong
|
264
281
|
@logger.warn 'Connection timed out', :peer => @peer unless @logger.nil?
|
@@ -282,14 +299,6 @@ module LogCourier
|
|
282
299
|
# Connection abort request due to a protocol error
|
283
300
|
@logger.warn 'Protocol error, connection aborted', :error => e.message, :peer => @peer unless @logger.nil?
|
284
301
|
return
|
285
|
-
rescue ShutdownSignal
|
286
|
-
# Shutting down
|
287
|
-
@logger.info 'Server shutting down, closing connection', :peer => @peer unless @logger.nil?
|
288
|
-
return
|
289
|
-
rescue StandardError, NativeException => e
|
290
|
-
# Some other unknown problem
|
291
|
-
@logger.warn e, :hint => 'Unknown error, connection aborted', :peer => @peer unless @logger.nil?
|
292
|
-
return
|
293
302
|
ensure
|
294
303
|
@fd.close rescue nil
|
295
304
|
end
|
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: '1.
|
4
|
+
version: '1.8'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Woods
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06
|
11
|
+
date: 2015-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cabin
|