diff --git a/koku/masu/database/aws_report_db_accessor.py b/koku/masu/database/aws_report_db_accessor.py index b234d4071b..19f83bc685 100644 --- a/koku/masu/database/aws_report_db_accessor.py +++ b/koku/masu/database/aws_report_db_accessor.py @@ -275,14 +275,14 @@ def back_populate_ocp_infrastructure_costs(self, start_date, end_date, report_pe } self._prepare_and_execute_raw_sql_query(table_name, sql, sql_params) - def populate_ocp_on_aws_tag_information(self, bill_ids, start_date, end_date, cluster_id): + def populate_ocp_on_aws_tag_information(self, bill_ids, start_date, end_date, current_ocp_report_period_id): """Populate the line item aggregated totals data table.""" sql_params = { "schema": self.schema, "bill_ids": bill_ids, "start_date": start_date, "end_date": end_date, - "cluster_id": cluster_id, + "report_period_id": current_ocp_report_period_id, } # Tag Summary sql = pkgutil.get_data("masu.database", "sql/reporting_ocpawstags_summary.sql") diff --git a/koku/masu/database/azure_report_db_accessor.py b/koku/masu/database/azure_report_db_accessor.py index 013e922fa8..3eaa4f493c 100644 --- a/koku/masu/database/azure_report_db_accessor.py +++ b/koku/masu/database/azure_report_db_accessor.py @@ -152,14 +152,14 @@ def get_bill_query_before_date(self, date): """Get the cost entry bill objects with billing period before provided date.""" return AzureCostEntryBill.objects.filter(billing_period_start__lte=date) - def populate_ocp_on_azure_tag_information(self, bill_ids, start_date, end_date, cluster_id): + def populate_ocp_on_azure_tag_information(self, bill_ids, start_date, end_date, report_period_id): """Populate the line item aggregated totals data table.""" sql_params = { "schema": self.schema, "bill_ids": bill_ids, "start_date": start_date, "end_date": end_date, - "cluster_id": cluster_id, + "report_period_id": report_period_id, } # Tag summary sql = pkgutil.get_data("masu.database", "sql/reporting_ocpazuretags_summary.sql") diff --git a/koku/masu/database/gcp_report_db_accessor.py b/koku/masu/database/gcp_report_db_accessor.py index 381fc2505c..5d17f18ace 100644 --- a/koku/masu/database/gcp_report_db_accessor.py +++ b/koku/masu/database/gcp_report_db_accessor.py @@ -475,14 +475,14 @@ def get_openshift_on_cloud_matched_tags_trino( ) return [json.loads(result[0]) for result in results] - def populate_ocp_on_gcp_tag_information(self, gcp_bill_ids, start_date, end_date, cluster_id): + def populate_ocp_on_gcp_tag_information(self, gcp_bill_ids, start_date, end_date, report_period_id): """Populate the line item aggregated totals data table.""" sql_params = { "schema": self.schema, "gcp_bill_ids": gcp_bill_ids, "start_date": start_date, "end_date": end_date, - "cluster_id": cluster_id, + "report_period_id": report_period_id, } # Tag Summary sql = pkgutil.get_data("masu.database", "sql/gcp/openshift/reporting_ocpgcptags_summary.sql") diff --git a/koku/masu/database/sql/gcp/openshift/reporting_ocpgcptags_summary.sql b/koku/masu/database/sql/gcp/openshift/reporting_ocpgcptags_summary.sql index 31c8a4d835..526c13a4b9 100644 --- a/koku/masu/database/sql/gcp/openshift/reporting_ocpgcptags_summary.sql +++ b/koku/masu/database/sql/gcp/openshift/reporting_ocpgcptags_summary.sql @@ -12,7 +12,7 @@ WITH cte_tag_value AS ( jsonb_each_text(li.tags) labels WHERE li.usage_start >= {{start_date}} AND li.usage_start <= {{end_date}} - AND li.cluster_id = {{cluster_id}} + AND li.report_period_id = {{report_period_id}} AND value IS NOT NULL AND li.tags ?| (SELECT array_agg(DISTINCT key) FROM {{schema | sqlsafe}}.reporting_enabledtagkeys WHERE enabled=true AND provider_type = 'GCP') {% if bill_ids %} diff --git a/koku/masu/database/sql/reporting_ocpawstags_summary.sql b/koku/masu/database/sql/reporting_ocpawstags_summary.sql index 76ef7f6132..0d105bfebe 100644 --- a/koku/masu/database/sql/reporting_ocpawstags_summary.sql +++ b/koku/masu/database/sql/reporting_ocpawstags_summary.sql @@ -11,7 +11,7 @@ WITH cte_tag_value AS ( jsonb_each_text(li.tags) labels WHERE li.usage_start >= {{start_date}} AND li.usage_start <= {{end_date}} - AND li.cluster_id = {{cluster_id}} + AND li.report_period_id = {{report_period_id}} AND li.tags ?| (SELECT array_agg(DISTINCT key) FROM {{schema | sqlsafe}}.reporting_enabledtagkeys WHERE enabled=true AND provider_type='AWS') {% if bill_ids %} AND li.cost_entry_bill_id IN {{ bill_ids | inclause }} diff --git a/koku/masu/database/sql/reporting_ocpazuretags_summary.sql b/koku/masu/database/sql/reporting_ocpazuretags_summary.sql index d343efeb06..c78fba95e3 100644 --- a/koku/masu/database/sql/reporting_ocpazuretags_summary.sql +++ b/koku/masu/database/sql/reporting_ocpazuretags_summary.sql @@ -10,7 +10,7 @@ WITH cte_tag_value AS ( jsonb_each_text(li.tags) labels WHERE li.usage_start >= {{start_date}} AND li.usage_start <= {{end_date}} - AND li.cluster_id = {{cluster_id}} + AND li.report_period_id = {{report_period_id}} AND li.tags ?| (SELECT array_agg(DISTINCT key) FROM {{schema | sqlsafe}}.reporting_enabledtagkeys WHERE enabled=true AND provider_type='Azure') {% if bill_ids %} AND li.cost_entry_bill_id IN {{ bill_ids | inclause }} diff --git a/koku/masu/processor/ocp/ocp_cloud_parquet_summary_updater.py b/koku/masu/processor/ocp/ocp_cloud_parquet_summary_updater.py index 1c09af6059..7eb52f224c 100644 --- a/koku/masu/processor/ocp/ocp_cloud_parquet_summary_updater.py +++ b/koku/masu/processor/ocp/ocp_cloud_parquet_summary_updater.py @@ -299,7 +299,7 @@ def update_aws_summary_tables(self, openshift_provider_uuid, aws_provider_uuid, sql_params["start_date"] = start sql_params["end_date"] = end accessor.back_populate_ocp_infrastructure_costs(start, end, current_ocp_report_period_id) - accessor.populate_ocp_on_aws_tag_information(aws_bill_ids, start, end, cluster_id) + accessor.populate_ocp_on_aws_tag_information(aws_bill_ids, start, end, current_ocp_report_period_id) accessor.populate_ocp_on_aws_ui_summary_tables_trino( start, end, openshift_provider_uuid, aws_provider_uuid ) @@ -434,7 +434,9 @@ def update_azure_summary_tables(self, openshift_provider_uuid, azure_provider_uu sql_params["start_date"] = start sql_params["end_date"] = end accessor.back_populate_ocp_infrastructure_costs(start, end, current_ocp_report_period_id) - accessor.populate_ocp_on_azure_tag_information(azure_bill_ids, start, end, cluster_id) + accessor.populate_ocp_on_azure_tag_information( + azure_bill_ids, start, end, current_ocp_report_period_id + ) accessor.populate_ocp_on_azure_ui_summary_tables_trino( start, end, openshift_provider_uuid, azure_provider_uuid ) @@ -555,7 +557,7 @@ def update_gcp_summary_tables(self, openshift_provider_uuid, gcp_provider_uuid, accessor.populate_ocp_on_gcp_ui_summary_tables_trino( start, end, openshift_provider_uuid, gcp_provider_uuid ) - accessor.populate_ocp_on_gcp_tag_information(gcp_bill_ids, start, end, cluster_id) + accessor.populate_ocp_on_gcp_tag_information(gcp_bill_ids, start, end, current_ocp_report_period_id) with OCPReportDBAccessor(self._schema) as ocp_accessor: sql_params["source_type"] = "GCP" diff --git a/koku/masu/test/database/test_aws_report_db_accessor.py b/koku/masu/test/database/test_aws_report_db_accessor.py index 803442bd99..2ce03b09fb 100644 --- a/koku/masu/test/database/test_aws_report_db_accessor.py +++ b/koku/masu/test/database/test_aws_report_db_accessor.py @@ -425,6 +425,7 @@ def test_populate_ocp_on_aws_tag_information(self, mock_unleash): """ mock_unleash.return_value = True populated_keys = [] + report_period_id = 1 with schema_context(self.schema): enabled_tags = EnabledTagKeys.objects.filter(provider_type=Provider.PROVIDER_AWS, enabled=True) for enabled_tag in enabled_tags: @@ -447,7 +448,7 @@ def test_populate_ocp_on_aws_tag_information(self, mock_unleash): child_key, child_obj, child_count = populated_keys[1] TagMapping.objects.create(parent=parent_obj, child=child_obj) self.accessor.populate_ocp_on_aws_tag_information( - bill_ids, self.dh.this_month_start, self.dh.today, self.cluster_id + bill_ids, self.dh.this_month_start, self.dh.today, report_period_id ) expected_parent_count = parent_count + child_count actual_parent_count = OCPAWSCostLineItemProjectDailySummaryP.objects.filter( diff --git a/koku/masu/test/database/test_azure_report_db_accessor.py b/koku/masu/test/database/test_azure_report_db_accessor.py index 8a7687a8b0..ca29931807 100644 --- a/koku/masu/test/database/test_azure_report_db_accessor.py +++ b/koku/masu/test/database/test_azure_report_db_accessor.py @@ -348,6 +348,7 @@ def test_populate_ocp_on_aZURE_tag_information(self, mock_unleash): """ mock_unleash.return_value = True populated_keys = [] + report_period_id = 1 with schema_context(self.schema): enabled_tags = EnabledTagKeys.objects.filter(provider_type=Provider.PROVIDER_AZURE, enabled=True) for enabled_tag in enabled_tags: @@ -370,7 +371,7 @@ def test_populate_ocp_on_aZURE_tag_information(self, mock_unleash): child_key, child_obj, child_count = populated_keys[1] TagMapping.objects.create(parent=parent_obj, child=child_obj) self.accessor.populate_ocp_on_azure_tag_information( - bill_ids, self.dh.this_month_start, self.dh.today, self.ocp_cluster_id + bill_ids, self.dh.this_month_start, self.dh.today, report_period_id ) expected_parent_count = parent_count + child_count actual_parent_count = OCPAzureCostLineItemProjectDailySummaryP.objects.filter( diff --git a/koku/masu/test/database/test_gcp_report_db_accessor.py b/koku/masu/test/database/test_gcp_report_db_accessor.py index 1888307cd2..4b84184ba5 100644 --- a/koku/masu/test/database/test_gcp_report_db_accessor.py +++ b/koku/masu/test/database/test_gcp_report_db_accessor.py @@ -391,11 +391,12 @@ def test_populate_ocp_gcp_ui_summary_tables(self, mock_sql): @patch("masu.database.gcp_report_db_accessor.GCPReportDBAccessor._execute_raw_sql_query") def test_populate_ocp_on_gcp_tag_information_assert_call(self, mock_trino): """Test that we construst our SQL and execute our query.""" + report_period_id = 1 start_date = self.dh.this_month_start.date() end_date = self.dh.this_month_end.date() mock_gcp_bills = [Mock(), Mock()] - self.accessor.populate_ocp_on_gcp_tag_information(mock_gcp_bills, start_date, end_date, self.ocp_cluster_id) + self.accessor.populate_ocp_on_gcp_tag_information(mock_gcp_bills, start_date, end_date, report_period_id) mock_trino.assert_called() @patch("masu.database.gcp_report_db_accessor.GCPReportDBAccessor.schema_exists_trino") @@ -493,6 +494,7 @@ def test_populate_ocp_on_gcp_tag_information(self, mock_unleash): """ mock_unleash.return_value = True populated_keys = [] + report_period_id = 1 with schema_context(self.schema): enabled_tags = EnabledTagKeys.objects.filter(provider_type=Provider.PROVIDER_GCP, enabled=True) for enabled_tag in enabled_tags: @@ -515,7 +517,7 @@ def test_populate_ocp_on_gcp_tag_information(self, mock_unleash): child_key, child_obj, child_count = populated_keys[1] TagMapping.objects.create(parent=parent_obj, child=child_obj) self.accessor.populate_ocp_on_gcp_tag_information( - bill_ids, self.dh.this_month_start, self.dh.today, self.ocp_cluster_id + bill_ids, self.dh.this_month_start, self.dh.today, report_period_id ) expected_parent_count = parent_count + child_count actual_parent_count = OCPGCPCostLineItemProjectDailySummaryP.objects.filter(