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::Rollup - simplify column declarations #22608

Merged
merged 2 commits into from
Aug 12, 2023
Merged
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
54 changes: 15 additions & 39 deletions app/models/metric/rollup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ module Metric::Rollup
[:stat_container_group_create_rate,
:stat_container_group_delete_rate,
:stat_container_image_registration_rate]
STORAGE_COLS = Metric.columns_hash.collect { |c, _h| c.to_sym if c.starts_with?("derived_storage_") }.compact
STORAGE_COLS = Metric.columns_hash.collect { |c, _h| c.to_sym if c.starts_with?("derived_storage_") }.compact.freeze

NON_STORAGE_ROLLUP_COLS = (ROLLUP_COLS - STORAGE_COLS)
NON_STORAGE_ROLLUP_COLS = (ROLLUP_COLS - STORAGE_COLS).freeze
CONTAINER_ROLLUP_COLS = [:cpu_usage_rate_average, :derived_vm_numvcpus, :derived_memory_used, :net_usage_rate_average].freeze
VM_ROLLUP_COLS = [:cpu_usage_rate_average, :derived_memory_used, :disk_usage_rate_average, :net_usage_rate_average].freeze

AGGREGATE_COLS = {
:MiqEnterprise_miq_regions => ROLLUP_COLS,
Expand Down Expand Up @@ -39,42 +41,12 @@ module Metric::Rollup
:derived_vm_numvcpus,
:derived_vm_used_disk_storage,
],
:ContainerImage_containers => [
:cpu_usage_rate_average,
:derived_vm_numvcpus,
:derived_memory_used,
:net_usage_rate_average
],
:ContainerProject_all_container_groups => [
:cpu_usage_rate_average,
:derived_vm_numvcpus,
:derived_memory_used,
:net_usage_rate_average
],
:ContainerService_container_groups => [
:cpu_usage_rate_average,
:derived_vm_numvcpus,
:derived_memory_used,
:net_usage_rate_average
],
:ContainerReplicator_container_groups => [
:cpu_usage_rate_average,
:derived_vm_numvcpus,
:derived_memory_used,
:net_usage_rate_average
],
:AvailabilityZone_vms => [
:cpu_usage_rate_average,
:derived_memory_used,
:net_usage_rate_average,
:disk_usage_rate_average
],
:HostAggregate_vms => [
:cpu_usage_rate_average,
:derived_memory_used,
:net_usage_rate_average,
:disk_usage_rate_average
],
:ContainerImage_containers => CONTAINER_ROLLUP_COLS,
:ContainerProject_all_container_groups => CONTAINER_ROLLUP_COLS,
:ContainerService_container_groups => CONTAINER_ROLLUP_COLS,
:ContainerReplicator_container_groups => CONTAINER_ROLLUP_COLS,
:AvailabilityZone_vms => VM_ROLLUP_COLS,
:HostAggregate_vms => VM_ROLLUP_COLS,
:Service_vms => [
:cpu_ready_delta_summation,
:cpu_system_delta_summation,
Expand Down Expand Up @@ -190,6 +162,10 @@ def self.excluded_col_for_expression?(col)
DERIVED_COLS_EXCLUDED_CLASSES = ['MiqRegion', 'MiqEnterprise']
TAG_SEP = "|"

def self.aggregate_columns(klass, assoc, interval_name)
interval_name == "realtime" ? const_get("#{klass.base_class.name.underscore.upcase}_REALTIME_COLS") : AGGREGATE_COLS["#{klass.base_class}_#{assoc}".to_sym]
end

def self.rollup_realtime(obj, rt_ts, _interval_name, _time_profile, new_perf, orig_perf)
# Roll up realtime metrics from child objects
children = obj.class::PERF_ROLLUP_CHILDREN
Expand Down Expand Up @@ -278,7 +254,7 @@ def self.rollup_child_metrics(obj, timestamp, interval_name, assoc)
result = {}
counts = {}

agg_cols = interval_name == "realtime" ? const_get("#{obj.class.base_class.name.underscore.upcase}_REALTIME_COLS") : AGGREGATE_COLS["#{obj.class.base_class}_#{assoc}".to_sym]
agg_cols = aggregate_columns(obj.class, assoc, interval_name)
agg_cols.each do |c|
# Initialize aggregation col values and counts to zero before starting
counts[c] = 0
Expand Down