logjam_agent 0.11.1 → 0.11.2

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: d8ac86d7887f904a1a41d57bf8b77eb69019d7f2
4
- data.tar.gz: e5ad10647f5ef3eea08c4b9e73ba0b797969ff45
3
+ metadata.gz: 72a34b22839e58224f3a3fa8fd1630c31fe66167
4
+ data.tar.gz: a2549cab27b6cd2c8437b48f9a7f41258440bd97
5
5
  SHA512:
6
- metadata.gz: f7b1184a841e9bae84f4c31463c25c2888ec841b049d18be4e7f82c6ff2581ed3f6b4edc99656ec84a04feba1fd88c9e8042ec7ab24be64f59413e8a9fbda06f
7
- data.tar.gz: 32cfaf66cc6db7aa5ae9fa4609b9d2f547f45d3905955434c820274eee41f53d05cebe203cd2336cd0467e28ce04caef6da1bc5e8564680583fe5e51903c26c3
6
+ metadata.gz: 85b8e013121eca92a8b06227c63be49c111ed3397fbe29c15bc3d14e8553d9ce97b1f7054371d8ecddec81aa6c534bb95c194cf4a62951cf318200011c6112f2
7
+ data.tar.gz: 5c007b20a6b1c7318cc167895bd66734f2dc6d1e24b9a6ae6b451d9141577bafc78ed73fe2b3fc18e4a41c7442ebf921c74003316c6107a4d1117408e9387927
@@ -11,19 +11,19 @@ module LogjamAgent
11
11
  opts = args.extract_options!
12
12
  @app = args[0] || LogjamAgent.application_name
13
13
  @env = args[1] || LogjamAgent.environment_name
14
- @config = default_options(@app, @env).merge!(opts)
15
- @exchange = @bunny = nil
14
+ @app_env = "#{@app}-#{@env}"
15
+ @config = default_options.merge!(opts)
16
+ @exchanges = {}
17
+ @bunny = nil
16
18
  @sequence = 0
17
19
  ensure_bunny_gem_is_available
18
20
  end
19
21
 
20
- def default_options(app, env)
22
+ def default_options
21
23
  {
22
24
  :host => "localhost",
23
- :exchange => "request-stream-#{app}-#{env}",
24
25
  :exchange_durable => true,
25
26
  :exchange_auto_delete => false,
26
- :routing_key => "logs.#{app}.#{env}"
27
27
  }
28
28
  end
29
29
 
@@ -31,13 +31,13 @@ module LogjamAgent
31
31
  def forward(msg, options = {})
32
32
  return if paused? || LogjamAgent.disabled
33
33
  begin
34
- # $stderr.puts msg
35
- key = options[:routing_key] || @config[:routing_key]
34
+ app_env = options[:app_env] || @app_env
35
+ key = options[:routing_key] || "logs.#{app_env.sub('-','.')}"
36
36
  if engine = options[:engine]
37
37
  key += ".#{engine}"
38
38
  end
39
39
  info = pack_info(@sequence = next_fixnum(@sequence))
40
- exchange.publish(msg, :key => key, :persistent => false, :headers => {:info => info})
40
+ exchange(app_env).publish(msg, :key => key, :persistent => false, :headers => {:info => info})
41
41
  rescue => error
42
42
  reraise_expectation_errors!
43
43
  pause(error)
@@ -55,7 +55,8 @@ module LogjamAgent
55
55
  rescue
56
56
  # if bunny throws an exception here, its not usable anymore anyway
57
57
  ensure
58
- @exchange = @bunny = nil
58
+ @exchanges = {}
59
+ @bunny = nil
59
60
  end
60
61
  end
61
62
 
@@ -81,11 +82,11 @@ module LogjamAgent
81
82
  @paused && @paused > RETRY_AFTER.ago
82
83
  end
83
84
 
84
- def exchange
85
- @exchange ||=
85
+ def exchange(app_env)
86
+ @exchanges[app_env] ||=
86
87
  begin
87
88
  bunny.start unless bunny.connected?
88
- bunny.exchange(@config[:exchange],
89
+ bunny.exchange("request-stream-#{app_env}",
89
90
  :durable => @config[:exchange_durable],
90
91
  :auto_delete => @config[:exchange_auto_delete],
91
92
  :type => :topic)
@@ -1,3 +1,3 @@
1
1
  module LogjamAgent
2
- VERSION = "0.11.1"
2
+ VERSION = "0.11.2"
3
3
  end
@@ -8,17 +8,16 @@ module LogjamAgent
8
8
  opts = args.extract_options!
9
9
  @app = args[0] || LogjamAgent.application_name
10
10
  @env = args[1] || LogjamAgent.environment_name
11
- @config = default_options(@app, @env).merge!(opts)
12
11
  @app_env = "#{@app}-#{@env}"
12
+ @config = default_options.merge!(opts)
13
13
  @zmq_hosts = Array(@config[:host])
14
14
  @zmq_port = @config[:port]
15
15
  @sequence = 0
16
16
  end
17
17
 
18
- def default_options(app, env)
18
+ def default_options
19
19
  {
20
20
  :host => "localhost",
21
- :routing_key => "logs.#{app}.#{env}",
22
21
  :port => 12345
23
22
  }
24
23
  end
@@ -54,7 +53,6 @@ module LogjamAgent
54
53
 
55
54
  def reset
56
55
  return unless @socket
57
- # $stderr.puts "closing socket"
58
56
  @socket.close
59
57
  @socket = nil
60
58
  end
@@ -62,20 +60,21 @@ module LogjamAgent
62
60
  def forward(msg, options={})
63
61
  return if LogjamAgent.disabled
64
62
  begin
65
- key = options[:routing_key] || @config[:routing_key]
63
+ app_env = options[:app_env] || @app_env
64
+ key = options[:routing_key] || "logs.#{app_env.sub('-','.')}"
66
65
  if engine = options[:engine]
67
66
  key += ".#{engine}"
68
67
  end
69
- publish(key, msg)
68
+ publish(app_env, key, msg)
70
69
  rescue => error
71
70
  reraise_expectation_errors!
72
71
  raise ForwardingError.new(error.message)
73
72
  end
74
73
  end
75
74
 
76
- def publish(key, data)
75
+ def publish(app_env, key, data)
77
76
  info = pack_info(@sequence = next_fixnum(@sequence))
78
- parts = [@app_env, key, data, info]
77
+ parts = [app_env, key, data, info]
79
78
  if socket.send_strings(parts, ZMQ::DONTWAIT) < 0
80
79
  raise "ZMQ error: #{ZMQ::Util.error_string}"
81
80
  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.11.1
4
+ version: 0.11.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Kaes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-10 00:00:00.000000000 Z
11
+ date: 2014-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake