From 3d8ded080e9e335317b494ef34cd4458c1db3ef6 Mon Sep 17 00:00:00 2001 From: Luke Couzens Date: Fri, 29 Nov 2024 11:34:16 +0000 Subject: [PATCH] [COST-5731] - Update OCP on AWS markup to use amortised (#5409) * [COST-5731] - Update OCP on AWS markup to use amortised --- koku/masu/database/aws_report_db_accessor.py | 11 +++++++++-- ...eporting_ocpallcostlineitem_daily_summary_aws.sql | 2 +- ..._ocpallcostlineitem_project_daily_summary_aws.sql | 2 +- .../reporting_ocpawscostlineitem_daily_summary.sql | 12 ++++++------ 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/koku/masu/database/aws_report_db_accessor.py b/koku/masu/database/aws_report_db_accessor.py index 4c4a9a8905..730705d3fd 100644 --- a/koku/masu/database/aws_report_db_accessor.py +++ b/koku/masu/database/aws_report_db_accessor.py @@ -329,11 +329,18 @@ def populate_markup_cost(self, provider_uuid, markup, start_date, end_date, bill OCPAWSCostLineItemProjectDailySummaryP.objects.filter( cost_entry_bill_id=bill_id, **date_filters ).update( - markup_cost=(F("unblended_cost") * markup), project_markup_cost=(F("unblended_cost") * markup) + markup_cost=(F("unblended_cost") * markup), + markup_cost_blended=(F("blended_cost") * markup), + markup_cost_savingsplan=(F("savingsplan_effective_cost") * markup), + markup_cost_amortized=(F("calculated_amortized_cost") * markup), + project_markup_cost=(F("calculated_amortized_cost") * markup), ) for ocpaws_model in OCP_ON_AWS_PERSPECTIVES: ocpaws_model.objects.filter(source_uuid=provider_uuid, **date_filters).update( - markup_cost=(F("unblended_cost") * markup) + markup_cost=(F("unblended_cost") * markup), + markup_cost_blended=(F("blended_cost") * markup), + markup_cost_savingsplan=(F("savingsplan_effective_cost") * markup), + markup_cost_amortized=(F("calculated_amortized_cost") * markup), ) OCPAllCostLineItemProjectDailySummaryP.objects.filter( diff --git a/koku/masu/database/sql/openshift/all/reporting_ocpallcostlineitem_daily_summary_aws.sql b/koku/masu/database/sql/openshift/all/reporting_ocpallcostlineitem_daily_summary_aws.sql index 6c6426a5b0..f53d2f3fe6 100644 --- a/koku/masu/database/sql/openshift/all/reporting_ocpallcostlineitem_daily_summary_aws.sql +++ b/koku/masu/database/sql/openshift/all/reporting_ocpallcostlineitem_daily_summary_aws.sql @@ -56,7 +56,7 @@ SELECT 'AWS'::text AS source_type, max(aws.unit), -- OCP on ALL tables should use calculated_amortized_cost sum(calculated_amortized_cost) as unblended_cost, - sum(aws.markup_cost), + sum(aws.markup_cost_amortized), max(aws.currency_code), max(cost_category_id) as cost_category_id, cast(1 as decimal) as shared_projects, diff --git a/koku/masu/database/sql/openshift/all/reporting_ocpallcostlineitem_project_daily_summary_aws.sql b/koku/masu/database/sql/openshift/all/reporting_ocpallcostlineitem_project_daily_summary_aws.sql index fb0190904f..4a425dbc54 100644 --- a/koku/masu/database/sql/openshift/all/reporting_ocpallcostlineitem_project_daily_summary_aws.sql +++ b/koku/masu/database/sql/openshift/all/reporting_ocpallcostlineitem_project_daily_summary_aws.sql @@ -58,7 +58,7 @@ SELECT 'AWS' as source_type, max(unit) as unit, -- OCP on ALL tables should use calculated_amortized_cost sum(calculated_amortized_cost) as unblended_cost, - sum(project_markup_cost) as project_markup_cost, + sum(markup_cost_amortized) as project_markup_cost, sum(pod_cost) as pod_cost, max(currency_code) as currency_code, max(cost_category_id) as cost_category_id, diff --git a/koku/masu/database/trino_sql/reporting_ocpawscostlineitem_daily_summary.sql b/koku/masu/database/trino_sql/reporting_ocpawscostlineitem_daily_summary.sql index 5146f4fda6..30b37611ad 100644 --- a/koku/masu/database/trino_sql/reporting_ocpawscostlineitem_daily_summary.sql +++ b/koku/masu/database/trino_sql/reporting_ocpawscostlineitem_daily_summary.sql @@ -1184,12 +1184,12 @@ SELECT pds.aws_uuid, ELSE calculated_amortized_cost / aws_uuid_count * cast({{markup}} as decimal(33,9)) END as markup_cost_amortized, CASE WHEN resource_id_matched = TRUE AND data_source = 'Pod' - THEN ({{pod_column | sqlsafe}} / {{node_column | sqlsafe}}) * unblended_cost - ELSE unblended_cost / aws_uuid_count + THEN ({{pod_column | sqlsafe}} / {{node_column | sqlsafe}}) * calculated_amortized_cost + ELSE calculated_amortized_cost / aws_uuid_count END as pod_cost, CASE WHEN resource_id_matched = TRUE AND data_source = 'Pod' - THEN ({{pod_column | sqlsafe}} / {{node_column | sqlsafe}}) * unblended_cost * cast({{markup}} as decimal(24,9)) - ELSE unblended_cost / aws_uuid_count * cast({{markup}} as decimal(24,9)) + THEN ({{pod_column | sqlsafe}} / {{node_column | sqlsafe}}) * calculated_amortized_cost * cast({{markup}} as decimal(24,9)) + ELSE calculated_amortized_cost / aws_uuid_count * cast({{markup}} as decimal(24,9)) END as project_markup_cost, pds.pod_labels, CASE WHEN pds.pod_labels IS NOT NULL @@ -1295,8 +1295,8 @@ SELECT max(savingsplan_effective_cost) * cast({{markup}} AS decimal(24,9)), max(calculated_amortized_cost), max(calculated_amortized_cost) * cast({{markup}} AS decimal(33,9)), - max(unblended_cost) AS pod_cost, - max(unblended_cost) * cast({{markup}} AS decimal(24,9)) AS project_markup_cost, + max(calculated_amortized_cost) AS pod_cost, + max(calculated_amortized_cost) * cast({{markup}} AS decimal(24,9)) AS project_markup_cost, max(ocp.pod_labels), cast(NULL AS varchar) AS tags, cast(NULL AS varchar) AS aws_cost_category,