From 42424ae251e65445f1abe42f368e3bfcf17b13fb Mon Sep 17 00:00:00 2001 From: Keenan Brock Date: Mon, 21 Oct 2019 15:39:10 -0400 Subject: [PATCH] Run perf_capture_timer by ems_id (vs zone) Up until now, perf_capture_timer is never passed a parameter So changing the parameter from zone to ems_id will not break anything. --- app/models/metric/capture.rb | 7 +++--- app/models/miq_schedule_worker/jobs.rb | 17 ++++++++------ spec/models/metric_spec.rb | 32 +++++++++++++------------- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/app/models/metric/capture.rb b/app/models/metric/capture.rb index 02a74dbb93a6..6bd0d99f5570 100644 --- a/app/models/metric/capture.rb +++ b/app/models/metric/capture.rb @@ -43,12 +43,13 @@ def self.alert_capture_threshold(target) ::Settings.performance.capture_threshold_with_alerts.default) end - def self.perf_capture_timer(zone = nil) + def self.perf_capture_timer(ems_id) _log.info("Queueing performance capture...") - zone ||= MiqServer.my_server.zone + ems = ExtManagementSystem.find(ems_id) + zone = ems.zone perf_capture_health_check(zone) - targets = Metric::Targets.capture_targets(zone) + targets = Metric::Targets.capture_ems_targets(ems) targets_by_rollup_parent = calc_targets_by_rollup_parent(targets) target_options = calc_target_options(zone, targets_by_rollup_parent) diff --git a/app/models/miq_schedule_worker/jobs.rb b/app/models/miq_schedule_worker/jobs.rb index ada9c16732a9..1d4fad445fa0 100644 --- a/app/models/miq_schedule_worker/jobs.rb +++ b/app/models/miq_schedule_worker/jobs.rb @@ -68,13 +68,16 @@ def storage_scan_timer end def metric_capture_perf_capture_timer - queue_work( - :class_name => "Metric::Capture", - :method_name => "perf_capture_timer", - :role => "ems_metrics_coordinator", - :priority => MiqQueue::HIGH_PRIORITY, - :state => ["ready", "dequeue"] - ) + MiqServer.my_server.zone.ems_collectable.each do |ems| + queue_work( + :class_name => "Metric::Capture", + :method_name => "perf_capture_timer", + :args => [ems.id], + :role => "ems_metrics_coordinator", + :priority => MiqQueue::HIGH_PRIORITY, + :state => ["ready", "dequeue"] + ) + end end def metric_purging_purge_realtime_timer diff --git a/spec/models/metric_spec.rb b/spec/models/metric_spec.rb index e44b44370c7e..682f220a6313 100644 --- a/spec/models/metric_spec.rb +++ b/spec/models/metric_spec.rb @@ -48,14 +48,14 @@ MiqQueue.delete_all end - context "executing capture_targets" do + context "executing capture_ems_targets" do it "should find enabled targets" do - targets = Metric::Targets.capture_targets + targets = Metric::Targets.capture_ems_targets(@ems_vmware.reload) assert_infra_targets_enabled targets, %w(ManageIQ::Providers::Vmware::InfraManager::Vm ManageIQ::Providers::Vmware::InfraManager::Host ManageIQ::Providers::Vmware::InfraManager::Host ManageIQ::Providers::Vmware::InfraManager::Vm ManageIQ::Providers::Vmware::InfraManager::Host Storage) end it "should find enabled targets excluding storages" do - targets = Metric::Targets.capture_targets(nil, :exclude_storages => true) + targets = Metric::Targets.capture_ems_targets(@ems_vmware.reload, :exclude_storages => true) assert_infra_targets_enabled targets, %w(ManageIQ::Providers::Vmware::InfraManager::Vm ManageIQ::Providers::Vmware::InfraManager::Host ManageIQ::Providers::Vmware::InfraManager::Host ManageIQ::Providers::Vmware::InfraManager::Vm ManageIQ::Providers::Vmware::InfraManager::Host) end end @@ -63,7 +63,7 @@ context "executing perf_capture_timer" do before do stub_settings_merge(:performance => {:history => {:initial_capture_days => 7}}) - Metric::Capture.perf_capture_timer + Metric::Capture.perf_capture_timer(@ems_vmware.id) end let(:expected_queue_items) do @@ -79,12 +79,12 @@ it "should queue up enabled targets" do expect(MiqQueue.group(:class_name, :method_name).count).to eq(expected_queue_items) - assert_metric_targets + assert_metric_targets(Metric::Targets.capture_ems_targets(@ems_vmware.reload)) end - context "executing capture_targets for realtime targets with parent objects" do + context "executing capture_ems_targets for realtime targets with parent objects" do before do - @expected_targets = Metric::Targets.capture_targets + @expected_targets = Metric::Targets.capture_ems_targets(@ems_vmware) end it "should create tasks and queue callbacks" do @@ -120,7 +120,7 @@ end it "calling perf_capture_timer when existing capture messages are on the queue should merge messages and append new task id to cb args" do - Metric::Capture.perf_capture_timer + Metric::Capture.perf_capture_timer(@ems_vmware.id) @vmware_clusters.each do |cluster| expected_hosts = cluster.hosts.select { |h| @expected_targets.include?(h) } next if expected_hosts.empty? @@ -162,14 +162,14 @@ messages = MiqQueue.where(:class_name => "Host", :method_name => 'capture_metrics_realtime') messages.each { |m| m.update_attribute(:state, "dequeue") } - Metric::Capture.perf_capture_timer + Metric::Capture.perf_capture_timer(@ems_vmware.id) messages = MiqQueue.where(:class_name => "Host", :method_name => 'capture_metrics_realtime') messages.each { |m| expect(m.lock_version).to eq(1) } end it "calling perf_capture_timer a second time should create another task with the correct time window" do - Metric::Capture.perf_capture_timer + Metric::Capture.perf_capture_timer(@ems_vmware.id) @vmware_clusters.each do |cluster| expected_hosts = cluster.hosts.select { |h| @expected_targets.include?(h) } @@ -194,7 +194,7 @@ it "should queue up enabled targets for historical" do expect(MiqQueue.count).to eq(10) - expected_targets = Metric::Targets.capture_targets(nil, :exclude_storages => true) + expected_targets = Metric::Targets.capture_ems_targets(@ems_vmware.reload, :exclude_storages => true) expected = expected_targets.flat_map { |t| [[t, "historical"]] * 2 } # Vm, Host, Host, Vm, Host selected = queue_intervals(MiqQueue.all) @@ -1030,9 +1030,9 @@ MiqQueue.delete_all end - context "executing capture_targets" do + context "executing capture_ems_targets" do it "should find enabled targets" do - targets = Metric::Targets.capture_targets + targets = Metric::Targets.capture_ems_targets(@ems_openstack) assert_cloud_targets_enabled targets, %w(ManageIQ::Providers::Openstack::CloudManager::Vm ManageIQ::Providers::Openstack::CloudManager::Vm ManageIQ::Providers::Openstack::CloudManager::Vm ManageIQ::Providers::Openstack::CloudManager::Vm ManageIQ::Providers::Openstack::CloudManager::Vm) end end @@ -1040,11 +1040,11 @@ context "executing perf_capture_timer" do before do stub_settings(:performance => {:history => {:initial_capture_days => 7}}) - Metric::Capture.perf_capture_timer + Metric::Capture.perf_capture_timer(@ems_openstack.id) end it "should queue up enabled targets" do - expected_targets = Metric::Targets.capture_targets + expected_targets = Metric::Targets.capture_ems_targets(@ems_openstack) expect(MiqQueue.group(:method_name).count).to eq('perf_capture_realtime' => expected_targets.count, 'perf_capture_historical' => expected_targets.count * 8, 'destroy_older_by_condition' => 1) @@ -1318,7 +1318,7 @@ def assert_perf_capture_now(target, mode) end end - def assert_metric_targets(expected_targets = Metric::Targets.capture_targets) + def assert_metric_targets(expected_targets) expected = expected_targets.flat_map do |t| # Storage is hourly only # Non-storage historical is expecting 7 days back, plus partial day = 8