logjam_agent 0.31.0 → 0.32.4
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/logjam_agent.rb +4 -6
- data/lib/logjam_agent/monkey_patches/ffi-rzmq-patch.rb +19 -0
- data/lib/logjam_agent/railtie.rb +2 -2
- data/lib/logjam_agent/version.rb +1 -1
- data/lib/logjam_agent/zmq_forwarder.rb +46 -34
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 882e0807f2b78aa878d7af652e4cb3ab6d0a77115e2add1792fc85091c629d15
|
4
|
+
data.tar.gz: 0500627f55dd0c1e10013db3e2cdba1c23f15b587d3ceb440fe2bd0921cd3a2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f37a0ce94d7a2cc233eb5ff2c9a84c39b2396b1c99a0349df185bae8716e46b24caf8e6d341bca6ed503914721b59142ee7db2221ada9d3c7a544c86648b80f8
|
7
|
+
data.tar.gz: d8c839977ec58a66e87381ca1cb76877988eacde9eaf59f7d4b2d102848c11c84ddc370c14bb1b0c559c1dab8e9a718de82a24d68982c61b94a49a69acd86fda
|
data/lib/logjam_agent.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "socket"
|
2
2
|
require "time_bandits"
|
3
|
+
require "logjam_agent/monkey_patches/ffi-rzmq-patch"
|
3
4
|
|
4
5
|
module LogjamAgent
|
5
6
|
module RequestHandling
|
@@ -76,12 +77,9 @@ module LogjamAgent
|
|
76
77
|
self.parameter_filters = []
|
77
78
|
|
78
79
|
def self.get_hostname
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
else
|
83
|
-
Socket.gethostbyname(n).first rescue n
|
84
|
-
end
|
80
|
+
name = Socket.gethostname
|
81
|
+
host = name.split('.').first
|
82
|
+
Addrinfo.getaddrinfo(host, nil, nil, :STREAM, nil, Socket::AI_CANONNAME).first.canonname rescue name
|
85
83
|
end
|
86
84
|
|
87
85
|
mattr_accessor :hostname
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# see https://github.com/chuckremes/ffi-rzmq/pull/133
|
2
|
+
|
3
|
+
require 'ffi-rzmq'
|
4
|
+
require 'ffi-rzmq/message'
|
5
|
+
|
6
|
+
module ZMQ
|
7
|
+
class Message
|
8
|
+
def copy_in_bytes bytes, len
|
9
|
+
data_buffer = LibC.malloc len
|
10
|
+
# writes the exact number of bytes, no null byte to terminate string
|
11
|
+
data_buffer.put_bytes 0, bytes, 0, len
|
12
|
+
|
13
|
+
# use libC to call free on the data buffer; earlier versions used an
|
14
|
+
# FFI::Function here that called back into Ruby, but Rubinius won't
|
15
|
+
# support that and there are issues with the other runtimes too
|
16
|
+
LibZMQ.zmq_msg_init_data @pointer, data_buffer, len, LibC::Free, nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/logjam_agent/railtie.rb
CHANGED
@@ -90,9 +90,9 @@ module LogjamAgent
|
|
90
90
|
# Rails 5 fires on_load events multiple times, so we need to protect against endless recursion
|
91
91
|
next if ActionController::TestCase::Behavior.instance_methods.include?(:process_without_logjam)
|
92
92
|
module ActionController::TestCase::Behavior
|
93
|
-
def process_with_logjam(
|
93
|
+
def process_with_logjam(action, **opts)
|
94
94
|
LogjamAgent.start_request
|
95
|
-
process_without_logjam(
|
95
|
+
process_without_logjam(action, **opts)
|
96
96
|
ensure
|
97
97
|
LogjamAgent.finish_request
|
98
98
|
end
|
data/lib/logjam_agent/version.rb
CHANGED
@@ -16,6 +16,7 @@ module LogjamAgent
|
|
16
16
|
@sequence = SEQUENCE_START
|
17
17
|
@socket = nil
|
18
18
|
@ping_ensured = false
|
19
|
+
@socket_mutex = Mutex.new
|
19
20
|
end
|
20
21
|
|
21
22
|
def connection_specs
|
@@ -35,11 +36,11 @@ module LogjamAgent
|
|
35
36
|
}
|
36
37
|
end
|
37
38
|
|
38
|
-
@@
|
39
|
+
@@context_mutex = Mutex.new
|
39
40
|
@@zmq_context = nil
|
40
41
|
|
41
42
|
def self.context
|
42
|
-
@@
|
43
|
+
@@context_mutex.synchronize do
|
43
44
|
@@zmq_context ||=
|
44
45
|
begin
|
45
46
|
require 'ffi-rzmq'
|
@@ -50,29 +51,9 @@ module LogjamAgent
|
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
53
|
-
def socket
|
54
|
-
return @socket if @socket
|
55
|
-
@socket = self.class.context.socket(ZMQ::DEALER)
|
56
|
-
raise "ZMQ error on socket creation: #{ZMQ::Util.error_string}" if @socket.nil?
|
57
|
-
if LogjamAgent.ensure_ping_at_exit
|
58
|
-
ensure_ping_at_exit
|
59
|
-
else
|
60
|
-
at_exit { reset }
|
61
|
-
end
|
62
|
-
@socket.setsockopt(ZMQ::LINGER, @config[:linger])
|
63
|
-
@socket.setsockopt(ZMQ::SNDHWM, @config[:snd_hwm])
|
64
|
-
@socket.setsockopt(ZMQ::RCVHWM, @config[:rcv_hwm])
|
65
|
-
@socket.setsockopt(ZMQ::RCVTIMEO, @config[:rcv_timeo])
|
66
|
-
@socket.setsockopt(ZMQ::SNDTIMEO, @config[:snd_timeo])
|
67
|
-
spec = connection_specs.sort_by{rand}.first
|
68
|
-
@socket.connect(spec)
|
69
|
-
@socket
|
70
|
-
end
|
71
|
-
|
72
54
|
def reset
|
73
|
-
|
74
|
-
|
75
|
-
@socket = nil
|
55
|
+
@socket_mutex.synchronize do
|
56
|
+
reset_without_locking
|
76
57
|
end
|
77
58
|
end
|
78
59
|
|
@@ -89,16 +70,47 @@ module LogjamAgent
|
|
89
70
|
key += ".#{engine}"
|
90
71
|
end
|
91
72
|
msg = LogjamAgent.encode_payload(data)
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
73
|
+
@socket_mutex.synchronize do
|
74
|
+
if options[:sync]
|
75
|
+
send_receive(app_env, key, msg)
|
76
|
+
else
|
77
|
+
publish(app_env, key, msg)
|
78
|
+
end
|
96
79
|
end
|
97
80
|
rescue => error
|
98
81
|
reraise_expectation_errors!
|
99
82
|
raise ForwardingError.new(error.message)
|
100
83
|
end
|
101
84
|
|
85
|
+
private
|
86
|
+
|
87
|
+
def reset_without_locking
|
88
|
+
if @socket
|
89
|
+
@socket.close
|
90
|
+
@socket = nil
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# this method assumes the caller holds the socket mutex
|
95
|
+
def socket
|
96
|
+
return @socket if @socket
|
97
|
+
@socket = self.class.context.socket(ZMQ::DEALER)
|
98
|
+
raise "ZMQ error on socket creation: #{ZMQ::Util.error_string}" if @socket.nil?
|
99
|
+
if LogjamAgent.ensure_ping_at_exit
|
100
|
+
ensure_ping_at_exit
|
101
|
+
else
|
102
|
+
at_exit { reset }
|
103
|
+
end
|
104
|
+
@socket.setsockopt(ZMQ::LINGER, @config[:linger])
|
105
|
+
@socket.setsockopt(ZMQ::SNDHWM, @config[:snd_hwm])
|
106
|
+
@socket.setsockopt(ZMQ::RCVHWM, @config[:rcv_hwm])
|
107
|
+
@socket.setsockopt(ZMQ::RCVTIMEO, @config[:rcv_timeo])
|
108
|
+
@socket.setsockopt(ZMQ::SNDTIMEO, @config[:snd_timeo])
|
109
|
+
spec = connection_specs.sort_by{rand}.first
|
110
|
+
@socket.connect(spec)
|
111
|
+
@socket
|
112
|
+
end
|
113
|
+
|
102
114
|
def publish(app_env, key, data)
|
103
115
|
info = pack_info(@sequence = next_fixnum(@sequence))
|
104
116
|
parts = [app_env, key, data, info]
|
@@ -109,8 +121,6 @@ module LogjamAgent
|
|
109
121
|
end
|
110
122
|
end
|
111
123
|
|
112
|
-
private
|
113
|
-
|
114
124
|
def log_warning(message)
|
115
125
|
LogjamAgent.error_handler.call ForwardingWarning.new(message)
|
116
126
|
end
|
@@ -123,12 +133,12 @@ module LogjamAgent
|
|
123
133
|
answer_parts = []
|
124
134
|
if socket.send_strings(request_parts) < 0
|
125
135
|
log_warning "ZMQ error on sending: #{ZMQ::Util.error_string}"
|
126
|
-
|
136
|
+
reset_without_locking
|
127
137
|
return nil
|
128
138
|
end
|
129
139
|
if socket.recv_strings(answer_parts) < 0
|
130
140
|
log_warning "ZMQ error on receiving: #{ZMQ::Util.error_string}"
|
131
|
-
|
141
|
+
reset_without_locking
|
132
142
|
return nil
|
133
143
|
end
|
134
144
|
if answer_parts.first != "" || !VALID_RESPONSE_CODES.include?(answer_parts.second.to_s.to_i)
|
@@ -138,8 +148,10 @@ module LogjamAgent
|
|
138
148
|
end
|
139
149
|
|
140
150
|
def ping
|
141
|
-
|
142
|
-
|
151
|
+
@socket_mutex.synchronize do
|
152
|
+
if @socket && !send_receive("ping", @app_env, "{}", NO_COMPRESSION)
|
153
|
+
log_warning "failed to receive pong"
|
154
|
+
end
|
143
155
|
end
|
144
156
|
end
|
145
157
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logjam_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.32.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Kaes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -236,6 +236,7 @@ files:
|
|
236
236
|
- lib/logjam_agent/buffered_logger.rb
|
237
237
|
- lib/logjam_agent/forwarders.rb
|
238
238
|
- lib/logjam_agent/middleware.rb
|
239
|
+
- lib/logjam_agent/monkey_patches/ffi-rzmq-patch.rb
|
239
240
|
- lib/logjam_agent/rack/logger.rb
|
240
241
|
- lib/logjam_agent/rack/rails_support.rb
|
241
242
|
- lib/logjam_agent/rack/sinatra_request.rb
|
@@ -274,7 +275,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
274
275
|
- !ruby/object:Gem::Version
|
275
276
|
version: '0'
|
276
277
|
requirements: []
|
277
|
-
rubygems_version: 3.
|
278
|
+
rubygems_version: 3.2.7
|
278
279
|
signing_key:
|
279
280
|
specification_version: 4
|
280
281
|
summary: Logjam client library to be used with logjam
|