Skip to content

Commit

Permalink
Merge pull request #19443 from kbrock/cu_collector_tests
Browse files Browse the repository at this point in the history
[WIP] Cap&U collector tests
  • Loading branch information
agrare authored Nov 5, 2019
2 parents 37f1c09 + f511115 commit c53fbbe
Show file tree
Hide file tree
Showing 9 changed files with 1,352 additions and 1,034 deletions.
115 changes: 113 additions & 2 deletions spec/models/metric/capture_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
describe Metric::Capture do
include Spec::Support::MetricHelper

before do
MiqRegion.seed

@zone = EvmSpecHelper.local_miq_server.zone
end

describe ".alert_capture_threshold" do
let(:target) { FactoryBot.build(:host_vmware) }

Expand All @@ -25,6 +33,69 @@
end
end

describe ".perf_capture_timer" do
context "with enabled and disabled vmware targets", :with_enabled_disabled_vmware do
let(:expected_queue_items) do
{
%w[ManageIQ::Providers::Vmware::InfraManager::Host perf_capture_realtime] => 3,
%w[ManageIQ::Providers::Vmware::InfraManager::Host perf_capture_historical] => 24,
%w[Storage perf_capture_hourly] => 1,
%w[ManageIQ::Providers::Vmware::InfraManager::Vm perf_capture_realtime] => 2,
%w[ManageIQ::Providers::Vmware::InfraManager::Vm perf_capture_historical] => 16,
%w[MiqTask destroy_older_by_condition] => 1
}
end

it "should queue up enabled targets" do
stub_settings_merge(:performance => {:history => {:initial_capture_days => 7}})
Metric::Capture.perf_capture_timer(@ems_vmware.id)

expect(MiqQueue.group(:class_name, :method_name).count).to eq(expected_queue_items)
assert_metric_targets(Metric::Targets.capture_ems_targets(@ems_vmware.reload))
end

it "calling perf_capture_timer when existing capture messages are on the queue in dequeue state should NOT merge" do
Metric::Capture.perf_capture_timer(@ems_vmware.id)
messages = MiqQueue.where(:class_name => "Host", :method_name => 'capture_metrics_realtime')
messages.each { |m| m.update_attribute(:state, "dequeue") }

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
end

context "with enabled and disabled openstack targets" do
before do
@ems_openstack = FactoryBot.create(:ems_openstack, :zone => @zone)
@availability_zone = FactoryBot.create(:availability_zone_target)
@ems_openstack.availability_zones << @availability_zone
@vms_in_az = FactoryBot.create_list(:vm_openstack, 2, :ems_id => @ems_openstack.id)
@availability_zone.vms = @vms_in_az
@availability_zone.vms.push(FactoryBot.create(:vm_openstack, :ems_id => nil))
@vms_not_in_az = FactoryBot.create_list(:vm_openstack, 3, :ems_id => @ems_openstack.id)

MiqQueue.delete_all
end

context "executing perf_capture_timer" do
before do
stub_settings(:performance => {:history => {:initial_capture_days => 7}})
Metric::Capture.perf_capture_timer(@ems_openstack.id)
end

it "should queue up enabled targets" do
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)
assert_metric_targets(expected_targets)
end
end
end
end

describe ".standard_capture_threshold" do
let(:host) { FactoryBot.build(:host_vmware) }

Expand All @@ -43,8 +114,7 @@
end

it "produces default with class not found" do
stub_performance_settings(:capture_threshold => {:vm => "4.minutes",
:default => "10.minutes"})
stub_performance_settings(:capture_threshold => {:vm => "4.minutes", :default => "10.minutes"})
Timecop.freeze(Time.now.utc) do
expect(described_class.standard_capture_threshold(host)).to eq 10.minutes.ago.utc
end
Expand All @@ -69,6 +139,45 @@
end
end

describe ".perf_capture_now" do
context "with enabled and disabled targets" do
before do
@ems_vmware = FactoryBot.create(:ems_vmware, :zone => @zone)
storages = FactoryBot.create_list(:storage_target_vmware, 2)
@vmware_clusters = FactoryBot.create_list(:cluster_target, 2)
@ems_vmware.ems_clusters = @vmware_clusters

6.times do |n|
host = FactoryBot.create(:host_target_vmware, :ext_management_system => @ems_vmware)
@ems_vmware.hosts << host

@vmware_clusters[n / 2].hosts << host if n < 4
host.storages << storages[n / 3]
end

MiqQueue.delete_all
end

context "executing perf_capture_gap" do
before do
t = Time.now.utc
Metric::Capture.perf_capture_gap(t - 7.days, t - 5.days)
end

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

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)

expect(selected).to match_array(expected)
end
end
end
end

describe ".perf_capture_now?" do
before do
stub_performance_settings(
Expand Down Expand Up @@ -132,6 +241,8 @@
end
end

private

def stub_performance_settings(hash)
stub_settings(:performance => hash)
end
Expand Down
58 changes: 58 additions & 0 deletions spec/models/metric/ci_mixin/capture_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
describe Metric::CiMixin::Capture do
before do
MiqRegion.seed

@zone = EvmSpecHelper.local_miq_server.zone
end

require ManageIQ::Providers::Openstack::Engine.root.join("spec/tools/openstack_data/openstack_data_test_helper")
let(:zone) { EvmSpecHelper.create_guid_miq_server_zone[2] }
let(:mock_meter_list) { OpenstackMeterListData.new }
Expand Down Expand Up @@ -432,4 +438,56 @@ def verify_perf_capture_queue_historical(last_perf_capture_on, total_queue_items
expect(project.my_zone).to eq ems.my_zone
end
end

describe ".perf_capture_realtime_now" do
context "with enabled and disabled targets", :with_enabled_disabled_vmware do
context "executing perf_capture_realtime_now" do
before do
@vm = Vm.first
@vm.perf_capture_realtime_now
end

it "should queue up realtime capture for vm" do
expect(MiqQueue.count).to eq(1)

msg = MiqQueue.first
expect(msg.priority).to eq(MiqQueue::HIGH_PRIORITY)
expect(msg.instance_id).to eq(@vm.id)
expect(msg.class_name).to eq("ManageIQ::Providers::Vmware::InfraManager::Vm")
end

context "with an existing queue item at a lower priority" do
before do
MiqQueue.first.update_attribute(:priority, MiqQueue::NORMAL_PRIORITY)
@vm.perf_capture_realtime_now
end

it "should raise the priority of the existing queue item" do
expect(MiqQueue.count).to eq(1)

msg = MiqQueue.first
expect(msg.priority).to eq(MiqQueue::HIGH_PRIORITY)
expect(msg.instance_id).to eq(@vm.id)
expect(msg.class_name).to eq("ManageIQ::Providers::Vmware::InfraManager::Vm")
end
end

context "with an existing queue item at a higher priority" do
before do
MiqQueue.first.update_attribute(:priority, MiqQueue::MAX_PRIORITY)
@vm.perf_capture_realtime_now
end

it "should not lower the priority of the existing queue item" do
expect(MiqQueue.count).to eq(1)

msg = MiqQueue.first
expect(msg.priority).to eq(MiqQueue::MAX_PRIORITY)
expect(msg.instance_id).to eq(@vm.id)
expect(msg.class_name).to eq("ManageIQ::Providers::Vmware::InfraManager::Vm")
end
end
end
end
end
end
Loading

0 comments on commit c53fbbe

Please sign in to comment.