From 86e8b821b9ba467150933176778ca76a7ca3b862 Mon Sep 17 00:00:00 2001 From: Ari Zellner Date: Wed, 19 Apr 2017 16:21:16 +0300 Subject: [PATCH] chargeback - group results with unknown project under 'unknown project' --- app/models/chargeback_container_image.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/chargeback_container_image.rb b/app/models/chargeback_container_image.rb index 5ccccf21fc0..003cbb10043 100644 --- a/app/models/chargeback_container_image.rb +++ b/app/models/chargeback_container_image.rb @@ -44,12 +44,13 @@ def self.build_results_for_report_ChargebackContainerImage(options) @data_index.store_path(:container_image, :by_container_id, c.id, c.container_image) end + @unknown_project ||= OpenStruct.new(:id => 0, :name => _('Unknown Project'), :ems_ref => _('Unknown')) build_results_for_report_chargeback(options) end def self.default_key(metric_rollup_record, ts_key) - project = @data_index.fetch_path(:container_project, :by_container_id, metric_rollup_record.resource_id) - image = @data_index.fetch_path(:container_image, :by_container_id, metric_rollup_record.resource_id) + project = self.project(metric_rollup_record) + image = self.image(metric_rollup_record) @options[:groupby] == 'project' ? "#{project.id}_#{ts_key}" : "#{project.id}_#{image.id}_#{ts_key}" end @@ -58,7 +59,7 @@ def self.image(consumption) end def self.project(consumption) - @data_index.fetch_path(:container_project, :by_container_id, consumption.resource_id) + @data_index.fetch_path(:container_project, :by_container_id, consumption.resource_id) || @unknown_project end def self.where_clause(records, _options)