Skip to content

Commit

Permalink
[COST-5731] - Update OCP on AWS markup to use amortised (#5409)
Browse files Browse the repository at this point in the history
* [COST-5731] - Update OCP on AWS markup to use amortised
  • Loading branch information
lcouzens authored Nov 29, 2024
1 parent df66399 commit 3d8ded0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
11 changes: 9 additions & 2 deletions koku/masu/database/aws_report_db_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 3d8ded0

Please sign in to comment.