Skip to content

Commit

Permalink
Merge pull request #14718 from agrare/bz_1439888_metrics_collection_n…
Browse files Browse the repository at this point in the history
…il_queue_name

Handle exception when a metrics target doesn't have an ext_management_system
(cherry picked from commit d7a82f2)

https://bugzilla.redhat.com/show_bug.cgi?id=1441272
  • Loading branch information
Fryguy authored and simaishi committed Apr 11, 2017
1 parent 1b5829b commit add1b94
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
10 changes: 7 additions & 3 deletions app/models/metric/capture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,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
Expand Down
23 changes: 12 additions & 11 deletions app/models/metric/ci_mixin/capture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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?
Expand Down Expand Up @@ -76,7 +77,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'],
}
Expand Down
6 changes: 3 additions & 3 deletions spec/models/metric/ci_mixin/capture_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,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
Expand Down

0 comments on commit add1b94

Please sign in to comment.