From 26368fbfdac5edf953e4087e917cc4691215c1ca Mon Sep 17 00:00:00 2001 From: Keenan Brock Date: Wed, 13 Nov 2019 16:47:47 -0500 Subject: [PATCH] metrics: move capture date logic to gap call --- app/models/metric/capture.rb | 5 ++++- app/models/metric/ci_mixin/capture.rb | 6 ++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/models/metric/capture.rb b/app/models/metric/capture.rb index bca52ad781a0..0f8f924a4ab1 100644 --- a/app/models/metric/capture.rb +++ b/app/models/metric/capture.rb @@ -64,6 +64,9 @@ def self.perf_capture_timer(ems_id) end def self.perf_capture_gap(start_time, end_time, zone_id = nil, ems_id = nil) + raise ArgumentError, "end_time and start_time must be specified" if start_time.nil? || end_time.nil? + raise _("Start time must be earlier than End time") if start_time > end_time + _log.info("Queueing performance capture for range: [#{start_time} - #{end_time}]...") emses = if ems_id @@ -74,7 +77,7 @@ def self.perf_capture_gap(start_time, end_time, zone_id = nil, ems_id = nil) end emses.each do |ems| targets = Metric::Targets.capture_ems_targets(ems, :exclude_storages => true) - target_options = Hash.new { |_n, _v| {:start_time => start_time, :end_time => end_time, :zone => ems.zone, :interval => 'historical'} } + target_options = Hash.new { |_n, _v| {:start_time => start_time.utc, :end_time => end_time.utc, :zone => ems.zone, :interval => 'historical'} } queue_captures(targets, target_options) end diff --git a/app/models/metric/ci_mixin/capture.rb b/app/models/metric/ci_mixin/capture.rb index 18f3d41ba959..8a21c6a4edbb 100644 --- a/app/models/metric/ci_mixin/capture.rb +++ b/app/models/metric/ci_mixin/capture.rb @@ -18,7 +18,6 @@ def ems_for_capture_target end def split_capture_intervals(interval_name, start_time, end_time, threshold = 1.day) - raise _("Start time must be earlier than End time") if start_time > end_time # Create an array of ordered pairs from start_time and end_time so that each ordered pair is contained # within the threshold. Then, reverse it so the newest ordered pair is first: # start_time = 2017/01/01 12:00:00, end_time = 2017/01/04 12:00:00 @@ -32,8 +31,8 @@ def split_capture_intervals(interval_name, start_time, end_time, threshold = 1.d private :split_capture_intervals def perf_capture_queue(interval_name, options = {}) - start_time = options[:start_time]&.utc - end_time = options[:end_time]&.utc + start_time = options[:start_time] + end_time = options[:end_time] priority = options[:priority] || Metric::Capture.interval_priority(interval_name) task_id = options[:task_id] zone = options[:zone] || my_zone @@ -41,7 +40,6 @@ def perf_capture_queue(interval_name, options = {}) 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? # cb is the task used to group cluster realtime metrics