logjam_agent 0.10.2 → 0.11.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/lib/logjam_agent/amqp_forwarder.rb +8 -4
- data/lib/logjam_agent/util.rb +55 -0
- data/lib/logjam_agent/version.rb +1 -1
- data/lib/logjam_agent/zmq_forwarder.rb +5 -1
- data/lib/logjam_agent.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c30b74711dc78c0beb70361f01b1bf9ea0b12445
|
4
|
+
data.tar.gz: f43e5841691c3c66b0be5a7ef57bd69c97ef6eb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7dcfd56d0d814e70368f0b1c4012fed93c7c327ce9b798f76490c06ab38fa878b0ed7b2498ac001b120482f0a65bd64a2a9e3b48b52a2e3611d30ef97fd4011
|
7
|
+
data.tar.gz: 79382ec2f801f546bcbc9f9b0c95c77e0700b10b96b4fa1bec0d2f61093563d1beb780662d7e4ba4c1760c2a7552ad9dbb1bcde1e76fa69885c913f113e46245
|
@@ -5,12 +5,15 @@ module LogjamAgent
|
|
5
5
|
|
6
6
|
attr_reader :app, :env
|
7
7
|
|
8
|
+
include LogjamAgent::Util
|
9
|
+
|
8
10
|
def initialize(*args)
|
9
11
|
opts = args.extract_options!
|
10
12
|
@app = args[0] || LogjamAgent.application_name
|
11
13
|
@env = args[1] || LogjamAgent.environment_name
|
12
14
|
@config = default_options(@app, @env).merge!(opts)
|
13
15
|
@exchange = @bunny = nil
|
16
|
+
@sequence = 0
|
14
17
|
ensure_bunny_gem_is_available
|
15
18
|
end
|
16
19
|
|
@@ -33,10 +36,11 @@ module LogjamAgent
|
|
33
36
|
if engine = options[:engine]
|
34
37
|
key += ".#{engine}"
|
35
38
|
end
|
36
|
-
|
37
|
-
|
39
|
+
info = pack_info(@sequence = next_fixnum(@sequence))
|
40
|
+
exchange.publish(msg, :key => key, :persistent => false, :headers => {:info => info})
|
41
|
+
rescue => error
|
38
42
|
reraise_expectation_errors!
|
39
|
-
pause(
|
43
|
+
pause(error)
|
40
44
|
end
|
41
45
|
end
|
42
46
|
|
@@ -48,7 +52,7 @@ module LogjamAgent
|
|
48
52
|
else
|
49
53
|
@bunny.stop
|
50
54
|
end
|
51
|
-
rescue
|
55
|
+
rescue
|
52
56
|
# if bunny throws an exception here, its not usable anymore anyway
|
53
57
|
ensure
|
54
58
|
@exchange = @bunny = nil
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module LogjamAgent
|
2
|
+
module Util
|
3
|
+
# copied from amqp protocol gem (slightly modified)
|
4
|
+
BIG_ENDIAN = ([1].pack("s") == "\x00\x01")
|
5
|
+
|
6
|
+
UINT64 = "Q"
|
7
|
+
|
8
|
+
# we assume we're running on MRI ruby
|
9
|
+
FIXNUM_MAX = 2 ** (1.size * 8 - 2) - 1
|
10
|
+
|
11
|
+
if BIG_ENDIAN
|
12
|
+
|
13
|
+
def pack_uint64_big_endian(uint64)
|
14
|
+
[uint64].pack(UINT64)
|
15
|
+
end
|
16
|
+
|
17
|
+
def unpack_uint64_big_endian(string)
|
18
|
+
string.unpack(UINT64)
|
19
|
+
end
|
20
|
+
|
21
|
+
else
|
22
|
+
|
23
|
+
def pack_uint64_big_endian(uint64)
|
24
|
+
[uint64].pack(UINT64).bytes.map(&:chr).reverse.join
|
25
|
+
end
|
26
|
+
|
27
|
+
def unpack_uint64_big_endian(string)
|
28
|
+
string.bytes.map(&:chr).reverse.join.unpack(UINT64)[0]
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
def zclock_time(t = Time.now)
|
34
|
+
t.tv_sec*1000 + t.tv_usec/1000
|
35
|
+
end
|
36
|
+
|
37
|
+
def next_fixnum(i)
|
38
|
+
(i+=1) > FIXNUM_MAX ? 0 : i
|
39
|
+
end
|
40
|
+
|
41
|
+
def pack_info(n)
|
42
|
+
info = pack_uint64_big_endian(zclock_time)
|
43
|
+
info << pack_uint64_big_endian(n)
|
44
|
+
end
|
45
|
+
|
46
|
+
def unpack_info(info)
|
47
|
+
zclock = unpack_uint64_big_endian(info[0..7])
|
48
|
+
secs = zclock / 1000
|
49
|
+
msecs = zclock % 1000
|
50
|
+
sent = Time.at(secs) + 1000.0/msecs
|
51
|
+
sequence = unpack_uint64_big_endian(info[8..15])
|
52
|
+
[sent, sequence]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/logjam_agent/version.rb
CHANGED
@@ -2,6 +2,8 @@ module LogjamAgent
|
|
2
2
|
class ZMQForwarder
|
3
3
|
attr_reader :app, :env
|
4
4
|
|
5
|
+
include Util
|
6
|
+
|
5
7
|
def initialize(*args)
|
6
8
|
opts = args.extract_options!
|
7
9
|
@app = args[0] || LogjamAgent.application_name
|
@@ -10,6 +12,7 @@ module LogjamAgent
|
|
10
12
|
@app_env = "#{@app}-#{@env}"
|
11
13
|
@zmq_hosts = Array(@config[:host])
|
12
14
|
@zmq_port = @config[:port]
|
15
|
+
@sequence = 0
|
13
16
|
end
|
14
17
|
|
15
18
|
def default_options(app, env)
|
@@ -71,7 +74,8 @@ module LogjamAgent
|
|
71
74
|
end
|
72
75
|
|
73
76
|
def publish(key, data)
|
74
|
-
|
77
|
+
info = pack_info(@sequence = next_fixnum(@sequence))
|
78
|
+
parts = [@app_env, key, data, info]
|
75
79
|
if socket.send_strings(parts, ZMQ::DONTWAIT) < 0
|
76
80
|
raise "ZMQ error: #{ZMQ::Util.error_string}"
|
77
81
|
end
|
data/lib/logjam_agent.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logjam_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Kaes
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- lib/logjam_agent/railtie.rb
|
87
87
|
- lib/logjam_agent/request.rb
|
88
88
|
- lib/logjam_agent/syslog_like_formatter.rb
|
89
|
+
- lib/logjam_agent/util.rb
|
89
90
|
- lib/logjam_agent/version.rb
|
90
91
|
- lib/logjam_agent/zmq_forwarder.rb
|
91
92
|
- logjam_agent.gemspec
|