logjam_agent 0.22.1 → 0.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -5
- data/lib/logjam_agent/util.rb +1 -1
- data/lib/logjam_agent/version.rb +1 -1
- data/lib/logjam_agent/zmq_forwarder.rb +41 -79
- data/test/zmq_forwarder_test.rb +4 -14
- 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: 5b450bb1940271397b1a147f72691f2a57a00711
|
4
|
+
data.tar.gz: cf22fd46224d61afde9c0962498fb37c62366f03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 382bc6ae715dc409925743184e07910c1148a5131eaf99341367b87c7b01b10715a5b6b0c04b4900eeb41bbc4288376cb03970538546457e94c530b137c13c73
|
7
|
+
data.tar.gz: 1a637b93221de09270e83fa98640f813b670e51b80b67f123f22e741928d828838a6062a5cf1cf1eea493800061e4240b3d796f9458c4f0682a41a6bb5d09651
|
data/README.md
CHANGED
@@ -40,14 +40,13 @@ module LogjamAgent
|
|
40
40
|
|
41
41
|
# Configure request data forwarder for ZeroMQ. Default options as given below.
|
42
42
|
# The host parameter can be a comma separted list of zmq connection specifictions,
|
43
|
-
# where the protocol prefix and port suffix are optional.
|
44
|
-
# snd_timeo options only apply for sychronous messages
|
43
|
+
# where the protocol prefix and port suffix are optional. rcv_timeo and
|
44
|
+
# snd_timeo options only apply for sychronous messages.
|
45
45
|
add_forwarder(:zmq,
|
46
46
|
:host => "localhost",
|
47
|
-
:port =>
|
48
|
-
:req_port => 9604,
|
47
|
+
:port => 9604,
|
49
48
|
:linger => 1000,
|
50
|
-
:snd_hwm =>
|
49
|
+
:snd_hwm => 100,
|
51
50
|
:rcv_timeo => 5000,
|
52
51
|
:snd_timeo => 5000)
|
53
52
|
|
data/lib/logjam_agent/util.rb
CHANGED
data/lib/logjam_agent/version.rb
CHANGED
@@ -16,27 +16,20 @@ module LogjamAgent
|
|
16
16
|
@sequence = SEQUENCE_START
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
@
|
19
|
+
def connection_specs
|
20
|
+
@connection_specs ||= @config[:host].split(',').map do |host|
|
21
21
|
augment_connection_spec(host, @config[:port])
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def req_connection_specs
|
26
|
-
@req_connection_specs ||= @config[:host].split(',').sort_by{rand}.map do |host|
|
27
|
-
augment_connection_spec(host, @config[:req_port])
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
25
|
def default_options
|
32
26
|
{
|
33
|
-
:
|
34
|
-
:
|
35
|
-
:
|
36
|
-
:
|
37
|
-
:
|
38
|
-
:
|
39
|
-
:snd_timeo => 5000
|
27
|
+
:port => 9604,
|
28
|
+
:linger => 1000,
|
29
|
+
:snd_hwm => 100,
|
30
|
+
:rcv_hwm => 100,
|
31
|
+
:rcv_timeo => 5000,
|
32
|
+
:snd_timeo => 5000
|
40
33
|
}
|
41
34
|
end
|
42
35
|
|
@@ -55,53 +48,26 @@ module LogjamAgent
|
|
55
48
|
end
|
56
49
|
end
|
57
50
|
|
58
|
-
def
|
59
|
-
return @
|
60
|
-
@
|
61
|
-
at_exit {
|
62
|
-
@
|
63
|
-
@
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
alias socket push_socket
|
70
|
-
|
71
|
-
def req_socket
|
72
|
-
return @req_socket if @req_socket
|
73
|
-
@req_socket = self.class.context.socket(ZMQ::REQ)
|
74
|
-
at_exit { reset_req_socket }
|
75
|
-
@req_socket.setsockopt(ZMQ::LINGER, @config[:linger])
|
76
|
-
@req_socket.setsockopt(ZMQ::SNDHWM, @config[:snd_hwm])
|
77
|
-
@req_socket.setsockopt(ZMQ::RCVHWM, @config[:rcv_hwm])
|
78
|
-
@req_socket.setsockopt(ZMQ::RCVTIMEO, @config[:rcv_timeo])
|
79
|
-
@req_socket.setsockopt(ZMQ::SNDTIMEO, @config[:snd_timeo])
|
80
|
-
# @req_socket.setsockopt(ZMQ::REQ_CORRELATE, 1)
|
81
|
-
# @req_socket.setsockopt(ZMQ::REQ_RELAXED, 1)
|
82
|
-
req_connection_specs.each do |spec|
|
83
|
-
@req_socket.connect(spec)
|
84
|
-
end
|
85
|
-
@req_socket
|
86
|
-
end
|
87
|
-
|
88
|
-
def reset_push_socket
|
89
|
-
if @push_socket
|
90
|
-
@push_socket.close
|
91
|
-
@push_socket = nil
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
def reset_req_socket
|
96
|
-
if @req_socket
|
97
|
-
@req_socket.close
|
98
|
-
@req_socket = nil
|
51
|
+
def socket
|
52
|
+
return @socket if @socket
|
53
|
+
@socket = self.class.context.socket(ZMQ::DEALER)
|
54
|
+
at_exit { reset }
|
55
|
+
@socket.setsockopt(ZMQ::LINGER, @config[:linger])
|
56
|
+
@socket.setsockopt(ZMQ::SNDHWM, @config[:snd_hwm])
|
57
|
+
@socket.setsockopt(ZMQ::RCVHWM, @config[:rcv_hwm])
|
58
|
+
@socket.setsockopt(ZMQ::RCVTIMEO, @config[:rcv_timeo])
|
59
|
+
@socket.setsockopt(ZMQ::SNDTIMEO, @config[:snd_timeo])
|
60
|
+
connection_specs.each do |spec|
|
61
|
+
@socket.connect(spec)
|
99
62
|
end
|
63
|
+
@socket
|
100
64
|
end
|
101
65
|
|
102
66
|
def reset
|
103
|
-
|
104
|
-
|
67
|
+
if @socket
|
68
|
+
@socket.close
|
69
|
+
@socket = nil
|
70
|
+
end
|
105
71
|
end
|
106
72
|
|
107
73
|
def forward(data, options={})
|
@@ -124,7 +90,7 @@ module LogjamAgent
|
|
124
90
|
def publish(app_env, key, data)
|
125
91
|
info = pack_info(@sequence = next_fixnum(@sequence))
|
126
92
|
parts = [app_env, key, data, info]
|
127
|
-
if
|
93
|
+
if socket.send_strings(parts, ZMQ::DONTWAIT) < 0
|
128
94
|
raise "ZMQ error on publishing: #{ZMQ::Util.error_string}"
|
129
95
|
end
|
130
96
|
end
|
@@ -135,29 +101,25 @@ module LogjamAgent
|
|
135
101
|
LogjamAgent.error_handler.call ForwardingWarning.new(message)
|
136
102
|
end
|
137
103
|
|
104
|
+
VALID_RESPONSE_CODES = [200,202]
|
105
|
+
|
138
106
|
def send_receive(app_env, key, data)
|
139
|
-
|
140
|
-
|
141
|
-
request_parts = [app_env, key, data, info]
|
107
|
+
info = pack_info(@sequence = next_fixnum(@sequence))
|
108
|
+
request_parts = ["", app_env, key, data, info]
|
142
109
|
answer_parts = []
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
return if answer_parts.first == "200 OK"
|
156
|
-
answer_parts.clear
|
110
|
+
if socket.send_strings(request_parts) < 0
|
111
|
+
log_warning "ZMQ error on sending: #{ZMQ::Util.error_string}"
|
112
|
+
reset
|
113
|
+
return
|
114
|
+
end
|
115
|
+
if socket.recv_strings(answer_parts) < 0
|
116
|
+
log_warning "ZMQ error on receiving: #{ZMQ::Util.error_string}"
|
117
|
+
reset
|
118
|
+
return
|
119
|
+
end
|
120
|
+
if answer_parts.first != "" || !VALID_RESPONSE_CODES.include?(answer_parts.second.to_s.to_i)
|
121
|
+
log_warning "unexpected answer from logjam broker: #{answer_parts.inspect}"
|
157
122
|
end
|
158
|
-
# if synchronous publishing fails, we just fall back to async
|
159
|
-
log_warning "could not publish sychronously, falling back to async"
|
160
|
-
publish(app_env, key, data)
|
161
123
|
end
|
162
124
|
|
163
125
|
if defined?(Mocha)
|
data/test/zmq_forwarder_test.rb
CHANGED
@@ -7,24 +7,14 @@ module LogjamAgent
|
|
7
7
|
LogjamAgent.compression_method = NO_COMPRESSION
|
8
8
|
end
|
9
9
|
|
10
|
-
test "sets up single
|
10
|
+
test "sets up single connection with default port" do
|
11
11
|
f = ZMQForwarder.new(:host => "a.b.c", :port => 3001)
|
12
|
-
assert_equal ["tcp://a.b.c:3001"], f.
|
12
|
+
assert_equal ["tcp://a.b.c:3001"], f.connection_specs
|
13
13
|
end
|
14
14
|
|
15
|
-
test "sets up multiple
|
15
|
+
test "sets up multiple connections" do
|
16
16
|
f = ZMQForwarder.new(:host => "a.b.c,tcp://x.y.z:9000,zmq.gnu.org:600")
|
17
|
-
assert_equal %w(tcp://a.b.c:
|
18
|
-
end
|
19
|
-
|
20
|
-
test "sets up single req connection with default port" do
|
21
|
-
f = ZMQForwarder.new(:host => "a.b.c", :req_port => 3001)
|
22
|
-
assert_equal ["tcp://a.b.c:3001"], f.req_connection_specs
|
23
|
-
end
|
24
|
-
|
25
|
-
test "sets up multiple req connections" do
|
26
|
-
f = ZMQForwarder.new(:host => "a.b.c,tcp://x.y.z:9000,zmq.gnu.org:600")
|
27
|
-
assert_equal %w(tcp://a.b.c:9604 tcp://x.y.z:9000 tcp://zmq.gnu.org:600).sort, f.req_connection_specs.sort
|
17
|
+
assert_equal %w(tcp://a.b.c:9604 tcp://x.y.z:9000 tcp://zmq.gnu.org:600), f.connection_specs
|
28
18
|
end
|
29
19
|
|
30
20
|
test "encodes the payload" do
|
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.23.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Kaes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|