Skip to content

Commit

Permalink
cu cops
Browse files Browse the repository at this point in the history
so much has moved, these are all marked as
needing to be changed
  • Loading branch information
kbrock committed Nov 20, 2019
1 parent a7404eb commit 0470e92
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
8 changes: 5 additions & 3 deletions app/models/manageiq/providers/base_manager/metrics_capture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,25 @@ 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

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

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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 0470e92

Please sign in to comment.