sensu-transport 4.0.0 → 5.0.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: 1ce225a451ad7f61802de97848a4cc88153f3ebb
4
- data.tar.gz: 2a206e0652fc6c6735a86aeb7be35b218ee14c0d
3
+ metadata.gz: 6ddf38a57a53500e8ce070c590f8d97abf95ca38
4
+ data.tar.gz: d4077218d37391f5b88ff1bbd52857062838f17d
5
5
  SHA512:
6
- metadata.gz: 24be969e850d8a38bdf898a01c61a4923e970a77cf38bc31b4ef0e2b771785fdc7fca9bbb6b848383f3dc9d467a568666b0b2a43384ba0979465919a656ce196
7
- data.tar.gz: 52c1e08b2a6daf56195866c649e465951a3f925f0267c7e3c42101659ba8d4941c7e34f5c5c8a5312db23419269e8e42a73a46f3187085734698270f943884a9
6
+ metadata.gz: 445b1f8dcf4720f5cfb624547c14efa7b4058600ab0ec462a60479ed24e738fbd5af9c5a027eafb602be7e67b27ca42d626c3f9168c651493076ce6b83884bb3
7
+ data.tar.gz: 589e362b85523ec6bf53913acdb4e191c89e9e2b51463484278b8004703ab10c195ad0f62953997bec0c31416c2f5f260f9d37bfa73dbb4d1e1dfaac76ad3cd7
data/.travis.yml CHANGED
@@ -1,12 +1,12 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 1.8.7
5
- - 1.9.2
6
- - 1.9.3
7
4
  - 2.0.0
8
5
  - 2.1.0
9
- - jruby-1.7.18
6
+ - 2.2.0
7
+ - 2.2.3
8
+ - 2.3.0
9
+ - jruby-1.7.23
10
10
  services:
11
11
  - rabbitmq
12
12
  - redis
@@ -12,6 +12,8 @@ module Sensu
12
12
  #
13
13
  # @param transport_name [String] transport name.
14
14
  # @param options [Hash] transport options.
15
+ # @yield [Object] passes initialized and connected connection
16
+ # object to the callback/block.
15
17
  def connect(transport_name, options={})
16
18
  require("sensu/transport/#{transport_name}")
17
19
  klass = Base.descendants.detect do |klass|
@@ -20,7 +22,9 @@ module Sensu
20
22
  transport = klass.new
21
23
  transport.logger = @logger
22
24
  transport.connect(options)
23
- transport
25
+ transport.callback do
26
+ yield(transport)
27
+ end
24
28
  end
25
29
  end
26
30
  end
@@ -5,6 +5,11 @@ module Sensu
5
5
  class Error < StandardError; end
6
6
 
7
7
  class Base
8
+ # Transports are deferrable objects. This is to enable callbacks
9
+ # to be called in the event the transport calls `succeed()` to
10
+ # indicate that it has initialized and connected successfully.
11
+ include EM::Deferrable
12
+
8
13
  # @!attribute [rw] logger
9
14
  # @return [Logger] the Sensu logger object.
10
15
  attr_accessor :logger
@@ -8,7 +8,9 @@ require File.join(File.dirname(__FILE__), "patches", "amqp")
8
8
  module Sensu
9
9
  module Transport
10
10
  class RabbitMQ < Base
11
- # RabbitMQ connection setup.
11
+ # RabbitMQ connection setup. The deferred status is set to
12
+ # `:succeeded` (via `succeed()`) once the connection has been
13
+ # established.
12
14
  #
13
15
  # @param options [Hash, String]
14
16
  def connect(options={})
@@ -190,6 +192,7 @@ module Sensu
190
192
  @connection.logger = @logger
191
193
  @connection.on_open do
192
194
  @connection_timeout.cancel
195
+ succeed
193
196
  yield if block_given?
194
197
  end
195
198
  @connection.on_tcp_connection_loss(&reconnect_callback)
@@ -200,7 +203,7 @@ module Sensu
200
203
  @channel = AMQP::Channel.new(@connection)
201
204
  @channel.auto_recovery = true
202
205
  @channel.on_error do |channel, channel_close|
203
- error = Error.new("rabbitmq channel closed")
206
+ error = Error.new("rabbitmq channel error")
204
207
  @on_error.call(error)
205
208
  end
206
209
  prefetch = 1
@@ -229,6 +232,7 @@ module Sensu
229
232
  end
230
233
  rescue EventMachine::ConnectionError
231
234
  rescue Java::JavaLang::RuntimeException
235
+ rescue Java::JavaNioChannels::UnresolvedAddressException
232
236
  end
233
237
  end
234
238
  end
@@ -1,11 +1,10 @@
1
- require "em-redis-unified"
1
+ require "sensu/redis"
2
2
 
3
3
  require File.join(File.dirname(__FILE__), "base")
4
4
 
5
5
  module Sensu
6
6
  module Transport
7
7
  class Redis < Base
8
-
9
8
  # The Redis keyspace to use for the transport.
10
9
  REDIS_KEYSPACE = "transport"
11
10
 
@@ -15,13 +14,18 @@ module Sensu
15
14
  super
16
15
  end
17
16
 
18
- # Redis transport connection setup. This method sets `@options`
19
- # and creates a named Redis connection "redis".
17
+ # Redis transport connection setup. This method sets `@options`,
18
+ # creates a named Redis connection "redis", and sets the deferred
19
+ # status to `:succeeded` via `succeed()`.
20
20
  #
21
21
  # @param options [Hash, String]
22
22
  def connect(options={})
23
23
  @options = options || {}
24
- redis_connection("redis")
24
+ redis_connection("redis") do |connection|
25
+ connection.callback do
26
+ succeed
27
+ end
28
+ end
25
29
  end
26
30
 
27
31
  # Reconnect to the Redis transport. The Redis connections used
@@ -134,12 +138,14 @@ module Sensu
134
138
  # @yield [info] passes list stats to the callback/block.
135
139
  # @yieldparam info [Hash] contains list stats.
136
140
  def stats(funnel, options={})
137
- redis_connection("redis").llen(funnel) do |messages|
138
- info = {
139
- :messages => messages,
140
- :consumers => 0
141
- }
142
- yield(info)
141
+ redis_connection("redis") do |connection|
142
+ connection.llen(funnel) do |messages|
143
+ info = {
144
+ :messages => messages,
145
+ :consumers => 0
146
+ }
147
+ yield(info)
148
+ end
143
149
  end
144
150
  end
145
151
 
@@ -178,18 +184,23 @@ module Sensu
178
184
  # up the connection and before adding it to the pool.
179
185
  #
180
186
  # @param name [String] the Redis connection name.
181
- # @return [Object]
187
+ # @yield [Object] passes the named connection object to the
188
+ # callback/block.
182
189
  def redis_connection(name)
183
- return @connections[name] if @connections[name]
184
- connection = EM::Protocols::Redis.connect(@options)
185
- connection.auto_reconnect = false
186
- connection.reconnect_on_error = false
187
- connection.on_error do |error|
188
- @on_error.call(error)
190
+ if @connections[name]
191
+ yield(@connections[name])
192
+ else
193
+ Sensu::Redis.connect(@options) do |connection|
194
+ connection.auto_reconnect = false
195
+ connection.reconnect_on_error = false
196
+ connection.on_error do |error|
197
+ @on_error.call(error)
198
+ end
199
+ monitor_connections
200
+ @connections[name] = connection
201
+ yield(connection)
202
+ end
189
203
  end
190
- monitor_connections
191
- @connections[name] = connection
192
- connection
193
204
  end
194
205
 
195
206
  # Create a Redis key within the defined Redis keyspace. This
@@ -219,9 +230,11 @@ module Sensu
219
230
  # @yieldparam subscribers [String] current subscriber count.
220
231
  def pubsub_publish(pipe, message)
221
232
  channel = redis_key("channel", pipe)
222
- redis_connection("redis").publish(channel, message) do |subscribers|
223
- info = {:subscribers => subscribers}
224
- yield(info) if block_given?
233
+ redis_connection("redis") do |connection|
234
+ connection.publish(channel, message) do |subscribers|
235
+ info = {:subscribers => subscribers}
236
+ yield(info) if block_given?
237
+ end
225
238
  end
226
239
  end
227
240
 
@@ -244,15 +257,17 @@ module Sensu
244
257
  # @yieldparam message [String] message content.
245
258
  def pubsub_subscribe(pipe)
246
259
  channel = redis_key("channel", pipe)
247
- redis_connection("pubsub").subscribe(channel) do |type, channel, message|
248
- case type
249
- when "subscribe"
250
- @logger.debug("subscribed to redis channel: #{channel}") if @logger
251
- when "unsubscribe"
252
- @logger.debug("unsubscribed from redis channel: #{channel}") if @logger
253
- when "message"
254
- info = {:channel => channel}
255
- yield(info, message)
260
+ redis_connection("pubsub") do |connection|
261
+ connection.subscribe(channel) do |type, channel, message|
262
+ case type
263
+ when "subscribe"
264
+ @logger.debug("subscribed to redis channel: #{channel}") if @logger
265
+ when "unsubscribe"
266
+ @logger.debug("unsubscribed from redis channel: #{channel}") if @logger
267
+ when "message"
268
+ info = {:channel => channel}
269
+ yield(info, message)
270
+ end
256
271
  end
257
272
  end
258
273
  end
@@ -269,9 +284,11 @@ module Sensu
269
284
  # @yieldparam queued [String] current list size.
270
285
  def list_publish(pipe, message)
271
286
  list = redis_key("list", pipe)
272
- redis_connection("redis").rpush(list, message) do |queued|
273
- info = {:queued => queued}
274
- yield(info) if block_given?
287
+ redis_connection("redis") do |connection|
288
+ connection.rpush(list, message) do |queued|
289
+ info = {:queued => queued}
290
+ yield(info) if block_given?
291
+ end
275
292
  end
276
293
  end
277
294
 
@@ -288,9 +305,11 @@ module Sensu
288
305
  # @yieldparam info [Hash] an empty hash.
289
306
  # @yieldparam message [String] message content.
290
307
  def list_blpop(list, &callback)
291
- redis_connection(list).blpop(list, 0) do |_, message|
292
- EM::next_tick { list_blpop(list, &callback) }
293
- callback.call({}, message)
308
+ redis_connection(list) do |connection|
309
+ connection.blpop(list, 0) do |_, message|
310
+ EM::next_tick { list_blpop(list, &callback) }
311
+ callback.call({}, message)
312
+ end
294
313
  end
295
314
  end
296
315
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "sensu-transport"
5
- spec.version = "4.0.0"
5
+ spec.version = "5.0.0"
6
6
  spec.authors = ["Sean Porter"]
7
7
  spec.email = ["portertech@gmail.com"]
8
8
  spec.summary = "The Sensu transport abstraction library"
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.add_dependency("eventmachine")
19
19
  spec.add_dependency("amq-protocol", "1.9.2")
20
20
  spec.add_dependency("amqp", "1.5.0")
21
- spec.add_dependency("em-redis-unified", ">= 1.0.0")
21
+ spec.add_dependency("sensu-redis", ">= 1.0.0")
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.6"
24
24
  spec.add_development_dependency "rake"
@@ -8,22 +8,44 @@ describe "Sensu::Transport" do
8
8
  it "can load and connect to the rabbitmq transport" do
9
9
  async_wrapper do
10
10
  options = {}
11
- transport = Sensu::Transport.connect("rabbitmq", options)
12
- timer(1) do
11
+ Sensu::Transport.connect("rabbitmq", options) do |transport|
13
12
  expect(transport.connected?).to be(true)
14
13
  async_done
15
14
  end
16
15
  end
17
16
  end
18
17
 
19
- it "can set the transport logger" do
18
+ it "can load and connect to the redis transport" do
19
+ async_wrapper do
20
+ options = {}
21
+ Sensu::Transport.connect("redis", options) do |transport|
22
+ expect(transport.connected?).to be(true)
23
+ async_done
24
+ end
25
+ end
26
+ end
27
+
28
+ it "can set the rabbitmq transport logger" do
29
+ async_wrapper do
30
+ logger = Logger.new(STDOUT)
31
+ Sensu::Transport.logger = logger
32
+ Sensu::Transport.connect("rabbitmq") do |transport|
33
+ expect(transport.logger).to eq(logger)
34
+ expect(transport.logger).to respond_to(:error)
35
+ async_done
36
+ end
37
+ end
38
+ end
39
+
40
+ it "can set the redis transport logger" do
20
41
  async_wrapper do
21
42
  logger = Logger.new(STDOUT)
22
43
  Sensu::Transport.logger = logger
23
- transport = Sensu::Transport.connect("rabbitmq")
24
- expect(transport.logger).to eq(logger)
25
- expect(transport.logger).to respond_to(:error)
26
- async_done
44
+ Sensu::Transport.connect("redis") do |transport|
45
+ expect(transport.logger).to eq(logger)
46
+ expect(transport.logger).to respond_to(:error)
47
+ async_done
48
+ end
27
49
  end
28
50
  end
29
51
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-transport
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Porter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-22 00:00:00.000000000 Z
11
+ date: 2016-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.5.0
55
55
  - !ruby/object:Gem::Dependency
56
- name: em-redis-unified
56
+ name: sensu-redis
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="