sensu-transport 4.0.0 → 5.0.0
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/.travis.yml +4 -4
- data/lib/sensu/transport.rb +5 -1
- data/lib/sensu/transport/base.rb +5 -0
- data/lib/sensu/transport/rabbitmq.rb +6 -2
- data/lib/sensu/transport/redis.rb +58 -39
- data/sensu-transport.gemspec +2 -2
- data/spec/transport_spec.rb +29 -7
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ddf38a57a53500e8ce070c590f8d97abf95ca38
|
4
|
+
data.tar.gz: d4077218d37391f5b88ff1bbd52857062838f17d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 445b1f8dcf4720f5cfb624547c14efa7b4058600ab0ec462a60479ed24e738fbd5af9c5a027eafb602be7e67b27ca42d626c3f9168c651493076ce6b83884bb3
|
7
|
+
data.tar.gz: 589e362b85523ec6bf53913acdb4e191c89e9e2b51463484278b8004703ab10c195ad0f62953997bec0c31416c2f5f260f9d37bfa73dbb4d1e1dfaac76ad3cd7
|
data/.travis.yml
CHANGED
data/lib/sensu/transport.rb
CHANGED
@@ -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
|
data/lib/sensu/transport/base.rb
CHANGED
@@ -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
|
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 "
|
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
|
-
#
|
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")
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
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
|
-
# @
|
187
|
+
# @yield [Object] passes the named connection object to the
|
188
|
+
# callback/block.
|
182
189
|
def redis_connection(name)
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
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")
|
223
|
-
|
224
|
-
|
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")
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
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")
|
273
|
-
|
274
|
-
|
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)
|
292
|
-
|
293
|
-
|
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
|
|
data/sensu-transport.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "sensu-transport"
|
5
|
-
spec.version = "
|
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("
|
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"
|
data/spec/transport_spec.rb
CHANGED
@@ -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
|
-
|
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
|
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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
+
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-
|
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:
|
56
|
+
name: sensu-redis
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|