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

Simplify tag list reconstruct #12670

Merged
merged 4 commits into from
Nov 29, 2016
Merged
Show file tree
Hide file tree
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
19 changes: 3 additions & 16 deletions app/models/chargeback/rates_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,9 @@ class RatesCache
def get(perf)
@rates ||= {}
@rates[perf.hash_features_affecting_rate] ||=
begin
prefix = tag_prefix(perf)
ChargebackRate.get_assigned_for_target(perf.resource,
:tag_list => perf.tag_list_reconstruct.map! { |t| prefix + t },
:parents => perf.parents_determining_rate)
end
end

private

def tag_prefix(perf)
case perf.resource_type
when Container.name then 'container_image'
when VmOrTemplate.name then 'vm'
when ContainerProject.name then 'container_project'
end
ChargebackRate.get_assigned_for_target(perf.resource,
:tag_list => perf.tag_list_with_prefix,
:parents => perf.parents_determining_rate)
end
end
end
21 changes: 16 additions & 5 deletions app/models/metric/chargeback_helper.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
module Metric::ChargebackHelper
TAG_MANAGED_PREFIX = "/tag/managed/".freeze

def hash_features_affecting_rate
tags = tag_names.split('|').reject { |n| n.starts_with?('folder_path_') }.sort.join('|')
keys = [tags] + resource_parents.map(&:id)
keys += [resource.container_image, timestamp] if resource_type == Container.name
keys.join('_')
end

def tag_list_reconstruct
tag_list = tag_names.split("|").inject([]) { |arr, t| arr << "/tag/managed/#{t}" }
def tag_prefix
klass_prefix = case resource_type
when Container.name then 'container_image'
when VmOrTemplate.name then 'vm'
when ContainerProject.name then 'container_project'
end

klass_prefix + TAG_MANAGED_PREFIX
end

if resource_type == Container.name
def tag_list_with_prefix
if resource.kind_of?(Container)
state = resource.vim_performance_state_for_ts(timestamp.to_s)
tag_list += state.image_tag_names.split("|").inject([]) { |arr, t| arr << "/tag/managed/#{t}" } if state.present?
image_tag_name = "#{state.image_tag_names}|" if state
end
tag_list

"#{image_tag_name}#{tag_names}".split("|").reject(&:empty?).map { |x| "#{tag_prefix}#{x}" }
end

def resource_parents
Expand Down