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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0cca5098317b3d3338b67eb29ee6a1989acd7faf
4
- data.tar.gz: 41338b77ab2e005017455c9f26a9518a76d3ccb2
3
+ metadata.gz: 5b450bb1940271397b1a147f72691f2a57a00711
4
+ data.tar.gz: cf22fd46224d61afde9c0962498fb37c62366f03
5
5
  SHA512:
6
- metadata.gz: d348f5ca4f773be3539c7be4bb6ac973eb1b1fbb013447b1ad454cb19fff9bd331120a666bcb492544360672ea5636a8518908830fc13ef10a00b44a211268a4
7
- data.tar.gz: f26426cf92bac9d176ceacfed0c8bc8ac74df8d4c68cf1725627a0eddde98f5fefbbcb37119eb2f30e332c22d875c47a643e82a76b29347bc4be43ccaabf5a07
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. req_port, rcv_timeo and
44
- # snd_timeo options only apply for sychronous messages (LogjamAgent.event).
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 => 9605,
48
- :req_port => 9604,
47
+ :port => 9604,
49
48
  :linger => 1000,
50
- :snd_hwm => 100,
49
+ :snd_hwm => 100,
51
50
  :rcv_timeo => 5000,
52
51
  :snd_timeo => 5000)
53
52
 
@@ -39,7 +39,7 @@ module LogjamAgent
39
39
  end
40
40
 
41
41
  def next_fixnum(i)
42
- (i+=1) > FIXNUM_MAX ? 0 : i
42
+ (i+=1) > FIXNUM_MAX ? 1 : i
43
43
  end
44
44
 
45
45
  def pack_info(n)
@@ -1,3 +1,3 @@
1
1
  module LogjamAgent
2
- VERSION = "0.22.1"
2
+ VERSION = "0.23.0"
3
3
  end
@@ -16,27 +16,20 @@ module LogjamAgent
16
16
  @sequence = SEQUENCE_START
17
17
  end
18
18
 
19
- def push_connection_specs
20
- @push_connection_specs ||= @config[:host].split(',').map do |host|
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
- :req_port => 9604,
34
- :port => 9605,
35
- :linger => 1000,
36
- :snd_hwm => 100,
37
- :rcv_hwm => 100,
38
- :rcv_timeo => 5000,
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 push_socket
59
- return @push_socket if @push_socket
60
- @push_socket = self.class.context.socket(ZMQ::PUSH)
61
- at_exit { reset_push_socket }
62
- @push_socket.setsockopt(ZMQ::LINGER, @config[:linger])
63
- @push_socket.setsockopt(ZMQ::SNDHWM, @config[:snd_hwm])
64
- push_connection_specs.each do |spec|
65
- @push_socket.connect(spec)
66
- end
67
- @push_socket
68
- end
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
- reset_push_socket
104
- reset_req_socket
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 push_socket.send_strings(parts, ZMQ::DONTWAIT) < 0
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
- # we don't need sequencing for synchronous calls
140
- info = pack_info(SEQUENCE_START)
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
- # we retry a few times relying on zeromq lib to pick servers to talk to
144
- 3.times do
145
- if req_socket.send_strings(request_parts) < 0
146
- log_warning "ZMQ error on sending: #{ZMQ::Util.error_string}"
147
- reset_req_socket
148
- next
149
- end
150
- if req_socket.recv_strings(answer_parts) < 0
151
- log_warning "ZMQ error on receiving: #{ZMQ::Util.error_string}"
152
- reset_req_socket
153
- next
154
- end
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)
@@ -7,24 +7,14 @@ module LogjamAgent
7
7
  LogjamAgent.compression_method = NO_COMPRESSION
8
8
  end
9
9
 
10
- test "sets up single push connection with default port" do
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.push_connection_specs
12
+ assert_equal ["tcp://a.b.c:3001"], f.connection_specs
13
13
  end
14
14
 
15
- test "sets up multiple push connections" do
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:9605 tcp://x.y.z:9000 tcp://zmq.gnu.org:600), f.push_connection_specs
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.22.1
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-07-12 00:00:00.000000000 Z
11
+ date: 2016-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake