logjam_agent 0.19.4 → 0.19.5

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: 4bffe54ae7a2f79b516804c95ecf2a2272d3b1b7
4
- data.tar.gz: 280a394d54ecf5d7fcb84dd78c15222746b77d2a
3
+ metadata.gz: 0279d90588ebec498f742e91649a69419e8d64cb
4
+ data.tar.gz: bd5268ff93c0f8d61f5bab144d815da2438c3432
5
5
  SHA512:
6
- metadata.gz: 00581356bef24ce775b29f9a201f2635909fb0fd36f73c9f0db2a741d40b3224d8557c2a7d57c17f964e4cffd2c213d78fa2c3a484fccdc4a5650cab6988362b
7
- data.tar.gz: be04344959f08f5ee808e12f0c8450984e2d02f7ffddef88ba62c65f8c1b38fa63d74aa2b9fcd73e1cb3fcffd08de3212daebc64a81266392d7b270bb2efcab6
6
+ metadata.gz: 32b4a9a97156a850fba99f585b53fec62b0aec9b1bf397e4cb3ceb419252886811eee5351a773b5f2b5ae8ecf9cd6ca39dc13a9f759500f2ecdb821b817615e0
7
+ data.tar.gz: ee8df18ee840b4d1dd79dc82ddf175eb3aae3cbb83886ee1d83b45cf5bfc9490d9c9186b9c01e7cc576ac75c1f78e5eaea9928eda0dedd9b98afb759706120cf
@@ -28,36 +28,38 @@ module LogjamAgent
28
28
  end
29
29
 
30
30
  # TODO: mutex!
31
- def forward(msg, options = {})
31
+ def forward(data, options = {})
32
32
  return if paused?
33
- begin
34
- app_env = options[:app_env] || @app_env
35
- key = options[:routing_key] || "logs.#{app_env.sub('-','.')}"
36
- if engine = options[:engine]
37
- key += ".#{engine}"
38
- end
39
- info = pack_info(@sequence = next_fixnum(@sequence))
40
- exchange(app_env).publish(msg, :key => key, :persistent => false, :headers => {:info => info})
41
- rescue => error
42
- reraise_expectation_errors!
43
- pause(error)
33
+ app_env = options[:app_env] || @app_env
34
+ key = options[:routing_key] || "logs.#{app_env.sub('-','.')}"
35
+ if engine = options[:engine]
36
+ key += ".#{engine}"
44
37
  end
38
+ msg = LogjamAgent.encode_payload(data)
39
+ publish(app_env, key, msg)
40
+ rescue => error
41
+ reraise_expectation_errors!
42
+ pause(error)
43
+ end
44
+
45
+ def publish(app_env, key, data)
46
+ info = pack_info(@sequence = next_fixnum(@sequence))
47
+ exchange(app_env).publish(data, :key => key, :persistent => false, :headers => {:info => info})
45
48
  end
46
49
 
47
50
  def reset(exception=nil)
48
51
  return unless @bunny
49
- begin
50
- if exception
51
- @bunny.__send__(:close_socket)
52
- else
53
- @bunny.stop
54
- end
55
- rescue
56
- # if bunny throws an exception here, its not usable anymore anyway
57
- ensure
58
- @exchanges = {}
59
- @bunny = nil
52
+ if exception
53
+ @bunny.__send__(:close_socket)
54
+ else
55
+ @bunny.stop
60
56
  end
57
+ rescue
58
+ # swallow StandardError
59
+ ensure
60
+ # if bunny throws an exception here, its not usable anymore anyway
61
+ @exchanges = {}
62
+ @bunny = nil
61
63
  end
62
64
 
63
65
  private
@@ -84,8 +84,7 @@ module LogjamAgent
84
84
  def forward
85
85
  return if @ignored || LogjamAgent.disabled
86
86
  engine = @fields.delete(:engine)
87
- # puts @fields.inspect
88
- @forwarder.forward(LogjamAgent.encode_payload(@fields), :engine => engine)
87
+ @forwarder.forward(@fields, :engine => engine)
89
88
  rescue Exception => e
90
89
  handle_forwarding_error(e)
91
90
  end
@@ -1,3 +1,3 @@
1
1
  module LogjamAgent
2
- VERSION = "0.19.4"
2
+ VERSION = "0.19.5"
3
3
  end
@@ -20,7 +20,7 @@ module LogjamAgent
20
20
  def default_options
21
21
  {
22
22
  :port => 9605,
23
- :linger => 100,
23
+ :linger => 1000,
24
24
  :snd_hwm => 100,
25
25
  }
26
26
  end
@@ -58,12 +58,13 @@ module LogjamAgent
58
58
  @socket = nil
59
59
  end
60
60
 
61
- def forward(msg, options={})
61
+ def forward(data, options={})
62
62
  app_env = options[:app_env] || @app_env
63
63
  key = options[:routing_key] || "logs.#{app_env.sub('-','.')}"
64
64
  if engine = options[:engine]
65
65
  key += ".#{engine}"
66
66
  end
67
+ msg = LogjamAgent.encode_payload(data)
67
68
  publish(app_env, key, msg)
68
69
  rescue => error
69
70
  reraise_expectation_errors!
data/logjam_agent.gemspec CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
24
24
  s.add_development_dependency "oj"
25
25
  s.add_development_dependency "byebug"
26
26
  s.add_development_dependency "minitest"
27
+ s.add_development_dependency "mocha"
27
28
 
28
29
  s.add_runtime_dependency "activesupport"
29
30
  s.add_runtime_dependency "time_bandits", [">= 0.6.0"]
@@ -0,0 +1,32 @@
1
+ require_relative "test_helper.rb"
2
+
3
+ module LogjamAgent
4
+ class AMQPForwarderTest < MiniTest::Test
5
+ def setup
6
+ AMQPForwarder.any_instance.expects(:ensure_bunny_gem_is_available)
7
+ end
8
+
9
+ def teardown
10
+ LogjamAgent.compression_method = NO_COMPRESSION
11
+ end
12
+
13
+ test "encodes the payload" do
14
+ data = {a: 1, b: "str"}
15
+ msg = LogjamAgent.encode_payload(data)
16
+ f = AMQPForwarder.new
17
+ f.expects(:publish).with("a-b", "x", msg)
18
+ f.forward(data, :routing_key => "x", :app_env => "a-b")
19
+ end
20
+
21
+ test "compressed message using snappy can be uncompressed" do
22
+ data = {a: 1, b: "str"}
23
+ normal_msg = LogjamAgent.encode_payload(data)
24
+ LogjamAgent.compression_method = SNAPPY_COMPRESSION
25
+ compressed_msg = LogjamAgent.encode_payload(data)
26
+ assert_equal normal_msg, Snappy.inflate(compressed_msg)
27
+ f = AMQPForwarder.new
28
+ f.expects(:publish).with("a-b", "x", compressed_msg)
29
+ f.forward(data, :routing_key => "x", :app_env => "a-b")
30
+ end
31
+ end
32
+ end
data/test/test_helper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'minitest/autorun'
2
2
  require 'minitest/unit'
3
3
  require 'minitest/pride' if ENV['RAINBOW_COLORED_TESTS'] == "1" && $stdout.tty?
4
- # require 'mocha/setup'
4
+ require 'mocha/setup'
5
5
 
6
6
  require_relative "../lib/logjam_agent"
7
7
 
@@ -3,6 +3,10 @@ require_relative "test_helper.rb"
3
3
  module LogjamAgent
4
4
  class ZMQForwarderTest < MiniTest::Test
5
5
 
6
+ def teardown
7
+ LogjamAgent.compression_method = NO_COMPRESSION
8
+ end
9
+
6
10
  test "sets up single connection with default port" do
7
11
  f = ZMQForwarder.new(:host => "a.b.c", :port => 3001)
8
12
  assert_equal ["tcp://a.b.c:3001"], f.connection_specs
@@ -13,5 +17,24 @@ module LogjamAgent
13
17
  assert_equal %w(tcp://a.b.c:9605 tcp://x.y.z:9000 tcp://zmq.gnu.org:600), f.connection_specs
14
18
  end
15
19
 
20
+ test "encodes the payload" do
21
+ data = {a: 1, b: "str"}
22
+ msg = LogjamAgent.encode_payload(data)
23
+ f = ZMQForwarder.new
24
+ f.expects(:publish).with("a-b", "x", msg)
25
+ f.forward(data, :routing_key => "x", :app_env => "a-b")
26
+ end
27
+
28
+ test "compressed message using snappy can be uncompressed" do
29
+ data = {a: 1, b: "str"}
30
+ normal_msg = LogjamAgent.encode_payload(data)
31
+ LogjamAgent.compression_method = SNAPPY_COMPRESSION
32
+ compressed_msg = LogjamAgent.encode_payload(data)
33
+ assert_equal normal_msg, Snappy.inflate(compressed_msg)
34
+ f = ZMQForwarder.new
35
+ f.expects(:publish).with("a-b", "x", compressed_msg)
36
+ f.forward(data, :routing_key => "x", :app_env => "a-b")
37
+ end
38
+
16
39
  end
17
40
  end
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.19.4
4
+ version: 0.19.5
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-05-10 00:00:00.000000000 Z
11
+ date: 2016-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: mocha
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: activesupport
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -148,6 +162,7 @@ files:
148
162
  - lib/logjam_agent/zmq_forwarder.rb
149
163
  - logjam_agent.gemspec
150
164
  - script/console
165
+ - test/amqp_forwarder_test.rb
151
166
  - test/test_helper.rb
152
167
  - test/util_test.rb
153
168
  - test/zmq_forwarder_test.rb
@@ -175,6 +190,7 @@ signing_key:
175
190
  specification_version: 4
176
191
  summary: Logjam client library to be used with logjam
177
192
  test_files:
193
+ - test/amqp_forwarder_test.rb
178
194
  - test/test_helper.rb
179
195
  - test/util_test.rb
180
196
  - test/zmq_forwarder_test.rb