Skip to content

Commit

Permalink
Add MiqQueue#tracking_label
Browse files Browse the repository at this point in the history
many times we add a task_id for logging only.
As we are getting away from task_id,
we don't want to loose the logging.

This allows us to transition away from task_id
The tracking_label will be set in the target system,
so a single request can be traced through the various systems
  • Loading branch information
kbrock committed Jun 23, 2017
1 parent b75c767 commit d2ad01f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/miq_queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def self.put(options)
options[:queue_name] ||= create_with_options[:queue_name] || "generic"
options[:msg_timeout] ||= create_with_options[:msg_timeout] || TIMEOUT
options[:task_id] = $_miq_worker_current_msg.try(:task_id) unless options.key?(:task_id)
options[:tracking_label] = Thread.current[:tracking_label] || options[:task_id] unless options.key?(:tracking_label)
options[:role] = options[:role].to_s unless options[:role].nil?

options[:args] = [options[:args]] if options[:args] && !options[:args].kind_of?(Array)
Expand Down
2 changes: 2 additions & 0 deletions app/models/miq_queue_worker_base/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def deliver_queue_message(msg)

begin
$_miq_worker_current_msg = msg
Thread.current[:tracking_label] = msg.tracking_label || msg.task_id
status, message, result = msg.deliver

if status == MiqQueue::STATUS_TIMEOUT
Expand All @@ -122,6 +123,7 @@ def deliver_queue_message(msg)
msg.unget
ensure
$_miq_worker_current_msg = nil # to avoid log messages inadvertantly prefixed by previous task_id
Thread.current[:tracking_label] = nil
#
# This tells the broker to release any memory being held on behalf of this process
# and reset the global broker handle ($vim_broker_client).
Expand Down

0 comments on commit d2ad01f

Please sign in to comment.