Skip to content

Commit

Permalink
Don't expect total_cost field from Azure API (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
Iain-S authored Sep 5, 2024
1 parent fa1a7bd commit db8228c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 0 additions & 2 deletions usage_function/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,12 @@ def test_retrieve_usage_1(self) -> None:
datum_1 = DummyAzureUsage()
datum_1.quantity = 1
datum_1.cost = 1
datum_1.total_cost = 1
datum_1.unit_price = 1
datum_1.effective_price = 1

datum_2 = DummyAzureUsage()
datum_2.quantity = 1
datum_2.cost = 1
datum_2.total_cost = 1
datum_2.unit_price = 1
datum_2.effective_price = 1

Expand Down
6 changes: 4 additions & 2 deletions usage_function/utils/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,14 @@ def retrieve_usage(
if i % 200 == 0:
logging.warning("Requesting item %d", i)

usage_item = models.Usage(**vars(item))
item_dict = dict(vars(item))

# When AmortizedCost metric is being used, the cost and effective_price values
# for reserved instances are not zero, thus the cost value is moved to
# amortised_cost
usage_item.total_cost = usage_item.cost
item_dict["total_cost"] = item_dict["cost"]

usage_item = models.Usage(**item_dict)

if usage_item.reservation_id is not None:
usage_item.amortised_cost = usage_item.cost
Expand Down

0 comments on commit db8228c

Please sign in to comment.