Skip to content

Commit 989975c

Browse files
myersCodylcouzens
andauthored
[COST-5548] Remove usage related to unattributed storage (#5326)
* [COST-5548] Remove usage related to unattributed storage Co-authored-by: Luke Couzens <[email protected]>
1 parent bd32348 commit 989975c

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

koku/api/report/aws/openshift/provider_map.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def __init__(self, provider, report_type, schema_name, cost_type, markup_cost="m
207207
Coalesce(F(self.markup_cost), Value(0, output_field=DecimalField()))
208208
* Coalesce("exchange_rate", Value(1, output_field=DecimalField()))
209209
),
210-
"usage": Sum(F("usage_amount")),
210+
"usage": Sum(Coalesce(F("usage_amount"), Value(0, output_field=DecimalField()))),
211211
"usage_units": Coalesce(Max("unit"), Value("GB-Mo")),
212212
},
213213
"annotations": {
@@ -249,7 +249,7 @@ def __init__(self, provider, report_type, schema_name, cost_type, markup_cost="m
249249
),
250250
# the `currency_annotation` is inserted by the `annotations` property of the query-handler
251251
"cost_units": Coalesce("currency_annotation", Value("USD", output_field=CharField())),
252-
"usage": Sum("usage_amount"),
252+
"usage": Sum(Coalesce(F("usage_amount"), Value(0, output_field=DecimalField()))),
253253
"usage_units": Coalesce(Max("unit"), Value("GB-Mo")),
254254
"clusters": ArrayAgg(Coalesce("cluster_alias", "cluster_id"), distinct=True),
255255
"source_uuid": ArrayAgg(
@@ -303,7 +303,7 @@ def __init__(self, provider, report_type, schema_name, cost_type, markup_cost="m
303303
Coalesce(F(self.markup_cost), Value(0, output_field=DecimalField()))
304304
* Coalesce("exchange_rate", Value(1, output_field=DecimalField()))
305305
),
306-
"usage": Sum(F("usage_amount")),
306+
"usage": Sum(Coalesce(F("usage_amount"), Value(0, output_field=DecimalField()))),
307307
"usage_units": Coalesce(Max("unit"), Value("GB-Mo")),
308308
},
309309
"aggregate_key": "usage_amount",
@@ -346,7 +346,7 @@ def __init__(self, provider, report_type, schema_name, cost_type, markup_cost="m
346346
),
347347
# the `currency_annotation` is inserted by the `annotations` property of the query-handler
348348
"cost_units": Coalesce("currency_annotation", Value("USD", output_field=CharField())),
349-
"usage": Sum("usage_amount"),
349+
"usage": Sum(Coalesce(F("usage_amount"), Value(0, output_field=DecimalField()))),
350350
"usage_units": Coalesce(Max("unit"), Value("Hrs")),
351351
"clusters": ArrayAgg(Coalesce("cluster_alias", "cluster_id"), distinct=True),
352352
"source_uuid": ArrayAgg(

koku/masu/database/trino_sql/reporting_ocpawscostlineitem_daily_summary.sql

+8-4
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,11 @@ SELECT cast(uuid() as varchar) as aws_uuid, -- need a new uuid or it will dedup
631631
max(aws.availability_zone) as availability_zone,
632632
max(aws.region) as region,
633633
max(aws.unit) as unit,
634-
max(aws.usage_amount) as usage_amount,
634+
CASE
635+
WHEN max(ocp.persistentvolumeclaim) = ''
636+
THEN cast(NULL as double)
637+
ELSE max(aws.usage_amount)
638+
END as usage_amount,
635639
max(aws.currency_code) as currency_code,
636640
max(ocp.persistentvolumeclaim_capacity_gigabyte) / max(aws_disk.capacity) * max(aws.unblended_cost) as unblended_cost,
637641
(max(persistentvolumeclaim_capacity_gigabyte) / max(aws_disk.capacity) * max(aws.unblended_cost)) * cast({{markup}} as decimal(24,9)) as markup_cost,
@@ -686,7 +690,7 @@ WHERE ocp.source = {{ocp_source_uuid}}
686690
AND aws.month = {{month}}
687691
-- Filter out Node Network Costs since they cannot be attributed to a namespace and are accounted for later
688692
AND aws.data_transfer_direction IS NULL
689-
AND ocp.namespace != 'Storage Unattributed'
693+
AND ocp.namespace != 'Storage unattributed'
690694
AND aws.resource_id_matched = True
691695
GROUP BY aws.uuid, ocp.namespace, ocp.pod_labels, ocp.volume_labels
692696
{% endif %}
@@ -769,7 +773,7 @@ SELECT cast(uuid() as varchar) as aws_uuid, -- need a new uuid or it will dedup
769773
max(aws.availability_zone) as availability_zone,
770774
max(aws.region) as region,
771775
max(aws.unit) as unit,
772-
max(aws.usage_amount) as usage_amount,
776+
cast(NULL as double) as usage_amount,
773777
max(aws.currency_code) as currency_code,
774778
(max(aws_disk.capacity) - max(pv_cap.total_pv_capacity)) / max(aws_disk.capacity) * max(aws.unblended_cost) as unblended_cost,
775779
((max(aws_disk.capacity) - max(pv_cap.total_pv_capacity)) / max(aws_disk.capacity) * max(aws.unblended_cost)) * cast({{markup}} as decimal(24,9)) as markup_cost,
@@ -805,7 +809,7 @@ WHERE ocp.source = {{ocp_source_uuid}}
805809
AND aws.month = {{month}}
806810
-- Filter out Node Network Costs since they cannot be attributed to a namespace and are accounted for later
807811
AND aws.data_transfer_direction IS NULL
808-
AND ocp.namespace != 'Storage Unattributed'
812+
AND ocp.namespace != 'Storage unattributed'
809813
AND aws_disk.capacity != pv_cap.total_pv_capacity -- prevent inserting zero cost rows
810814
GROUP BY aws.uuid, aws.resource_id
811815
{% endif %}

0 commit comments

Comments
 (0)