From 48c8a9579e50920844306e2eedb1593465747bef Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Mon, 10 Apr 2017 14:33:27 -0400 Subject: [PATCH 1/2] Handle an exception from target.perf_capture_queue Prevent a single target.perf_capture_queue exception from preventing the rest of the targets from being queued. If an invalid target made its way into the targets list and perf_capture_queue throws an exception then currently the remaining list of targets won't be queued. https://bugzilla.redhat.com/show_bug.cgi?id=1439888 --- app/models/metric/capture.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/models/metric/capture.rb b/app/models/metric/capture.rb index 628226fef0a..0dfa0a45399 100644 --- a/app/models/metric/capture.rb +++ b/app/models/metric/capture.rb @@ -213,9 +213,13 @@ def self.queue_captures(targets, target_options) options = target_options[target] - target.perf_capture_queue(interval_name, options) - if !target.kind_of?(Storage) && use_historical && target.last_perf_capture_on.nil? - target.perf_capture_queue('historical') + begin + target.perf_capture_queue(interval_name, options) + if !target.kind_of?(Storage) && use_historical && target.last_perf_capture_on.nil? + target.perf_capture_queue('historical') + end + rescue => err + _log.warn("Failed to queue perf_capture for target [#{target.class.name}], [#{target.id}], [#{target.name}]: #{err}") end end end From be1cf3d4cff88c54b28c5253c726f5e85b35aae0 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Mon, 10 Apr 2017 15:06:28 -0400 Subject: [PATCH 2/2] Raise a more useful exception if target.ems is nil https://bugzilla.redhat.com/show_bug.cgi?id=1439888 --- app/models/metric/ci_mixin/capture.rb | 23 +++++++++++---------- spec/models/metric/ci_mixin/capture_spec.rb | 6 +++--- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/app/models/metric/ci_mixin/capture.rb b/app/models/metric/ci_mixin/capture.rb index d4c8a4ab1b2..2b8b7c54435 100644 --- a/app/models/metric/ci_mixin/capture.rb +++ b/app/models/metric/ci_mixin/capture.rb @@ -5,16 +5,14 @@ def perf_capture_object delegate :perf_collect_metrics, :to => :perf_capture_object - def queue_name_for_metrics_collection - ems = if self.kind_of?(ExtManagementSystem) - self - elsif respond_to?(:ext_management_system) && ext_management_system.present? - ext_management_system - elsif respond_to?(:old_ext_management_system) && old_ext_management_system.present? - old_ext_management_system - end - raise _("Unsupported type %{name} (id: %{number})") % {:name => self.class.name, :number => id} if ems.nil? - ems.metrics_collector_queue_name + def ems_for_capture_target + if self.kind_of?(ExtManagementSystem) + self + elsif respond_to?(:ext_management_system) && ext_management_system.present? + ext_management_system + elsif respond_to?(:old_ext_management_system) && old_ext_management_system.present? + old_ext_management_system + end end def split_capture_intervals(interval_name, start_time, end_time, threshold = 1.day) @@ -38,8 +36,11 @@ def perf_capture_queue(interval_name, options = {}) task_id = options[:task_id] zone = options[:zone] || my_zone zone = zone.name if zone.respond_to?(:name) + ems = ems_for_capture_target + raise ArgumentError, "invalid interval_name '#{interval_name}'" unless Metric::Capture::VALID_CAPTURE_INTERVALS.include?(interval_name) raise ArgumentError, "end_time cannot be specified if start_time is nil" if start_time.nil? && !end_time.nil? + raise ArgumentError, "target does not have an ExtManagementSystem" if ems.nil? start_time = start_time.utc unless start_time.nil? end_time = end_time.utc unless end_time.nil? @@ -65,7 +66,7 @@ def perf_capture_queue(interval_name, options = {}) :class_name => self.class.name, :instance_id => id, :role => 'ems_metrics_collector', - :queue_name => queue_name_for_metrics_collection, + :queue_name => ems.metrics_collector_queue_name, :zone => zone, :state => ['ready', 'dequeue'], } diff --git a/spec/models/metric/ci_mixin/capture_spec.rb b/spec/models/metric/ci_mixin/capture_spec.rb index 3538da9d97d..dbbb09b1e5e 100644 --- a/spec/models/metric/ci_mixin/capture_spec.rb +++ b/spec/models/metric/ci_mixin/capture_spec.rb @@ -241,9 +241,9 @@ def parse_datetime(datetime) group.disconnect_inv project.disconnect_inv - expect(container.queue_name_for_metrics_collection).to eq ems.metrics_collector_queue_name - expect(group.queue_name_for_metrics_collection).to eq ems.metrics_collector_queue_name - expect(project.queue_name_for_metrics_collection).to eq ems.metrics_collector_queue_name + expect(container.ems_for_capture_target).to eq ems + expect(group.ems_for_capture_target).to eq ems + expect(project.ems_for_capture_target).to eq ems expect(container.my_zone).to eq ems.my_zone expect(group.my_zone).to eq ems.my_zone