Skip to content

Commit b1a0123

Browse files
samdoranmyersCody
andauthored
[COST-5315] Return network_unattributed_distributed costs in the OCP costs API (#5231)
* Add network_unattributed_distributed to reports/openshift/costs/ API * Add test for expected distributed cost values --------- Co-authored-by: Cody Myers <[email protected]>
1 parent 6c28e4b commit b1a0123

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

koku/api/report/ocp/provider_map.py

+2
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ def __init__(self, provider, report_type, schema_name):
245245
+ self.distributed_unattributed_storage_cost,
246246
"cost_platform_distributed": self.distributed_platform_cost,
247247
"cost_worker_unallocated_distributed": self.distributed_worker_cost,
248+
"cost_network_unattributed_distributed": self.distributed_unattributed_network_cost,
248249
"cost_storage_unattributed_distributed": self.distributed_unattributed_storage_cost,
249250
},
250251
"default_ordering": {"cost_total": "desc"},
@@ -274,6 +275,7 @@ def __init__(self, provider, report_type, schema_name):
274275
+ self.distributed_unattributed_network_cost,
275276
"cost_platform_distributed": self.distributed_platform_cost,
276277
"cost_worker_unallocated_distributed": self.distributed_worker_cost,
278+
"cost_network_unattributed_distributed": self.distributed_unattributed_network_cost,
277279
"cost_storage_unattributed_distributed": self.distributed_unattributed_storage_cost,
278280
# the `currency_annotation` is inserted by the `annotations` property of the query-handler
279281
"cost_units": Coalesce("currency_annotation", Value("USD", output_field=CharField())),

koku/api/report/ocp/query_handler.py

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def __init__(self, parameters):
7575
"cost_usage": {"key": "usage", "group": "cost"},
7676
"cost_platform_distributed": {"key": "platform_distributed", "group": "cost"},
7777
"cost_worker_unallocated_distributed": {"key": "worker_unallocated_distributed", "group": "cost"},
78+
"cost_network_unattributed_distributed": {"key": "network_unattributed_distributed", "group": "cost"},
7879
"cost_storage_unattributed_distributed": {"key": "storage_unattributed_distributed", "group": "cost"},
7980
"cost_total_distributed": {"key": "distributed", "group": "cost"},
8081
"cost_total": {"key": "total", "group": "cost"},

koku/api/report/test/ocp/view/test_views.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,19 @@ def test_execute_query_ocp_costs_group_by_project__distributed_costs(self):
593593
.get("total")
594594
)
595595
expected_total = cost if cost is not None else 0
596-
total = data.get("meta", {}).get("total", {}).get("cost", {}).get("total", {}).get("value", 0)
596+
meta_total_cost = data.get("meta", {}).get("total", {}).get("cost", {})
597+
total = meta_total_cost.get("total", {}).get("value", 0)
597598
distributed_cost = data.get("meta", {}).get("total", {}).get("cost", {}).get("distributed", {}).get("value", 0)
599+
expected_dist_cost_keys = {
600+
"platform_distributed",
601+
"worker_unallocated_distributed",
602+
"network_unattributed_distributed",
603+
"storage_unattributed_distributed",
604+
}
605+
self.assertTrue(
606+
expected_dist_cost_keys.issubset(meta_total_cost),
607+
f"Missing {expected_dist_cost_keys.difference(meta_total_cost)}",
608+
)
598609
self.assertNotEqual(total, Decimal(0))
599610
self.assertNotEqual(distributed_cost, Decimal(0))
600611
self.assertAlmostEqual(distributed_cost, expected_total, 6)

0 commit comments

Comments
 (0)