Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Rate selection using union of all tags in reporting period #15857

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that some tag_names on the rollup can be nil, so probably we need something like:

@rollups.where.not(:tag_names => nil ).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