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 Jul 15, 2023
1 parent 249cffe commit 4c1d687
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 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 @@ -238,14 +242,15 @@ 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

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 4c1d687

Please sign in to comment.