Skip to content

Commit

Permalink
Run perf_capture_timer by ems_id or zone
Browse files Browse the repository at this point in the history
Up until now, perf_capture_timer is never passed a parameter
So changing the parameter from zone to ems_id will not break anything.

capture_targets(zone) is temporary. we are transitioning to only passing
an ems_id. Gap is currently run by zone in the ui. So the ui will need
to change before completely making the transition from zone to ems.
  • Loading branch information
kbrock committed Oct 21, 2019
1 parent ee1a3f2 commit 3f58c9a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 22 deletions.
8 changes: 5 additions & 3 deletions app/models/metric/capture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = nil)
_log.info("Queueing performance capture...")

zone ||= MiqServer.my_server.zone
ems = ExtManagementSystem.find(ems_id) if ems_id
zone = ems.try(:zone) || MiqServer.my_server.zone
perf_capture_health_check(zone)
targets = Metric::Targets.capture_targets(zone)
targets = Metric::Targets.capture_targets(ems || zone)

targets_by_rollup_parent = calc_targets_by_rollup_parent(targets)
target_options = calc_target_options(zone, targets_by_rollup_parent)
Expand All @@ -65,6 +66,7 @@ def self.perf_capture_gap(start_time, end_time, zone_id = nil)
_log.info("Queueing performance capture for range: [#{start_time} - #{end_time}]...")

zone = Zone.find(zone_id) if zone_id
zone ||= MiqServer.my_server.zone
targets = Metric::Targets.capture_targets(zone, :exclude_storages => true)
targets.each { |target| target.perf_capture_queue('historical', :start_time => start_time, :end_time => end_time, :zone => zone) }

Expand Down
17 changes: 12 additions & 5 deletions app/models/metric/targets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,18 @@ def self.capture_vm_targets(emses, hosts)
# If a Cluster, standalone Host, or Storage is not enabled, skip it.
# If a Cluster is enabled, capture all of its Hosts.
# If a Host is enabled, capture all of its Vms.
def self.capture_targets(zone = nil, options = {})
zone = MiqServer.my_server.zone if zone.nil?
zone = Zone.find(zone) if zone.kind_of?(Integer)
zone.ext_management_systems.flat_map do |ems|
capture_ems_targets(ems, options) || []
#
# We used to run perf captures by zone, now we are running them by ems.
# For new code, please pass an ems into zone_or_ems
#
# @param zone_or_ems [Zone, ExtManagementSystem]
def self.capture_targets(zone_or_ems, options = {})
if zone_or_ems.kind_of?(ExtManagementSystem)
capture_ems_targets(zone_or_ems, options) || []
else
zone_or_ems.ext_management_systems.flat_map do |ems|
capture_ems_targets(ems, options) || []
end
end
end
end
39 changes: 25 additions & 14 deletions spec/models/metric_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@

context "executing capture_targets" do
it "should find enabled targets" do
targets = Metric::Targets.capture_targets
targets = Metric::Targets.capture_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_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

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
Expand All @@ -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_targets(@ems_vmware.reload))
end

context "executing capture_targets for realtime targets with parent objects" do
before do
@expected_targets = Metric::Targets.capture_targets
@expected_targets = Metric::Targets.capture_targets(@ems_vmware)
end

it "should create tasks and queue callbacks" do
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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) }
Expand All @@ -191,10 +191,21 @@
Metric::Capture.perf_capture_gap(t - 7.days, t - 5.days)
end

it "should queue up enabled targets for historical" do
it "should queue up enabled targets for historical by ems" do
expect(MiqQueue.count).to eq(10)

expected_targets = Metric::Targets.capture_targets(nil, :exclude_storages => true)
expected_targets = Metric::Targets.capture_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)

expect(selected).to match_array(expected)
end

it "should queue up enabled targets for historical by zone" do
expect(MiqQueue.count).to eq(10)

expected_targets = Metric::Targets.capture_targets(@ems_vmware.zone, :exclude_storages => true)
expected = expected_targets.flat_map { |t| [[t, "historical"]] * 2 } # Vm, Host, Host, Vm, Host

selected = queue_intervals(MiqQueue.all)
Expand Down Expand Up @@ -1032,19 +1043,19 @@

context "executing capture_targets" do
it "should find enabled targets" do
targets = Metric::Targets.capture_targets
targets = Metric::Targets.capture_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

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_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)
Expand Down Expand Up @@ -1318,7 +1329,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
Expand Down

0 comments on commit 3f58c9a

Please sign in to comment.