From 0470e924ee220c9553f5d4d61f7f84a71ba7a4a3 Mon Sep 17 00:00:00 2001 From: Keenan Brock Date: Wed, 20 Nov 2019 10:59:35 -0500 Subject: [PATCH] cu cops so much has moved, these are all marked as needing to be changed --- .../providers/base_manager/metrics_capture.rb | 8 +++++--- .../base_manager/metrics_capture_spec.rb | 16 ++++++++-------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/models/manageiq/providers/base_manager/metrics_capture.rb b/app/models/manageiq/providers/base_manager/metrics_capture.rb index 4a8b094a541..f9c47b7aad3 100644 --- a/app/models/manageiq/providers/base_manager/metrics_capture.rb +++ b/app/models/manageiq/providers/base_manager/metrics_capture.rb @@ -54,14 +54,14 @@ def perf_capture_health_check q_items = MiqQueue.select(:method_name, :created_on).order(:created_on) .where(:state => "ready", :role => "ems_metrics_collector", - :method_name => %w(perf_capture perf_capture_realtime perf_capture_hourly perf_capture_historical), + :method_name => %w[perf_capture perf_capture_realtime perf_capture_hourly perf_capture_historical], :zone => my_zone) items_by_interval = q_items.group_by(&:method_name) items_by_interval.reverse_merge!("perf_capture_realtime" => [], "perf_capture_hourly" => [], "perf_capture_historical" => []) items_by_interval.each do |method_name, items| interval = method_name.sub("perf_capture_", "") msg = "#{items.length} #{interval.inspect} captures on the queue for zone [#{my_zone}]" - msg << " - oldest: [#{items.first.created_on.utc.iso8601}], recent: [#{items.last.created_on.utc.iso8601}]" if items.length > 0 + msg << " - oldest: [#{items.first.created_on.utc.iso8601}], recent: [#{items.last.created_on.utc.iso8601}]" if items.present? _log.info(msg) end end @@ -94,6 +94,7 @@ def perf_capture_now?(target) return true if target.last_perf_capture_on.nil? return true if target.last_perf_capture_on < Metric::Capture.standard_capture_threshold(target) return false if target.last_perf_capture_on >= Metric::Capture.alert_capture_threshold(target) + MiqAlert.target_needs_realtime_capture?(target) end @@ -183,6 +184,7 @@ def perf_capture_queue(target, interval_name, options = {}) queue_item_options = queue_item.merge(:method_name => "perf_capture_#{item_interval}") queue_item_options[:args] = start_and_end_time if start_and_end_time.present? next if item_interval != 'realtime' && messages[start_and_end_time].try(:priority) == priority + MiqQueue.put_or_update(queue_item_options) do |msg, qi| # reason for setting MiqQueue#miq_task_id is to initializes MiqTask.started_on column when message delivered. qi[:miq_task_id] = task_id if task_id && item_interval == "realtime" @@ -198,7 +200,7 @@ def perf_capture_queue(target, interval_name, options = {}) # rerun the job (either with new task or higher priority) qi.delete(:state) if task_id && item_interval == "realtime" - existing_tasks = (((msg.miq_callback || {})[:args] || []).first) || [] + existing_tasks = ((msg.miq_callback || {})[:args] || []).first || [] qi[:miq_callback] = cb.merge(:args => [existing_tasks + [task_id]]) end qi diff --git a/spec/models/manageiq/providers/base_manager/metrics_capture_spec.rb b/spec/models/manageiq/providers/base_manager/metrics_capture_spec.rb index 82fda1ed599..ea86e514613 100644 --- a/spec/models/manageiq/providers/base_manager/metrics_capture_spec.rb +++ b/spec/models/manageiq/providers/base_manager/metrics_capture_spec.rb @@ -71,9 +71,9 @@ def verify_perf_capture_queue(last_perf_capture_on, total_queue_items) it "when last_perf_capture_on is nil (first time)" do MiqQueue.delete_all Timecop.freeze do - Timecop.travel(Time.now.end_of_day - 6.hours) + Timecop.travel(Time.now.utc.end_of_day - 6.hours) verify_perf_capture_queue(nil, 1) - Timecop.travel(Time.now + 20.minutes) + Timecop.travel(Time.now.utc + 20.minutes) verify_perf_capture_queue(nil, 1) end end @@ -81,7 +81,7 @@ def verify_perf_capture_queue(last_perf_capture_on, total_queue_items) it "when last_perf_capture_on is very old (older than the realtime_cut_off of 4.hours.ago)" do MiqQueue.delete_all Timecop.freeze do - Timecop.travel(Time.now.end_of_day - 6.hours) + Timecop.travel(Time.now.utc.end_of_day - 6.hours) verify_perf_capture_queue((10.days + 5.hours + 23.minutes).ago, 11) end end @@ -89,7 +89,7 @@ def verify_perf_capture_queue(last_perf_capture_on, total_queue_items) it "when last_perf_capture_on is recent (before the realtime_cut_off of 4.hours.ago)" do MiqQueue.delete_all Timecop.freeze do - Timecop.travel(Time.now.end_of_day - 6.hours) + Timecop.travel(Time.now.utc.end_of_day - 6.hours) verify_perf_capture_queue((0.days + 2.hours + 5.minutes).ago, 1) end end @@ -99,7 +99,7 @@ def verify_perf_capture_queue(last_perf_capture_on, total_queue_items) Timecop.freeze do # set a specific time of day to avoid sporadic test failures that fall on the exact right time to bump the # queue items to 12 instead of 11 - current_time = Time.now.end_of_day - 6.hours + current_time = Time.now.utc.end_of_day - 6.hours Timecop.travel(current_time) last_perf_capture_on = (10.days + 5.hours + 23.minutes).ago verify_perf_capture_queue(last_perf_capture_on, 11) @@ -131,7 +131,7 @@ def verify_perf_capture_queue_historical(last_perf_capture_on, total_queue_items MiqQueue.delete_all Timecop.freeze do allow(Metric::Capture).to receive(:historical_days).and_return(7) - current_time = Time.now.end_of_day - 6.hours + current_time = Time.now.utc.end_of_day - 6.hours Timecop.travel(current_time) verify_perf_capture_queue_historical(nil, 8) Timecop.travel(current_time + 20.minutes) @@ -145,7 +145,7 @@ def verify_perf_capture_queue_historical(last_perf_capture_on, total_queue_items # set a specific time of day to avoid sporadic test failures that fall on the exact right time to bump the # queue items to 12 instead of 11 allow(Metric::Capture).to receive(:historical_days).and_return(7) - current_time = Time.now.end_of_day - 6.hours + current_time = Time.now.utc.end_of_day - 6.hours last_capture_on = (10.days + 5.hours + 23.minutes).ago Timecop.travel(current_time) verify_perf_capture_queue_historical(last_capture_on, 8) @@ -160,7 +160,7 @@ def verify_perf_capture_queue_historical(last_perf_capture_on, total_queue_items # set a specific time of day to avoid sporadic test failures that fall on the exact right time to bump the # queue items to 12 instead of 11 allow(Metric::Capture).to receive(:historical_days).and_return(7) - current_time = Time.now.end_of_day - 6.hours + current_time = Time.now.utc.end_of_day - 6.hours last_capture_on = (10.days + 5.hours + 23.minutes).ago Timecop.travel(current_time) verify_perf_capture_queue_historical(last_capture_on, 8)