From b08ccb224ad2b83895f1f73311ac23cb63bddade Mon Sep 17 00:00:00 2001 From: Keenan Brock Date: Sat, 8 Jul 2023 00:28:11 -0400 Subject: [PATCH] Metric::Rollup#aggregate_column extract logic into own method --- app/models/metric/rollup.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/metric/rollup.rb b/app/models/metric/rollup.rb index af6dd534317..a3dd1fee6c6 100644 --- a/app/models/metric/rollup.rb +++ b/app/models/metric/rollup.rb @@ -162,6 +162,10 @@ def self.excluded_col_for_expression?(col) DERIVED_COLS_EXCLUDED_CLASSES = ['MiqRegion', 'MiqEnterprise'] TAG_SEP = "|" + def self.aggregate_columns(klass, 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 @@ -238,6 +242,7 @@ def self.rollup_realtime_perfs(obj, rt_perfs, new_perf = {}) new_perf end + # @param assoc association to fetch from model (values are from obj.class::PERF_ROLLUP_CHILDREN) def self.rollup_child_metrics(obj, timestamp, interval_name, assoc) ts = timestamp.kind_of?(Time) ? timestamp.utc.iso8601 : timestamp recs = obj.vim_performance_state_association(timestamp, assoc).to_a @@ -245,7 +250,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, interval_name) agg_cols.each do |c| # Initialize aggregation col values and counts to zero before starting counts[c] = 0