Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[COST-5430] Adjust EBS rate to be a daily rate #523

Merged
merged 3 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion example_aws_static_data.yml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
generators:
- EC2Generator:
start_date: 2020-03-01
start_date: today
processor_arch: 32-bit
resource_id: 55555555
product_sku: VEAJHRNKTJZQ
Expand Down Expand Up @@ -52,6 +52,19 @@
family: 'Memory Optimized'
cost: 1.000
rate: 0.500
- EBSGenerator:
start_date: today
product_sku: VEAJHRNBBBBD
resource_id: 12345674
amount: 8
rate: 0.1
tags:
resourceTags/user:storageclass: gamma
resourceTags/user:Mapping: d1
resourceTags/user:Map: d2
cost_category:
costCategory/env: ephemeral



accounts:
Expand Down
3 changes: 2 additions & 1 deletion nise/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__version__ = "4.6.6"
__version__ = "4.6.7"


VERSION = __version__.split(".")
20 changes: 14 additions & 6 deletions nise/generators/aws/ebs_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
"""Module for ebs data generation."""
import calendar
from random import choice
from random import uniform

Expand Down Expand Up @@ -53,25 +54,32 @@ def _get_storage(self):
"""Get storage data."""
return choice(self.STORAGE)

def _calculate_cost_per_day(self, start):
"""EBS charges in a monthly rate.
Therefore we need to convert to a daily rate to calculate the cost."""
num_days_in_month = calendar.monthrange(start.year, start.month)[1]
hours_in_month = num_days_in_month * 24
daily_rate = self._rate / hours_in_month
return self._amount * daily_rate

def _update_data(self, row, start, end, **kwargs):
"""Update data with generator specific data."""
row = self._add_common_usage_info(row, start, end)

rate = self._rate
amount = self._amount
cost = amount * rate
cost = self._calculate_cost_per_day(start)
location, aws_region, _, storage_region = self._get_location()
description = f"${rate} per GB-Month of snapshot data stored - {location}"
description = f"${self._rate} per GB-Month of snapshot data stored - {location}"
burst, max_iops, max_thru, max_vol_size, vol_backed, vol_type = self._get_storage()

row["lineItem/ProductCode"] = "AmazonEC2"
row["lineItem/UsageType"] = f"{storage_region}:VolumeUsage"
row["lineItem/Operation"] = "CreateVolume"
row["lineItem/ResourceId"] = self._resource_id
row["lineItem/UsageAmount"] = str(amount)
row["lineItem/UnblendedRate"] = str(rate)
row["lineItem/UnblendedRate"] = str(self._rate)
row["lineItem/UnblendedCost"] = str(cost)
row["lineItem/BlendedRate"] = str(rate)
row["lineItem/BlendedRate"] = str(self._rate)
row["lineItem/BlendedCost"] = str(cost)
row["lineItem/LineItemDescription"] = description
row["product/ProductName"] = "Amazon Elastic Compute Cloud"
Expand All @@ -89,7 +97,7 @@ def _update_data(self, row, start, end, **kwargs):
row["product/usagetype"] = f"{storage_region}:VolumeUsage"
row["product/volumeType"] = vol_type
row["pricing/publicOnDemandCost"] = str(cost)
row["pricing/publicOnDemandRate"] = str(rate)
row["pricing/publicOnDemandRate"] = str(self._rate)
row["pricing/term"] = "OnDemand"
row["pricing/unit"] = "GB-Mo"
self._add_tag_data(row)
Expand Down
Loading