right_agent 2.2.1 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/lib/right_agent.rb +1 -0
  3. data/lib/right_agent/actor.rb +0 -28
  4. data/lib/right_agent/actors/agent_manager.rb +20 -18
  5. data/lib/right_agent/agent.rb +69 -87
  6. data/lib/right_agent/agent_tag_manager.rb +1 -1
  7. data/lib/right_agent/clients/api_client.rb +0 -1
  8. data/lib/right_agent/clients/auth_client.rb +2 -6
  9. data/lib/right_agent/clients/balanced_http_client.rb +2 -2
  10. data/lib/right_agent/clients/base_retry_client.rb +12 -19
  11. data/lib/right_agent/clients/right_http_client.rb +1 -5
  12. data/lib/right_agent/clients/router_client.rb +8 -15
  13. data/lib/right_agent/command/command_parser.rb +3 -3
  14. data/lib/right_agent/command/command_runner.rb +1 -1
  15. data/lib/right_agent/connectivity_checker.rb +7 -11
  16. data/lib/right_agent/dispatcher.rb +7 -42
  17. data/lib/right_agent/enrollment_result.rb +2 -2
  18. data/lib/right_agent/error_tracker.rb +202 -0
  19. data/lib/right_agent/log.rb +0 -2
  20. data/lib/right_agent/packets.rb +1 -1
  21. data/lib/right_agent/pending_requests.rb +10 -4
  22. data/lib/right_agent/pid_file.rb +3 -3
  23. data/lib/right_agent/protocol_version_mixin.rb +3 -3
  24. data/lib/right_agent/scripts/agent_deployer.rb +13 -1
  25. data/lib/right_agent/sender.rb +14 -30
  26. data/lib/right_agent/serialize/secure_serializer.rb +4 -4
  27. data/right_agent.gemspec +2 -2
  28. data/spec/agent_spec.rb +5 -5
  29. data/spec/clients/auth_client_spec.rb +1 -1
  30. data/spec/clients/balanced_http_client_spec.rb +4 -2
  31. data/spec/clients/base_retry_client_spec.rb +5 -6
  32. data/spec/clients/router_client_spec.rb +1 -4
  33. data/spec/dispatcher_spec.rb +6 -55
  34. data/spec/error_tracker_spec.rb +293 -0
  35. data/spec/pending_requests_spec.rb +2 -2
  36. data/spec/sender_spec.rb +3 -3
  37. data/spec/spec_helper.rb +4 -2
  38. metadata +33 -66
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eb258d0df08bc7694ac92eb41a9e819eebfc8d6a
4
+ data.tar.gz: 6e5674fe87ac4372a3ae2479cae0f7911b65bc54
5
+ SHA512:
6
+ metadata.gz: fc15f988d7292135374f76a736570d746669d8ab369435723c8b10f5ef8e229d41864dc122fd92658b46c4a1ebc5d67229dfad0fe78e1611a59162ded66ba39a
7
+ data.tar.gz: 060fdb4a7cb60604c45c4498add812ac079388edbf417bd4bc8fc0d83e2c9449101f369db7ba9f29c8d9d65a44dc36ee7b8788aa6a0ee4cc74daf38a6283b936
@@ -34,6 +34,7 @@ require File.normalize_path(File.join(RIGHT_AGENT_BASE_DIR, 'console'))
34
34
  require File.normalize_path(File.join(RIGHT_AGENT_BASE_DIR, 'daemonize'))
35
35
  require File.normalize_path(File.join(RIGHT_AGENT_BASE_DIR, 'exceptions'))
36
36
  require File.normalize_path(File.join(RIGHT_AGENT_BASE_DIR, 'http_exceptions'))
37
+ require File.normalize_path(File.join(RIGHT_AGENT_BASE_DIR, 'error_tracker'))
37
38
  require File.normalize_path(File.join(RIGHT_AGENT_BASE_DIR, 'multiplexer'))
38
39
  require File.normalize_path(File.join(RIGHT_AGENT_BASE_DIR, 'tracer'))
39
40
  require File.normalize_path(File.join(RIGHT_AGENT_BASE_DIR, 'audit_formatter'))
@@ -128,34 +128,6 @@ module RightScale
128
128
  @exposed[method] if @exposed
129
129
  end
130
130
 
131
- # Set method called when dispatching to this actor fails
132
- #
133
- # The callback method is required to accept the following parameters:
134
- # method(Symbol):: Actor method being dispatched to
135
- # deliverable(Packet):: Packet delivered to dispatcher
136
- # exception(Exception):: Exception raised
137
- #
138
- # === Parameters
139
- # proc(Proc|Symbol|String):: Procedure to be called on exception
140
- #
141
- # === Block
142
- # Block to be executed if no Proc provided
143
- #
144
- # === Return
145
- # @exception_callback(Proc):: Callback procedure
146
- def on_exception(proc = nil, &blk)
147
- raise 'No callback provided for on_exception' unless proc || blk
148
- @exception_callback = proc || blk
149
- end
150
-
151
- # Get exception callback procedure
152
- #
153
- # === Return
154
- # @exception_callback(Proc):: Callback procedure
155
- def exception_callback
156
- @exception_callback
157
- end
158
-
159
131
  end # ClassMethods
160
132
 
161
133
  module InstanceMethods
@@ -28,8 +28,6 @@ class AgentManager
28
28
  include RightScale::Actor
29
29
  include RightScale::OperationResultHelper
30
30
 
31
- on_exception { |meth, deliverable, e| RightScale::ExceptionMailer.deliver_notification(meth, deliverable, e) }
32
-
33
31
  expose_idempotent :ping, :stats, :profile, :set_log_level, :connect, :disconnect, :connect_failed
34
32
  expose_non_idempotent :execute, :terminate
35
33
 
@@ -42,6 +40,7 @@ class AgentManager
42
40
  # agent(RightScale::Agent):: This agent
43
41
  def initialize(agent)
44
42
  @agent = agent
43
+ @error_tracker = RightScale::ErrorTracker.instance
45
44
  end
46
45
 
47
46
  # Always return success along with identity, protocol version, and broker information
@@ -140,7 +139,7 @@ class AgentManager
140
139
  begin
141
140
  success_result(self.instance_eval(code))
142
141
  rescue Exception => e
143
- error_result(e.message + " at\n " + e.backtrace.join("\n "))
142
+ error_result("Failed executing: #{code.inspect}", e, :trace)
144
143
  end
145
144
  end
146
145
 
@@ -157,18 +156,19 @@ class AgentManager
157
156
  # :force(Boolean):: Reconnect even if already connected
158
157
  #
159
158
  # === Return
160
- # res(RightScale::OperationResult):: Success unless exception is raised
159
+ # (RightScale::OperationResult):: Success unless exception is raised
161
160
  def connect(options)
162
161
  options = RightScale::SerializationHelper.symbolize_keys(options)
163
- res = success_result
162
+ result = success_result
164
163
  begin
165
164
  if (error = @agent.connect(options[:host], options[:port], options[:id], options[:priority], options[:force]))
166
- res = error_result(error)
165
+ result = error_result(error)
167
166
  end
168
167
  rescue Exception => e
169
- res = error_result("Failed to connect to broker", e)
168
+ @error_tracker.log(self, error = "Failed to connect to broker", e)
169
+ result = error_result(error, e)
170
170
  end
171
- res
171
+ result
172
172
  end
173
173
 
174
174
  # Disconnect agent from a broker
@@ -180,18 +180,19 @@ class AgentManager
180
180
  # :remove(Boolean):: Remove broker from configuration in addition to disconnecting it
181
181
  #
182
182
  # === Return
183
- # res(RightScale::OperationResult):: Success unless exception is raised
183
+ # (RightScale::OperationResult):: Success unless exception is raised
184
184
  def disconnect(options)
185
185
  options = RightScale::SerializationHelper.symbolize_keys(options)
186
- res = success_result
186
+ result = success_result
187
187
  begin
188
188
  if (error = @agent.disconnect(options[:host], options[:port], options[:remove]))
189
- res = error_result(error)
189
+ result = error_result(error)
190
190
  end
191
191
  rescue Exception => e
192
- res = error_result("Failed to disconnect from broker", e)
192
+ @error_tracker.log(self, error = "Failed to disconnect from broker", e)
193
+ result = error_result(error, e)
193
194
  end
194
- res
195
+ result
195
196
  end
196
197
 
197
198
  # Declare one or more broker connections unusable because connection setup has failed
@@ -201,18 +202,19 @@ class AgentManager
201
202
  # :brokers(Array):: Identity of brokers
202
203
  #
203
204
  # === Return
204
- # res(RightScale::OperationResult):: Success unless exception is raised
205
+ # (RightScale::OperationResult):: Success unless exception is raised
205
206
  def connect_failed(options)
206
207
  options = RightScale::SerializationHelper.symbolize_keys(options)
207
- res = success_result
208
+ result = success_result
208
209
  begin
209
210
  if (error = @agent.connect_failed(options[:brokers]))
210
- res = error_result(error)
211
+ result = error_result(error)
211
212
  end
212
213
  rescue Exception => e
213
- res = error_result("Failed to notify agent that brokers #{options[:brokers]} are unusable", e)
214
+ @error_tracker.log(self, error = "Failed to notify agent that brokers #{options[:brokers]} are unusable", e)
215
+ result = error_result(error, e)
214
216
  end
215
- res
217
+ result
216
218
  end
217
219
 
218
220
  # Terminate self
@@ -57,9 +57,6 @@ module RightScale
57
57
  # (Array) Tag strings published by agent
58
58
  attr_accessor :tags
59
59
 
60
- # (Proc) Callback procedure for exceptions
61
- attr_reader :exception_callback
62
-
63
60
  # Default option settings for the agent
64
61
  DEFAULT_OPTIONS = {
65
62
  :user => 'agent',
@@ -90,6 +87,15 @@ module RightScale
90
87
  # Block to be activated when finish terminating
91
88
  TERMINATE_BLOCK = lambda { EM.stop if EM.reactor_running? }
92
89
 
90
+ # Exceptions with restricted error backtrace level
91
+ # Value :no_trace means no backtrace and no tracking in stats or reporting to Errbit
92
+ TRACE_LEVEL = {
93
+ RightSupport::Net::NoResult => :no_trace,
94
+ RightScale::Exceptions::ConnectivityFailure => :no_trace,
95
+ RightScale::BalancedHttpClient::NotResponding => :no_trace,
96
+ RightAMQP::HABrokerClient::NoConnectedBrokers => :no_trace
97
+ }
98
+
93
99
  # Initializes a new agent and establishes an HTTP or AMQP RightNet connection
94
100
  # This must be used inside an EM.run block unless the EventMachine reactor
95
101
  # was already started by the server that this application runs on
@@ -129,10 +135,8 @@ module RightScale
129
135
  # :prefetch(Integer):: Maximum number of messages the AMQP broker is to prefetch for this agent
130
136
  # before it receives an ack. Value 1 ensures that only last unacknowledged gets redelivered
131
137
  # if the agent crashes. Value 0 means unlimited prefetch.
132
- # :exception_callback(Proc):: Callback with following parameters that is activated on exception events:
133
- # exception(Exception):: Exception
134
- # message(Packet):: Message being processed
135
- # agent(Agent):: Reference to agent
138
+ # :airbrake_endpoint(String):: URL for Airbrake for reporting unexpected exceptions to Errbit
139
+ # :airbrake_api_key(String):: Key for using the Airbrake API access to Errbit
136
140
  # :ready_callback(Proc):: Called once agent is connected to AMQP broker and ready for service (no argument)
137
141
  # :restart_callback(Proc):: Called on each restart vote with votes being initiated by offline queue
138
142
  # exceeding MAX_QUEUED_REQUESTS or by repeated failures to access RightNet when online (no argument)
@@ -192,7 +196,10 @@ module RightScale
192
196
  Log.init(@identity, @options[:log_path], :print => true)
193
197
  Log.level = @options[:log_level] if @options[:log_level]
194
198
  RightSupport::Log::Mixin.default_logger = Log
199
+ ErrorTracker.init(self, @options[:agent_name], :shard_id => @options[:shard_id], :trace_level => TRACE_LEVEL,
200
+ :airbrake_endpoint => @options[:airbrake_endpoint], :airbrake_api_key => @options[:airbrake_api_key])
195
201
  @history.update("start")
202
+
196
203
  now = Time.now
197
204
  Log.info("[start] Agent #{@identity} starting; time: #{now.utc}; utc_offset: #{now.utc_offset}")
198
205
  @options.each { |k, v| Log.info("- #{k}: #{k.to_s =~ /pass/ ? '****' : (v.respond_to?(:each) ? v.inspect : v)}") }
@@ -213,7 +220,7 @@ module RightScale
213
220
  else
214
221
  # Initiate AMQP broker connection, wait for connection before proceeding
215
222
  # otherwise messages published on failed connection will be lost
216
- @client = RightAMQP::HABrokerClient.new(Serializer.new(:secure), @options)
223
+ @client = RightAMQP::HABrokerClient.new(Serializer.new(:secure), @options.merge(:exception_stats => ErrorTracker.exception_stats))
217
224
  @queues.each { |s| @remaining_queue_setup[s] = @client.all }
218
225
  @client.connection_status(:one_off => @options[:connect_timeout]) do |status|
219
226
  if status == :connected
@@ -230,12 +237,10 @@ module RightScale
230
237
  end
231
238
  end
232
239
  end
233
- rescue SystemExit
234
- raise
235
240
  rescue PidFile::AlreadyRunning
236
241
  EM.stop if EM.reactor_running?
237
242
  raise
238
- rescue Exception => e
243
+ rescue StandardError => e
239
244
  terminate("failed startup", e)
240
245
  end
241
246
  true
@@ -289,14 +294,14 @@ module RightScale
289
294
  # force(Boolean):: Reconnect even if already connected
290
295
  #
291
296
  # === Return
292
- # res(String|nil):: Error message if failed, otherwise nil
297
+ # (String|nil):: Error message if failed, otherwise nil
293
298
  def connect(host, port, index, priority = nil, force = false)
294
299
  @connect_request_stats.update("connect b#{index}")
295
300
  even_if = " even if already connected" if force
296
301
  Log.info("Connecting to broker at host #{host.inspect} port #{port.inspect} " +
297
302
  "index #{index.inspect} priority #{priority.inspect}#{even_if}")
298
303
  Log.info("Current broker configuration: #{@client.status.inspect}")
299
- res = nil
304
+ result = nil
300
305
  begin
301
306
  @client.connect(host, port, index, priority, force) do |id|
302
307
  @client.connection_status(:one_off => @options[:connect_timeout], :brokers => [id]) do |status|
@@ -310,20 +315,18 @@ module RightScale
310
315
  Log.warning("Successfully connected to broker #{id} but failed to update config file")
311
316
  end
312
317
  else
313
- Log.error("Failed to connect to broker #{id}, status #{status.inspect}")
318
+ ErrorTracker.log(self, "Failed to connect to broker #{id}, status #{status.inspect}")
314
319
  end
315
320
  rescue Exception => e
316
- Log.error("Failed to connect to broker #{id}, status #{status.inspect}", e)
317
- @exception_stats.track("connect", e)
321
+ ErrorTracker.log(self, "Failed to connect to broker #{id}, status #{status.inspect}", e)
318
322
  end
319
323
  end
320
324
  end
321
- rescue Exception => e
322
- res = Log.format("Failed to connect to broker at host #{host.inspect} and port #{port.inspect}", e)
323
- @exception_stats.track("connect", e)
325
+ rescue StandardError => e
326
+ ErrorTracker.log(self, msg = "Failed to connect to broker at host #{host.inspect} and port #{port.inspect}", e)
327
+ result = Log.format(msg, e)
324
328
  end
325
- Log.error(res) if res
326
- res
329
+ result
327
330
  end
328
331
 
329
332
  # Disconnect from an AMQP broker and optionally remove it from the configuration
@@ -336,7 +339,7 @@ module RightScale
336
339
  # defaults to false
337
340
  #
338
341
  # === Return
339
- # res(String|nil):: Error message if failed, otherwise nil
342
+ # (String|nil):: Error message if failed, otherwise nil
340
343
  def disconnect(host, port, remove = false)
341
344
  and_remove = " and removing" if remove
342
345
  Log.info("Disconnecting#{and_remove} broker at host #{host.inspect} port #{port.inspect}")
@@ -344,29 +347,28 @@ module RightScale
344
347
  id = RightAMQP::HABrokerClient.identity(host, port)
345
348
  @connect_request_stats.update("disconnect #{@client.alias_(id)}")
346
349
  connected = @client.connected
347
- res = nil
350
+ result = e = nil
348
351
  if connected.include?(id) && connected.size == 1
349
- res = "Not disconnecting from #{id} because it is the last connected broker for this agent"
352
+ result = "Not disconnecting from #{id} because it is the last connected broker for this agent"
350
353
  elsif @client.get(id)
351
354
  begin
352
355
  if remove
353
356
  @client.remove(host, port) do |id|
354
357
  unless update_configuration(:host => @client.hosts, :port => @client.ports)
355
- res = "Successfully disconnected from broker #{id} but failed to update config file"
358
+ result = "Successfully disconnected from broker #{id} but failed to update config file"
356
359
  end
357
360
  end
358
361
  else
359
362
  @client.close_one(id)
360
363
  end
361
- rescue Exception => e
362
- res = Log.format("Failed to disconnect from broker #{id}", e)
363
- @exception_stats.track("disconnect", e)
364
+ rescue StandardError => e
365
+ result = Log.format("Failed to disconnect from broker #{id}", e)
364
366
  end
365
367
  else
366
- res = "Cannot disconnect from broker #{id} because not configured for this agent"
368
+ result = "Cannot disconnect from broker #{id} because not configured for this agent"
367
369
  end
368
- Log.error(res) if res
369
- res
370
+ ErrorTracker.log(self, result, e) if result
371
+ result
370
372
  end
371
373
 
372
374
  # There were problems while setting up service for this agent on the given AMQP brokers,
@@ -377,11 +379,11 @@ module RightScale
377
379
  # ids(Array):: Identity of brokers
378
380
  #
379
381
  # === Return
380
- # res(String|nil):: Error message if failed, otherwise nil
382
+ # (String|nil):: Error message if failed, otherwise nil
381
383
  def connect_failed(ids)
382
384
  aliases = @client.aliases(ids).join(", ")
383
385
  @connect_request_stats.update("enroll failed #{aliases}")
384
- res = nil
386
+ result = nil
385
387
  begin
386
388
  Log.info("Received indication that service initialization for this agent for brokers #{ids.inspect} has failed")
387
389
  connected = @client.connected
@@ -389,12 +391,11 @@ module RightScale
389
391
  Log.info("Not marking brokers #{ignored.inspect} as unusable because currently connected") if ignored
390
392
  Log.info("Current broker configuration: #{@client.status.inspect}")
391
393
  @client.declare_unusable(ids - ignored)
392
- rescue Exception => e
393
- res = Log.format("Failed handling broker connection failure indication for #{ids.inspect}", e)
394
- Log.error(res)
395
- @exception_stats.track("connect failed", e)
394
+ rescue StandardError => e
395
+ ErrorTracker.log(self, msg = "Failed handling broker connection failure indication for #{ids.inspect}", e)
396
+ result = Log.format(msg, e)
396
397
  end
397
- res
398
+ result
398
399
  end
399
400
 
400
401
  # Update agent's persisted configuration
@@ -411,11 +412,11 @@ module RightScale
411
412
  AgentConfig.store_cfg(@agent_name, cfg)
412
413
  true
413
414
  else
414
- Log.error("Could not access configuration file #{AgentConfig.cfg_file(@agent_name).inspect} for update")
415
+ ErrorTracker.log(self, "Could not access configuration file #{AgentConfig.cfg_file(@agent_name).inspect} for update")
415
416
  false
416
417
  end
417
- rescue Exception => e
418
- Log.error("Failed updating configuration file #{AgentConfig.cfg_file(@agent_name).inspect}", e, :trace)
418
+ rescue StandardError => e
419
+ ErrorTracker.log(self, "Failed updating configuration file #{AgentConfig.cfg_file(@agent_name).inspect}", e)
419
420
  false
420
421
  end
421
422
 
@@ -432,7 +433,7 @@ module RightScale
432
433
  def terminate(reason = nil, exception = nil)
433
434
  begin
434
435
  @history.update("stop") if @history
435
- Log.error("[stop] Terminating because #{reason}", exception, :trace) if reason
436
+ ErrorTracker.log(self, "[stop] Terminating because #{reason}", exception) if reason
436
437
  if exception.is_a?(Exception)
437
438
  h = @history.analyze_service
438
439
  if h[:last_crashed]
@@ -455,10 +456,8 @@ module RightScale
455
456
  Log.info("[stop] Agent #{@identity} terminating")
456
457
  stop_gracefully(@options[:grace_timeout])
457
458
  end
458
- rescue SystemExit
459
- raise
460
- rescue Exception => e
461
- Log.error("Failed to terminate gracefully", e, :trace)
459
+ rescue StandardError => e
460
+ ErrorTracker.log(self, "Failed to terminate gracefully", e)
462
461
  begin @terminate_callback.call; rescue Exception; end
463
462
  end
464
463
  true
@@ -523,10 +522,9 @@ module RightScale
523
522
  # with percentage breakdown per failure type, or nil if none
524
523
  def agent_stats(reset = false)
525
524
  stats = {
526
- "exceptions" => @exception_stats.stats,
527
525
  "request failures" => @request_failure_stats.all,
528
526
  "response failures" => @response_failure_stats.all
529
- }
527
+ }.merge(ErrorTracker.stats(reset))
530
528
  if @mode != :http
531
529
  stats["connect requests"] = @connect_request_stats.all
532
530
  stats["non-deliveries"] = @non_delivery_stats.all
@@ -544,7 +542,6 @@ module RightScale
544
542
  @non_delivery_stats = RightSupport::Stats::Activity.new
545
543
  @request_failure_stats = RightSupport::Stats::Activity.new
546
544
  @response_failure_stats = RightSupport::Stats::Activity.new
547
- @exception_stats = RightSupport::Stats::Exceptions.new(self, @options[:exception_callback])
548
545
  true
549
546
  end
550
547
 
@@ -588,7 +585,6 @@ module RightScale
588
585
  @mode = @options[:mode].to_sym
589
586
  @stats_routing_key = "stats.#{@agent_type}.#{parsed_identity.base_id}"
590
587
  @terminate_callback = TERMINATE_BLOCK
591
- @exception_callback = @options[:exception_callback]
592
588
  @revision = revision
593
589
  @queues = [@identity]
594
590
  @remaining_queue_setup = {}
@@ -623,9 +619,7 @@ module RightScale
623
619
  # reconnect attempt, which can result in repeated attempts to setup
624
620
  # queues when finally do connect
625
621
  setup_status_checks([@options[:check_interval], @options[:connect_timeout]].max)
626
- rescue SystemExit
627
- raise
628
- rescue Exception => e
622
+ rescue StandardError => e
629
623
  terminate("failed service startup", e)
630
624
  end
631
625
  true
@@ -650,20 +644,20 @@ module RightScale
650
644
  end
651
645
  rescue Dispatcher::DuplicateRequest
652
646
  rescue Exception => e
653
- Log.error("Failed sending response for <#{event[:uuid]}>", e, :trace)
647
+ ErrorTracker.log(self, "Failed sending response for <#{event[:uuid]}>", e)
654
648
  end
655
649
  end
656
650
  elsif event[:type] == "Result"
657
651
  if (data = event[:data]) && (result = data[:result]) && result.respond_to?(:non_delivery?) && result.non_delivery?
658
652
  Log.info("Non-delivery of event <#{data[:request_uuid]}>: #{result.content}")
659
653
  else
660
- Log.error("Unexpected Result event from #{event[:from]}: #{event.inspect}")
654
+ ErrorTracker.log(self, "Unexpected Result event from #{event[:from]}: #{event.inspect}")
661
655
  end
662
656
  else
663
- Log.error("Unrecognized event type #{event[:type]} from #{event[:from]}")
657
+ ErrorTracker.log(self, "Unrecognized event type #{event[:type]} from #{event[:from]}")
664
658
  end
665
659
  else
666
- Log.error("Unrecognized event: #{event.class}")
660
+ ErrorTracker.log(self, "Unrecognized event: #{event.class}")
667
661
  end
668
662
  nil
669
663
  end
@@ -742,14 +736,14 @@ module RightScale
742
736
  actors.delete(actor)
743
737
  end
744
738
  end
745
- Log.error("Actors #{actors.inspect} not found in #{actors_dirs.inspect}") unless actors.empty?
739
+ ErrorTracker.log(self, "Actors #{actors.inspect} not found in #{actors_dirs.inspect}") unless actors.empty?
746
740
 
747
741
  # Perform agent-specific initialization including actor creation and registration
748
742
  if (init_file = AgentConfig.init_file)
749
743
  Log.info("[setup] Initializing agent from #{init_file}")
750
744
  instance_eval(File.read(init_file), init_file)
751
745
  else
752
- Log.error("No agent init.rb file found in init directory of #{AgentConfig.root_dir.inspect}")
746
+ ErrorTracker.log(self, "No agent init.rb file found in init directory of #{AgentConfig.root_dir.inspect}")
753
747
  end
754
748
  true
755
749
  end
@@ -786,7 +780,7 @@ module RightScale
786
780
  old.call if old.is_a? Proc
787
781
  end
788
782
  rescue Exception => e
789
- Log.error("Failed in termination", e, :trace)
783
+ ErrorTracker.log(self, "Failed in termination", e)
790
784
  end
791
785
  end
792
786
  end
@@ -828,8 +822,7 @@ module RightScale
828
822
  result = Result.new(token, from, OperationResult.non_delivery(reason), to)
829
823
  @sender.handle_response(result)
830
824
  rescue Exception => e
831
- Log.error("Failed handling non-delivery for <#{token}>", e, :trace)
832
- @exception_stats.track("message return", e)
825
+ ErrorTracker.log(self, "Failed handling non-delivery for <#{token}>", e)
833
826
  end
834
827
  end
835
828
  end
@@ -881,8 +874,7 @@ module RightScale
881
874
  end
882
875
  @sender.message_received
883
876
  rescue Exception => e
884
- Log.error("#{queue} queue processing error", e, :trace)
885
- @exception_stats.track("#{queue} queue", e, packet)
877
+ ErrorTracker.log(self, "#{queue} queue processing error", e)
886
878
  ensure
887
879
  # Relying on fact that all dispatches/deliveries are synchronous and therefore
888
880
  # need to have completed or failed by now, thus allowing packet acknowledgement
@@ -907,17 +899,16 @@ module RightScale
907
899
  @client.publish(exchange, result, :persistent => true, :mandatory => true, :log_filter => [:request_from, :tries, :persistent, :duration])
908
900
  end
909
901
  else
910
- Log.error("Failed to dispatch request #{request.trace} from queue #{queue} because no dispatcher configured")
902
+ ErrorTracker.log(self, "Failed to dispatch request #{request.trace} from queue #{queue} because no dispatcher configured")
911
903
  @request_failure_stats.update("NoConfiguredDispatcher")
912
904
  end
913
905
  rescue Dispatcher::DuplicateRequest
914
906
  rescue RightAMQP::HABrokerClient::NoConnectedBrokers => e
915
- Log.error("Failed to publish result of dispatched request #{request.trace} from queue #{queue}", e)
907
+ ErrorTracker.log(self, "Failed to publish result of dispatched request #{request.trace} from queue #{queue}", e)
916
908
  @request_failure_stats.update("NoConnectedBrokers")
917
- rescue Exception => e
918
- Log.error("Failed to dispatch request #{request.trace} from queue #{queue}", e, :trace)
909
+ rescue StandardError => e
910
+ ErrorTracker.log(self, "Failed to dispatch request #{request.trace} from queue #{queue}", e)
919
911
  @request_failure_stats.update(e.class.name)
920
- @exception_stats.track("request", e)
921
912
  end
922
913
  true
923
914
  end
@@ -932,10 +923,9 @@ module RightScale
932
923
  def deliver_response(result)
933
924
  begin
934
925
  @sender.handle_response(result)
935
- rescue Exception => e
936
- Log.error("Failed to deliver response #{result.trace}", e, :trace)
926
+ rescue StandardError => e
927
+ ErrorTracker.log(self, "Failed to deliver response #{result.trace}", e)
937
928
  @response_failure_stats.update(e.class.name)
938
- @exception_stats.track("response", e)
939
929
  end
940
930
  true
941
931
  end
@@ -968,8 +958,7 @@ module RightScale
968
958
  begin
969
959
  callback.call(type, state)
970
960
  rescue RuntimeError => e
971
- Log.error("Failed status callback", e)
972
- @exception_stats.track("update status", e)
961
+ ErrorTracker.log(self, "Failed status callback", e, nil, :caller)
973
962
  end
974
963
  end
975
964
  true
@@ -1005,38 +994,31 @@ module RightScale
1005
994
  update_status(:auth, :failed)
1006
995
  end
1007
996
  rescue Exception => e
1008
- Log.error("Failed switching mode", e)
1009
- @exception_stats.track("check status", e)
997
+ ErrorTracker.log(self, "Failed switching mode", e)
1010
998
  end
1011
999
 
1012
1000
  begin
1013
1001
  finish_setup unless @terminating || @mode == :http
1014
1002
  rescue Exception => e
1015
- Log.error("Failed finishing setup", e)
1016
- @exception_stats.track("check status", e)
1003
+ ErrorTracker.log(self, "Failed finishing setup", e)
1017
1004
  end
1018
1005
 
1019
1006
  begin
1020
1007
  @client.queue_status(@queues, timeout = @options[:check_interval] / 10) unless @terminating || @mode == :http
1021
1008
  rescue Exception => e
1022
- Log.error("Failed checking queue status", e)
1023
- @exception_stats.track("check status", e)
1009
+ ErrorTracker.log(self, "Failed checking queue status", e)
1024
1010
  end
1025
1011
 
1026
1012
  begin
1027
1013
  publish_stats unless @terminating || @stats_routing_key.nil?
1028
- rescue Exceptions::ConnectivityFailure => e
1029
- Log.error("Failed publishing stats", e, :no_trace)
1030
1014
  rescue Exception => e
1031
- Log.error("Failed publishing stats", e)
1032
- @exception_stats.track("check status", e)
1015
+ ErrorTracker.log(self, "Failed publishing stats", e)
1033
1016
  end
1034
1017
 
1035
1018
  begin
1036
1019
  check_other(@check_status_count) unless @terminating
1037
1020
  rescue Exception => e
1038
- Log.error("Failed to perform other check status check", e)
1039
- @exception_stats.track("check status", e)
1021
+ ErrorTracker.log(self, "Failed to perform other check status check", e)
1040
1022
  end
1041
1023
 
1042
1024
  @check_status_count += 1
@@ -1131,7 +1113,7 @@ module RightScale
1131
1113
  Log.info("[stop] Continuing with termination")
1132
1114
  finish.call
1133
1115
  rescue Exception => e
1134
- Log.error("Failed while finishing termination", e, :trace)
1116
+ ErrorTracker.log(self, "Failed while finishing termination", e)
1135
1117
  begin @terminate_callback.call; rescue Exception; end
1136
1118
  end
1137
1119
  end