right_agent 2.2.1-x86-mingw32 → 2.4.3-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/README.rdoc +2 -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 +70 -87
  6. data/lib/right_agent/agent_config.rb +1 -1
  7. data/lib/right_agent/agent_tag_manager.rb +1 -1
  8. data/lib/right_agent/clients/api_client.rb +2 -1
  9. data/lib/right_agent/clients/auth_client.rb +2 -6
  10. data/lib/right_agent/clients/balanced_http_client.rb +22 -11
  11. data/lib/right_agent/clients/base_retry_client.rb +14 -22
  12. data/lib/right_agent/clients/non_blocking_client.rb +1 -0
  13. data/lib/right_agent/clients/right_http_client.rb +4 -8
  14. data/lib/right_agent/clients/router_client.rb +10 -16
  15. data/lib/right_agent/command/command_parser.rb +3 -3
  16. data/lib/right_agent/command/command_runner.rb +1 -1
  17. data/lib/right_agent/command/command_serializer.rb +0 -32
  18. data/lib/right_agent/connectivity_checker.rb +7 -11
  19. data/lib/right_agent/core_payload_types/dev_repository.rb +32 -0
  20. data/lib/right_agent/dispatcher.rb +8 -45
  21. data/lib/right_agent/enrollment_result.rb +2 -2
  22. data/lib/right_agent/error_tracker.rb +230 -0
  23. data/lib/right_agent/exceptions.rb +1 -1
  24. data/lib/right_agent/log.rb +8 -6
  25. data/lib/right_agent/packets.rb +5 -3
  26. data/lib/right_agent/pending_requests.rb +10 -4
  27. data/lib/right_agent/pid_file.rb +3 -3
  28. data/lib/right_agent/platform.rb +14 -14
  29. data/lib/right_agent/protocol_version_mixin.rb +6 -3
  30. data/lib/right_agent/scripts/agent_deployer.rb +13 -1
  31. data/lib/right_agent/sender.rb +16 -35
  32. data/lib/right_agent/serialize/secure_serializer.rb +6 -9
  33. data/lib/right_agent/serialize/serializer.rb +7 -3
  34. data/right_agent.gemspec +5 -5
  35. data/spec/agent_spec.rb +5 -5
  36. data/spec/clients/auth_client_spec.rb +1 -1
  37. data/spec/clients/balanced_http_client_spec.rb +20 -28
  38. data/spec/clients/base_retry_client_spec.rb +5 -6
  39. data/spec/clients/non_blocking_client_spec.rb +4 -0
  40. data/spec/clients/router_client_spec.rb +1 -4
  41. data/spec/dispatcher_spec.rb +6 -55
  42. data/spec/error_tracker_spec.rb +346 -0
  43. data/spec/log_spec.rb +4 -0
  44. data/spec/pending_requests_spec.rb +2 -2
  45. data/spec/sender_spec.rb +3 -3
  46. data/spec/serialize/serializer_spec.rb +14 -0
  47. data/spec/spec_helper.rb +4 -2
  48. metadata +13 -11
@@ -52,6 +52,8 @@ RightAgent has been tested on EC2 instances running CentOS 5.2 and Ubuntu 8.10.
52
52
 
53
53
  RightAgent is work in progress, expect more documentation and examples in the near future.
54
54
 
55
+ Owned by the RightScale Cornsilk team.
56
+
55
57
  = ADDITIONAL RESOURCES
56
58
 
57
59
  * [1] RabbitMQ is http://www.rabbitmq.com/documentation.html
@@ -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,16 @@ 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::HttpExceptions::RequestTimeout => :no_trace,
95
+ RightScale::Exceptions::ConnectivityFailure => :no_trace,
96
+ RightScale::BalancedHttpClient::NotResponding => :no_trace,
97
+ RightAMQP::HABrokerClient::NoConnectedBrokers => :no_trace
98
+ }
99
+
93
100
  # Initializes a new agent and establishes an HTTP or AMQP RightNet connection
94
101
  # This must be used inside an EM.run block unless the EventMachine reactor
95
102
  # was already started by the server that this application runs on
@@ -129,10 +136,8 @@ module RightScale
129
136
  # :prefetch(Integer):: Maximum number of messages the AMQP broker is to prefetch for this agent
130
137
  # before it receives an ack. Value 1 ensures that only last unacknowledged gets redelivered
131
138
  # 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
139
+ # :airbrake_endpoint(String):: URL for Airbrake for reporting unexpected exceptions to Errbit
140
+ # :airbrake_api_key(String):: Key for using the Airbrake API access to Errbit
136
141
  # :ready_callback(Proc):: Called once agent is connected to AMQP broker and ready for service (no argument)
137
142
  # :restart_callback(Proc):: Called on each restart vote with votes being initiated by offline queue
138
143
  # exceeding MAX_QUEUED_REQUESTS or by repeated failures to access RightNet when online (no argument)
@@ -192,7 +197,10 @@ module RightScale
192
197
  Log.init(@identity, @options[:log_path], :print => true)
193
198
  Log.level = @options[:log_level] if @options[:log_level]
194
199
  RightSupport::Log::Mixin.default_logger = Log
200
+ ErrorTracker.init(self, @options[:agent_name], :shard_id => @options[:shard_id], :trace_level => TRACE_LEVEL,
201
+ :airbrake_endpoint => @options[:airbrake_endpoint], :airbrake_api_key => @options[:airbrake_api_key])
195
202
  @history.update("start")
203
+
196
204
  now = Time.now
197
205
  Log.info("[start] Agent #{@identity} starting; time: #{now.utc}; utc_offset: #{now.utc_offset}")
198
206
  @options.each { |k, v| Log.info("- #{k}: #{k.to_s =~ /pass/ ? '****' : (v.respond_to?(:each) ? v.inspect : v)}") }
@@ -213,7 +221,7 @@ module RightScale
213
221
  else
214
222
  # Initiate AMQP broker connection, wait for connection before proceeding
215
223
  # otherwise messages published on failed connection will be lost
216
- @client = RightAMQP::HABrokerClient.new(Serializer.new(:secure), @options)
224
+ @client = RightAMQP::HABrokerClient.new(Serializer.new(:secure), @options.merge(:exception_stats => ErrorTracker.exception_stats))
217
225
  @queues.each { |s| @remaining_queue_setup[s] = @client.all }
218
226
  @client.connection_status(:one_off => @options[:connect_timeout]) do |status|
219
227
  if status == :connected
@@ -230,12 +238,10 @@ module RightScale
230
238
  end
231
239
  end
232
240
  end
233
- rescue SystemExit
234
- raise
235
241
  rescue PidFile::AlreadyRunning
236
242
  EM.stop if EM.reactor_running?
237
243
  raise
238
- rescue Exception => e
244
+ rescue StandardError => e
239
245
  terminate("failed startup", e)
240
246
  end
241
247
  true
@@ -289,14 +295,14 @@ module RightScale
289
295
  # force(Boolean):: Reconnect even if already connected
290
296
  #
291
297
  # === Return
292
- # res(String|nil):: Error message if failed, otherwise nil
298
+ # (String|nil):: Error message if failed, otherwise nil
293
299
  def connect(host, port, index, priority = nil, force = false)
294
300
  @connect_request_stats.update("connect b#{index}")
295
301
  even_if = " even if already connected" if force
296
302
  Log.info("Connecting to broker at host #{host.inspect} port #{port.inspect} " +
297
303
  "index #{index.inspect} priority #{priority.inspect}#{even_if}")
298
304
  Log.info("Current broker configuration: #{@client.status.inspect}")
299
- res = nil
305
+ result = nil
300
306
  begin
301
307
  @client.connect(host, port, index, priority, force) do |id|
302
308
  @client.connection_status(:one_off => @options[:connect_timeout], :brokers => [id]) do |status|
@@ -310,20 +316,18 @@ module RightScale
310
316
  Log.warning("Successfully connected to broker #{id} but failed to update config file")
311
317
  end
312
318
  else
313
- Log.error("Failed to connect to broker #{id}, status #{status.inspect}")
319
+ ErrorTracker.log(self, "Failed to connect to broker #{id}, status #{status.inspect}")
314
320
  end
315
321
  rescue Exception => e
316
- Log.error("Failed to connect to broker #{id}, status #{status.inspect}", e)
317
- @exception_stats.track("connect", e)
322
+ ErrorTracker.log(self, "Failed to connect to broker #{id}, status #{status.inspect}", e)
318
323
  end
319
324
  end
320
325
  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)
326
+ rescue StandardError => e
327
+ ErrorTracker.log(self, msg = "Failed to connect to broker at host #{host.inspect} and port #{port.inspect}", e)
328
+ result = Log.format(msg, e)
324
329
  end
325
- Log.error(res) if res
326
- res
330
+ result
327
331
  end
328
332
 
329
333
  # Disconnect from an AMQP broker and optionally remove it from the configuration
@@ -336,7 +340,7 @@ module RightScale
336
340
  # defaults to false
337
341
  #
338
342
  # === Return
339
- # res(String|nil):: Error message if failed, otherwise nil
343
+ # (String|nil):: Error message if failed, otherwise nil
340
344
  def disconnect(host, port, remove = false)
341
345
  and_remove = " and removing" if remove
342
346
  Log.info("Disconnecting#{and_remove} broker at host #{host.inspect} port #{port.inspect}")
@@ -344,29 +348,28 @@ module RightScale
344
348
  id = RightAMQP::HABrokerClient.identity(host, port)
345
349
  @connect_request_stats.update("disconnect #{@client.alias_(id)}")
346
350
  connected = @client.connected
347
- res = nil
351
+ result = e = nil
348
352
  if connected.include?(id) && connected.size == 1
349
- res = "Not disconnecting from #{id} because it is the last connected broker for this agent"
353
+ result = "Not disconnecting from #{id} because it is the last connected broker for this agent"
350
354
  elsif @client.get(id)
351
355
  begin
352
356
  if remove
353
357
  @client.remove(host, port) do |id|
354
358
  unless update_configuration(:host => @client.hosts, :port => @client.ports)
355
- res = "Successfully disconnected from broker #{id} but failed to update config file"
359
+ result = "Successfully disconnected from broker #{id} but failed to update config file"
356
360
  end
357
361
  end
358
362
  else
359
363
  @client.close_one(id)
360
364
  end
361
- rescue Exception => e
362
- res = Log.format("Failed to disconnect from broker #{id}", e)
363
- @exception_stats.track("disconnect", e)
365
+ rescue StandardError => e
366
+ result = Log.format("Failed to disconnect from broker #{id}", e)
364
367
  end
365
368
  else
366
- res = "Cannot disconnect from broker #{id} because not configured for this agent"
369
+ result = "Cannot disconnect from broker #{id} because not configured for this agent"
367
370
  end
368
- Log.error(res) if res
369
- res
371
+ ErrorTracker.log(self, result, e) if result
372
+ result
370
373
  end
371
374
 
372
375
  # There were problems while setting up service for this agent on the given AMQP brokers,
@@ -377,11 +380,11 @@ module RightScale
377
380
  # ids(Array):: Identity of brokers
378
381
  #
379
382
  # === Return
380
- # res(String|nil):: Error message if failed, otherwise nil
383
+ # (String|nil):: Error message if failed, otherwise nil
381
384
  def connect_failed(ids)
382
385
  aliases = @client.aliases(ids).join(", ")
383
386
  @connect_request_stats.update("enroll failed #{aliases}")
384
- res = nil
387
+ result = nil
385
388
  begin
386
389
  Log.info("Received indication that service initialization for this agent for brokers #{ids.inspect} has failed")
387
390
  connected = @client.connected
@@ -389,12 +392,11 @@ module RightScale
389
392
  Log.info("Not marking brokers #{ignored.inspect} as unusable because currently connected") if ignored
390
393
  Log.info("Current broker configuration: #{@client.status.inspect}")
391
394
  @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)
395
+ rescue StandardError => e
396
+ ErrorTracker.log(self, msg = "Failed handling broker connection failure indication for #{ids.inspect}", e)
397
+ result = Log.format(msg, e)
396
398
  end
397
- res
399
+ result
398
400
  end
399
401
 
400
402
  # Update agent's persisted configuration
@@ -411,11 +413,11 @@ module RightScale
411
413
  AgentConfig.store_cfg(@agent_name, cfg)
412
414
  true
413
415
  else
414
- Log.error("Could not access configuration file #{AgentConfig.cfg_file(@agent_name).inspect} for update")
416
+ ErrorTracker.log(self, "Could not access configuration file #{AgentConfig.cfg_file(@agent_name).inspect} for update")
415
417
  false
416
418
  end
417
- rescue Exception => e
418
- Log.error("Failed updating configuration file #{AgentConfig.cfg_file(@agent_name).inspect}", e, :trace)
419
+ rescue StandardError => e
420
+ ErrorTracker.log(self, "Failed updating configuration file #{AgentConfig.cfg_file(@agent_name).inspect}", e)
419
421
  false
420
422
  end
421
423
 
@@ -432,7 +434,7 @@ module RightScale
432
434
  def terminate(reason = nil, exception = nil)
433
435
  begin
434
436
  @history.update("stop") if @history
435
- Log.error("[stop] Terminating because #{reason}", exception, :trace) if reason
437
+ ErrorTracker.log(self, "[stop] Terminating because #{reason}", exception) if reason
436
438
  if exception.is_a?(Exception)
437
439
  h = @history.analyze_service
438
440
  if h[:last_crashed]
@@ -455,10 +457,8 @@ module RightScale
455
457
  Log.info("[stop] Agent #{@identity} terminating")
456
458
  stop_gracefully(@options[:grace_timeout])
457
459
  end
458
- rescue SystemExit
459
- raise
460
- rescue Exception => e
461
- Log.error("Failed to terminate gracefully", e, :trace)
460
+ rescue StandardError => e
461
+ ErrorTracker.log(self, "Failed to terminate gracefully", e)
462
462
  begin @terminate_callback.call; rescue Exception; end
463
463
  end
464
464
  true
@@ -523,10 +523,9 @@ module RightScale
523
523
  # with percentage breakdown per failure type, or nil if none
524
524
  def agent_stats(reset = false)
525
525
  stats = {
526
- "exceptions" => @exception_stats.stats,
527
526
  "request failures" => @request_failure_stats.all,
528
527
  "response failures" => @response_failure_stats.all
529
- }
528
+ }.merge(ErrorTracker.stats(reset))
530
529
  if @mode != :http
531
530
  stats["connect requests"] = @connect_request_stats.all
532
531
  stats["non-deliveries"] = @non_delivery_stats.all
@@ -544,7 +543,6 @@ module RightScale
544
543
  @non_delivery_stats = RightSupport::Stats::Activity.new
545
544
  @request_failure_stats = RightSupport::Stats::Activity.new
546
545
  @response_failure_stats = RightSupport::Stats::Activity.new
547
- @exception_stats = RightSupport::Stats::Exceptions.new(self, @options[:exception_callback])
548
546
  true
549
547
  end
550
548
 
@@ -588,7 +586,6 @@ module RightScale
588
586
  @mode = @options[:mode].to_sym
589
587
  @stats_routing_key = "stats.#{@agent_type}.#{parsed_identity.base_id}"
590
588
  @terminate_callback = TERMINATE_BLOCK
591
- @exception_callback = @options[:exception_callback]
592
589
  @revision = revision
593
590
  @queues = [@identity]
594
591
  @remaining_queue_setup = {}
@@ -623,9 +620,7 @@ module RightScale
623
620
  # reconnect attempt, which can result in repeated attempts to setup
624
621
  # queues when finally do connect
625
622
  setup_status_checks([@options[:check_interval], @options[:connect_timeout]].max)
626
- rescue SystemExit
627
- raise
628
- rescue Exception => e
623
+ rescue StandardError => e
629
624
  terminate("failed service startup", e)
630
625
  end
631
626
  true
@@ -650,20 +645,20 @@ module RightScale
650
645
  end
651
646
  rescue Dispatcher::DuplicateRequest
652
647
  rescue Exception => e
653
- Log.error("Failed sending response for <#{event[:uuid]}>", e, :trace)
648
+ ErrorTracker.log(self, "Failed sending response for <#{event[:uuid]}>", e)
654
649
  end
655
650
  end
656
651
  elsif event[:type] == "Result"
657
652
  if (data = event[:data]) && (result = data[:result]) && result.respond_to?(:non_delivery?) && result.non_delivery?
658
653
  Log.info("Non-delivery of event <#{data[:request_uuid]}>: #{result.content}")
659
654
  else
660
- Log.error("Unexpected Result event from #{event[:from]}: #{event.inspect}")
655
+ ErrorTracker.log(self, "Unexpected Result event from #{event[:from]}: #{event.inspect}")
661
656
  end
662
657
  else
663
- Log.error("Unrecognized event type #{event[:type]} from #{event[:from]}")
658
+ ErrorTracker.log(self, "Unrecognized event type #{event[:type]} from #{event[:from]}")
664
659
  end
665
660
  else
666
- Log.error("Unrecognized event: #{event.class}")
661
+ ErrorTracker.log(self, "Unrecognized event: #{event.class}")
667
662
  end
668
663
  nil
669
664
  end
@@ -742,14 +737,14 @@ module RightScale
742
737
  actors.delete(actor)
743
738
  end
744
739
  end
745
- Log.error("Actors #{actors.inspect} not found in #{actors_dirs.inspect}") unless actors.empty?
740
+ ErrorTracker.log(self, "Actors #{actors.inspect} not found in #{actors_dirs.inspect}") unless actors.empty?
746
741
 
747
742
  # Perform agent-specific initialization including actor creation and registration
748
743
  if (init_file = AgentConfig.init_file)
749
744
  Log.info("[setup] Initializing agent from #{init_file}")
750
745
  instance_eval(File.read(init_file), init_file)
751
746
  else
752
- Log.error("No agent init.rb file found in init directory of #{AgentConfig.root_dir.inspect}")
747
+ ErrorTracker.log(self, "No agent init.rb file found in init directory of #{AgentConfig.root_dir.inspect}")
753
748
  end
754
749
  true
755
750
  end
@@ -786,7 +781,7 @@ module RightScale
786
781
  old.call if old.is_a? Proc
787
782
  end
788
783
  rescue Exception => e
789
- Log.error("Failed in termination", e, :trace)
784
+ ErrorTracker.log(self, "Failed in termination", e)
790
785
  end
791
786
  end
792
787
  end
@@ -828,8 +823,7 @@ module RightScale
828
823
  result = Result.new(token, from, OperationResult.non_delivery(reason), to)
829
824
  @sender.handle_response(result)
830
825
  rescue Exception => e
831
- Log.error("Failed handling non-delivery for <#{token}>", e, :trace)
832
- @exception_stats.track("message return", e)
826
+ ErrorTracker.log(self, "Failed handling non-delivery for <#{token}>", e)
833
827
  end
834
828
  end
835
829
  end
@@ -881,8 +875,7 @@ module RightScale
881
875
  end
882
876
  @sender.message_received
883
877
  rescue Exception => e
884
- Log.error("#{queue} queue processing error", e, :trace)
885
- @exception_stats.track("#{queue} queue", e, packet)
878
+ ErrorTracker.log(self, "#{queue} queue processing error", e)
886
879
  ensure
887
880
  # Relying on fact that all dispatches/deliveries are synchronous and therefore
888
881
  # need to have completed or failed by now, thus allowing packet acknowledgement
@@ -907,17 +900,16 @@ module RightScale
907
900
  @client.publish(exchange, result, :persistent => true, :mandatory => true, :log_filter => [:request_from, :tries, :persistent, :duration])
908
901
  end
909
902
  else
910
- Log.error("Failed to dispatch request #{request.trace} from queue #{queue} because no dispatcher configured")
903
+ ErrorTracker.log(self, "Failed to dispatch request #{request.trace} from queue #{queue} because no dispatcher configured")
911
904
  @request_failure_stats.update("NoConfiguredDispatcher")
912
905
  end
913
906
  rescue Dispatcher::DuplicateRequest
914
907
  rescue RightAMQP::HABrokerClient::NoConnectedBrokers => e
915
- Log.error("Failed to publish result of dispatched request #{request.trace} from queue #{queue}", e)
908
+ ErrorTracker.log(self, "Failed to publish result of dispatched request #{request.trace} from queue #{queue}", e)
916
909
  @request_failure_stats.update("NoConnectedBrokers")
917
- rescue Exception => e
918
- Log.error("Failed to dispatch request #{request.trace} from queue #{queue}", e, :trace)
910
+ rescue StandardError => e
911
+ ErrorTracker.log(self, "Failed to dispatch request #{request.trace} from queue #{queue}", e)
919
912
  @request_failure_stats.update(e.class.name)
920
- @exception_stats.track("request", e)
921
913
  end
922
914
  true
923
915
  end
@@ -932,10 +924,9 @@ module RightScale
932
924
  def deliver_response(result)
933
925
  begin
934
926
  @sender.handle_response(result)
935
- rescue Exception => e
936
- Log.error("Failed to deliver response #{result.trace}", e, :trace)
927
+ rescue StandardError => e
928
+ ErrorTracker.log(self, "Failed to deliver response #{result.trace}", e)
937
929
  @response_failure_stats.update(e.class.name)
938
- @exception_stats.track("response", e)
939
930
  end
940
931
  true
941
932
  end
@@ -968,8 +959,7 @@ module RightScale
968
959
  begin
969
960
  callback.call(type, state)
970
961
  rescue RuntimeError => e
971
- Log.error("Failed status callback", e)
972
- @exception_stats.track("update status", e)
962
+ ErrorTracker.log(self, "Failed status callback", e, nil, :caller)
973
963
  end
974
964
  end
975
965
  true
@@ -1005,38 +995,31 @@ module RightScale
1005
995
  update_status(:auth, :failed)
1006
996
  end
1007
997
  rescue Exception => e
1008
- Log.error("Failed switching mode", e)
1009
- @exception_stats.track("check status", e)
998
+ ErrorTracker.log(self, "Failed switching mode", e)
1010
999
  end
1011
1000
 
1012
1001
  begin
1013
1002
  finish_setup unless @terminating || @mode == :http
1014
1003
  rescue Exception => e
1015
- Log.error("Failed finishing setup", e)
1016
- @exception_stats.track("check status", e)
1004
+ ErrorTracker.log(self, "Failed finishing setup", e)
1017
1005
  end
1018
1006
 
1019
1007
  begin
1020
1008
  @client.queue_status(@queues, timeout = @options[:check_interval] / 10) unless @terminating || @mode == :http
1021
1009
  rescue Exception => e
1022
- Log.error("Failed checking queue status", e)
1023
- @exception_stats.track("check status", e)
1010
+ ErrorTracker.log(self, "Failed checking queue status", e)
1024
1011
  end
1025
1012
 
1026
1013
  begin
1027
1014
  publish_stats unless @terminating || @stats_routing_key.nil?
1028
- rescue Exceptions::ConnectivityFailure => e
1029
- Log.error("Failed publishing stats", e, :no_trace)
1030
1015
  rescue Exception => e
1031
- Log.error("Failed publishing stats", e)
1032
- @exception_stats.track("check status", e)
1016
+ ErrorTracker.log(self, "Failed publishing stats", e)
1033
1017
  end
1034
1018
 
1035
1019
  begin
1036
1020
  check_other(@check_status_count) unless @terminating
1037
1021
  rescue Exception => e
1038
- Log.error("Failed to perform other check status check", e)
1039
- @exception_stats.track("check status", e)
1022
+ ErrorTracker.log(self, "Failed to perform other check status check", e)
1040
1023
  end
1041
1024
 
1042
1025
  @check_status_count += 1
@@ -1131,7 +1114,7 @@ module RightScale
1131
1114
  Log.info("[stop] Continuing with termination")
1132
1115
  finish.call
1133
1116
  rescue Exception => e
1134
- Log.error("Failed while finishing termination", e, :trace)
1117
+ ErrorTracker.log(self, "Failed while finishing termination", e)
1135
1118
  begin @terminate_callback.call; rescue Exception; end
1136
1119
  end
1137
1120
  end