From 3520af619277df0807fa844a99dd2ae8aa1e8fd5 Mon Sep 17 00:00:00 2001 From: Gregg Tanzillo Date: Fri, 18 Aug 2017 17:20:10 -0400 Subject: [PATCH] Rate selection using union of all tags in reporting period --- .../chargeback/consumption_with_rollups.rb | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/app/models/chargeback/consumption_with_rollups.rb b/app/models/chargeback/consumption_with_rollups.rb index 36ccc6cf5c1..4dde0cdda74 100644 --- a/app/models/chargeback/consumption_with_rollups.rb +++ b/app/models/chargeback/consumption_with_rollups.rb @@ -1,7 +1,7 @@ class Chargeback class ConsumptionWithRollups < Consumption delegate :timestamp, :resource, :resource_id, :resource_name, :resource_type, :parent_ems, - :hash_features_affecting_rate, :tag_list_with_prefix, :parents_determining_rate, + :parents_determining_rate, :to => :first_metric_rollup_record def initialize(metric_rollup_records, start_time, end_time) @@ -10,7 +10,7 @@ def initialize(metric_rollup_records, start_time, end_time) end def tag_names - first_metric_rollup_record.tag_names.split('|') + @tag_names ||= @rollups.map { |m| m.tag_names.split('|') }.flatten.uniq end def max(metric) @@ -30,6 +30,23 @@ def chargeback_fields_present @chargeback_fields_present ||= @rollups.count(&:chargeback_fields_present?) end + def tag_list_with_prefix + @tag_list_with_prefix ||= @rollups.map { |m| m.tag_list_with_prefix }.flatten.uniq + end + + # def hash_features_affecting_rate + # @rollups.map { |m| m.hash_features_affecting_rate.split("|") }.flatten.uniq.join("|") + # end + + def hash_features_affecting_rate + @hash_features_affecting_rate ||= begin + tags = tag_names.reject { |n| n.starts_with?('folder_path_') }.sort.join('|') + keys = [tags] + first_metric_rollup_record.resource_parents.map(&:id) + keys += [first_metric_rollup_record.resource.container_image, timestamp] if resource_type == Container.name + keys.join('_') + end + end + private def born_at