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-5444] Adding effective price to generator #529

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion nise/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "4.6.9"
__version__ = "4.7.0"


VERSION = __version__.split(".")
7 changes: 7 additions & 0 deletions nise/generators/gcp/compute_engine_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class ComputeEngineGenerator(GCPGenerator):

LABELS = (([{"key": "vm_key_proj2", "value": "vm_label_proj2"}]), ([]))

EFFECTIVE_PRICE = ("0.0114", "0.0417", "0.1922", "0.0452")

def __init__(self, start_date, end_date, currency, project, attributes=None): # noqa: C901
"""Initialize the cloud storage generator."""
super().__init__(start_date, end_date, currency, project, attributes)
Expand Down Expand Up @@ -123,6 +125,8 @@ def _update_data(self, row): # noqa: C901
row["currency"] = self._currency
row["labels"] = self.determine_labels(self.LABELS)
row["system_labels"] = self.determine_system_labels(sku[3])
row["price.effective_price"] = choice(self.EFFECTIVE_PRICE)

if self.resource_level:
resource = self._generate_resource(
self._resource_name, self._resource_global_name, self.project.get("region")
Expand Down Expand Up @@ -183,6 +187,9 @@ def _update_data(self, row): # noqa: C901
month = datetime.strptime(row.get("usage_start_time")[:7], "%Y-%m").month
invoice["month"] = f"{year}{month:02d}"
row["invoice"] = invoice
effective_price = choice(self.EFFECTIVE_PRICE)
row["price"] = {"effective_price": effective_price}

if self.resource_level:
resource = self._generate_resource()
row["resource"] = resource
Expand Down
1 change: 1 addition & 0 deletions nise/generators/gcp/gcp_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"invoice.month",
"cost_type",
"partition_date",
"price.effective_price",
)

GCP_RESOURCE_COLUMNS = ("resource.name", "resource.global_name")
Expand Down
6 changes: 6 additions & 0 deletions nise/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ def gcp_bucket_to_dataset(gcp_bucket_name, file_name, dataset_name, table_name,
"mode": "NULLABLE",
},
{"name": "cost_type", "type": "STRING", "mode": "NULLABLE"},
{
"name": "price",
"type": "RECORD",
"fields": [{"name": "effective_price", "type": "STRING", "mode": "NULLABLE"}],
"mode": "NULLABLE",
},
{
"name": "adjustment_info",
"type": "RECORD",
Expand Down
2 changes: 2 additions & 0 deletions tests/test_gcp_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def setUp(self):
"resource.name": "resource-name",
"resource.global_name": "global-name",
"resource_level": True,
"price.effective_price": 0.04524,
}
self.now = datetime.now().replace(microsecond=0, second=0, minute=0)
self.yesterday = self.now - timedelta(days=1)
Expand Down Expand Up @@ -126,6 +127,7 @@ def test_compute_engine_init_with_usage_attributes(self):
generated_data = generator.generate_data()
list_data = list(generated_data)
self.assertEqual(list_data[0]["cost"], self.usage_attributes["usage.amount"] * self.usage_attributes["price"])
self.assertIn("price.effective_price", list_data[0])

def test_compute_engine_init_with_sku_attributes(self):
"""Test the init with sku attributes for Compute Engine."""
Expand Down
Loading