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

Metric rollups at the Service level #15695

Merged
merged 3 commits into from
Aug 8, 2017
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
2 changes: 1 addition & 1 deletion app/models/manageiq/providers/cloud_manager/vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def mac_addresses
end

def perf_rollup_parents(interval_name = nil)
[availability_zone, host_aggregates].compact.flatten unless interval_name == 'realtime'
[availability_zone, host_aggregates, service].compact.flatten unless interval_name == 'realtime'
end

#
Expand Down
1 change: 1 addition & 0 deletions app/models/metric/ci_mixin/targets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def perf_capture_always?
when ManageIQ::Providers::Kubernetes::ContainerManager::Container then true
when ManageIQ::Providers::Kubernetes::ContainerManager::ContainerGroup then true
when ManageIQ::Providers::Kubernetes::ContainerManager::ContainerNode then true
when Service then true
# going to treat an availability_zone like a host wrt perf_capture settings
when Host, EmsCluster, AvailabilityZone, HostAggregate then Metric::Targets.perf_capture_always[:host_and_cluster]
when Storage then Metric::Targets.perf_capture_always[:storage]
Expand Down
4 changes: 3 additions & 1 deletion app/models/metric/processing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ module Metric::Processing
EmsCluster,
ExtManagementSystem,
MiqRegion,
MiqEnterprise
MiqEnterprise,
Service
]

def self.process_derived_columns(obj, attrs, ts = nil)
Expand All @@ -54,6 +55,7 @@ def self.process_derived_columns(obj, attrs, ts = nil)

DERIVED_COLS.each do |col|
dummy, group, typ, mode = col.to_s.split("_")
next if group == "vm" && obj.kind_of?(Service) && typ != "count"
case typ
when "available"
# Do not derive "available" values if there haven't been any usage
Expand Down
19 changes: 19 additions & 0 deletions app/models/metric/rollup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,25 @@ module Metric::Rollup
:derived_memory_used,
:net_usage_rate_average,
:disk_usage_rate_average
],
:Service_vms => [
:cpu_ready_delta_summation,
:cpu_system_delta_summation,
:cpu_usage_rate_average,
:cpu_usagemhz_rate_average,
:cpu_used_delta_summation,
:cpu_wait_delta_summation,
:derived_vm_allocated_disk_storage,
:derived_vm_numvcpus,
:derived_vm_used_disk_storage,
:derived_memory_used,
:derived_memory_available,
:disk_devicelatency_absolute_average,
:disk_kernellatency_absolute_average,
:disk_queuelatency_absolute_average,
:disk_usage_rate_average,
:mem_usage_absolute_average,
:net_usage_rate_average,
]
}

Expand Down
14 changes: 14 additions & 0 deletions app/models/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class Service < ApplicationRecord
belongs_to :service_template # Template this service was cloned from

has_many :dialogs, -> { distinct }, :through => :service_template
has_many :metrics, :as => :resource
has_many :metric_rollups, :as => :resource
has_many :vim_performance_states, :as => :resource

has_one :miq_request_task, :dependent => :nullify, :as => :destination
has_one :miq_request, :through => :miq_request_task
Expand Down Expand Up @@ -60,6 +63,7 @@ class Service < ApplicationRecord
include ProcessTasksMixin
include TenancyMixin
include SupportsFeatureMixin
include Metric::CiMixin

include_concern 'RetirementManagement'
include_concern 'Aggregation'
Expand Down Expand Up @@ -388,4 +392,14 @@ def queue_chargeback_report_generation(options = {})
)
_log.info "Added to queue: generate_chargeback_report for service #{name}"
end

#
# Metric methods
#

PERF_ROLLUP_CHILDREN = :vms

def perf_rollup_parents(interval_name = nil)
[].compact unless interval_name == 'realtime'
end
end
13 changes: 11 additions & 2 deletions app/models/vim_performance_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,17 @@ def capture_total(field)
def capture_assoc_ids
result = {}
ASSOCIATIONS.each do |assoc|
method = assoc
method = (resource.kind_of?(EmsCluster) ? :all_vms_and_templates : :vms_and_templates) if assoc == :vms
method = if assoc == :vms
if resource.kind_of?(EmsCluster)
:all_vms_and_templates
elsif resource.kind_of?(Service)
:vms
else
:vms_and_templates
end
else
assoc
end
next unless resource.respond_to?(method)
assoc_recs = resource.send(method)
has_state = assoc_recs[0] && assoc_recs[0].respond_to?(:state)
Expand Down
3 changes: 2 additions & 1 deletion app/models/vim_performance_tag_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class VimPerformanceTagValue < ApplicationRecord
"ContainerGroup" => [],
"ContainerProject" => [],
"ContainerService" => [],
"ContainerReplicator" => []
"ContainerReplicator" => [],
"Service" => [:vms]
}

def self.build_from_performance_record(parent_perf, options = {:save => true})
Expand Down
2 changes: 1 addition & 1 deletion app/models/vm_or_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,7 @@ def has_active_ems?
PERF_ROLLUP_CHILDREN = nil

def perf_rollup_parents(interval_name = nil)
[host].compact unless interval_name == 'realtime'
[host, service].compact unless interval_name == 'realtime'
end

# Called from integrate ws to kick off scan for vdi VMs
Expand Down
4 changes: 4 additions & 0 deletions spec/factories/vm_amazon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@
FactoryGirl.create(:ems_amazon, :vms => [x])
end
end

trait :powered_off do
raw_power_state "stopped"
end
end
end
22 changes: 22 additions & 0 deletions spec/models/metric/processing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,28 @@
end

context ".process_derived_columns" do
context "services" do
let(:vm_amazon_a) { FactoryGirl.create(:vm_amazon) }
let(:vm_amazon_b) { FactoryGirl.create(:vm_amazon, :powered_off) }
let(:service) { FactoryGirl.create(:service) }
let(:metric_a) { FactoryGirl.create(:metric_rollup_vm_hr, :resource => vm_amazon_a) }
let(:metric_b) { FactoryGirl.create(:metric_rollup_vm_hr, :resource => vm_amazon_b) }

before do
service.add_resource(vm_amazon_a)
service.add_resource(vm_amazon_b)
service.save
end

it "calculates derived values" do
derived_columns = described_class.process_derived_columns(service, metric_a.attributes.symbolize_keys)

expect(derived_columns[:derived_vm_count_on]).to eq(1)
expect(derived_columns[:derived_vm_count_off]).to eq(1)
expect(derived_columns[:derived_vm_count_total]).to eq(2)
end
end

context "on :derived_host_sockets" do
let(:hardware) { FactoryGirl.create(:hardware, :cpu_sockets => 2) }
let(:host) { FactoryGirl.create(:host, :hardware => hardware) }
Expand Down
16 changes: 16 additions & 0 deletions spec/models/metric_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,22 @@
assert_perf_capture_now @vm, :with_alerts
end
end

context "services" do
let(:service) { FactoryGirl.create(:service) }

before do
service.add_resource(@vm)
service.save
MiqQueue.delete_all
end

it "queues service rollups" do
@vm.perf_rollup_to_parents("hourly", "2010-04-14T21:51:10Z", "2010-04-14T22:50:50Z")

expect(MiqQueue.all.pluck(:class_name).uniq).to eq(%w(Service))
end
end
end

context "with a small environment and time_profile" do
Expand Down