Skip to content

Commit

Permalink
Metric::Rollup#aggregate_column
Browse files Browse the repository at this point in the history
extract logic into own method
  • Loading branch information
kbrock committed Aug 1, 2023
1 parent d10075a commit 9f6b517
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/models/metric/rollup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,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 @@ -250,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

0 comments on commit 9f6b517

Please sign in to comment.