Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cu schedule collector by ems #19420

Merged
merged 4 commits into from
Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 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)
_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)
Expand Down
14 changes: 11 additions & 3 deletions app/models/metric/targets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ def self.perf_capture_always=(options)
MiqRegion.my_region.perf_capture_always = options
end

def self.capture_ems_targets(ems, options = {})
case ems
when EmsCloud then capture_cloud_targets([ems], options)
when EmsInfra then capture_infra_targets([ems], options)
when ::ManageIQ::Providers::ContainerManager then capture_container_targets([ems], options)
end
end

def self.capture_infra_targets(emses, options)
load_infra_targets_data(emses, options)
all_hosts = capture_host_targets(emses)
Expand Down Expand Up @@ -141,8 +149,8 @@ def self.capture_vm_targets(emses, hosts)
def self.capture_targets(zone = nil, options = {})
zone = MiqServer.my_server.zone if zone.nil?
zone = Zone.find(zone) if zone.kind_of?(Integer)
capture_infra_targets(zone.ems_infras, options) + \
capture_cloud_targets(zone.ems_clouds, options) + \
capture_container_targets(zone.ems_containers, options)
zone.ems_metrics_collectable.flat_map do |ems|
capture_ems_targets(ems, options) || []
end
end
end
4 changes: 2 additions & 2 deletions app/models/miq_schedule_worker/jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ def storage_scan_timer
end

def metric_capture_perf_capture_timer
zone = MiqServer.my_server(true).zone
if zone.role_active?("ems_metrics_coordinator")
MiqServer.my_server.zone.ems_metrics_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"]
Expand Down
1 change: 1 addition & 0 deletions app/models/miq_schedule_worker/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ def do_work

private

# @returns Hash<class, Integer> Hash of ems_class => refresh_interval
def schedule_settings_for_ems_refresh
ExtManagementSystem.leaf_subclasses.each.with_object({}) do |klass, hash|
next unless klass.ems_type
Expand Down
5 changes: 5 additions & 0 deletions app/models/zone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ def ems_clouds
ext_management_systems.select { |e| e.kind_of?(EmsCloud) }
end

# @return [Array<ExtManagementSystem>] All emses that can collect Capacity and Utilization metrics
def ems_metrics_collectable
ext_management_systems.select { |e| e.kind_of?(EmsCloud) || e.kind_of?(EmsInfra) || e.kind_of?(ManageIQ::Providers::ContainerManager) }
end

def ems_networks
ext_management_systems.select { |e| e.kind_of?(ManageIQ::Providers::NetworkManager) }
end
Expand Down
32 changes: 16 additions & 16 deletions spec/models/metric_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,22 @@
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

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

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)
Expand Down Expand Up @@ -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
Expand Down