Skip to content

Commit

Permalink
metrics: combine time ranges for tests
Browse files Browse the repository at this point in the history
Instead of getting into the weeds about how granular our messages are,
we are just making sure all the time frames of interest are tested
  • Loading branch information
kbrock committed Jan 7, 2020
1 parent 953fcd8 commit 37fb722
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions spec/support/metric_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,29 @@ def queue_timings(items = MiqQueue.where(:method_name => %w[perf_capture_hourly
messages[interval_name] ||= {}
(messages[interval_name][obj] ||= []) << q.args
end
messages["historical"]&.transform_values!(&:sort!)
messages["historical"]&.transform_values! { |v| combine_consecutive(v) }

messages
end

def combine_consecutive(array)
x = array.sort!.shift
array.each_with_object([]) do |i, ac|
if i.first == x.last
x[1] = i.last
else
ac << x
x = i
end
end << x
end

# sorry, stole from the code - not really testing
def arg_day_range(start_time, end_time, threshold = 1.day)
(start_time.utc..end_time.utc).step_value(threshold).each_cons(2).collect do |s_time, e_time|
[s_time, e_time]
combine_consecutive(
(start_time.utc..end_time.utc).step_value(threshold).each_cons(2).collect do |s_time, e_time|
[s_time, e_time]
end
end
end

Expand Down

0 comments on commit 37fb722

Please sign in to comment.