module Metric::ChargebackHelper
  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}" }

    if resource_type == Container.name
      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?
    end
    tag_list
  end

  def resource_parents
    [parent_host, parent_ems_cluster, parent_storage, parent_ems, resource.try(:tenant)].compact
  end
end

module Metric::ChargebackHelper
  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}" }

    if resource_type == Container.name
      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?
    end
    tag_list
  end

  def resource_parents
    [parent_host || resource.try(:host),
     parent_ems_cluster || resource.try(:ems_cluster),
     parent_storage || resource.try(:storage),
     parent_ems || resource.try(:ext_management_system),
     resource.try(:tenant)
    ].compact
  end
end

Select resources when there are nil in MetricRollups records
Select resources when there are nil in MetricRollups records

In this PR #11648 we
introduced selecting rates according to first MetricRollup
record of group. We can do it because group of these records
belong to one resource.

Selection is based on
MetricRollup#parent_host or parent_ems_cluster or
parent_storage or parent_ems but sometimes this fields in
MetricRollup are nil and it produces empty cells on the
report - it is because proper rate was not selected.

Fix provides that we are selecting parents from
the resource direcly when there are not exists in
MetricRollup.
