Skip to content

Commit

Permalink
Rate selection using union of all tags in reporting period
Browse files Browse the repository at this point in the history
  • Loading branch information
gtanzillo committed Aug 18, 2017
1 parent 7444e38 commit 3520af6
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions app/models/chargeback/consumption_with_rollups.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 3520af6

Please sign in to comment.