From aa0379cfdc77f7d6036c3abddaafca5d68e2139a Mon Sep 17 00:00:00 2001 From: David Nakabaale Date: Thu, 9 May 2024 14:10:46 -0400 Subject: [PATCH] [COST-4930] Add AWS EC2 Compute summary table (#5069) * [COST-4930] Add AWS EC2 Compute summary table * seperate migration from model creation --- koku/reporting/provider/aws/models.py | 68 +++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/koku/reporting/provider/aws/models.py b/koku/reporting/provider/aws/models.py index 2fcf2b471f..119a969f04 100644 --- a/koku/reporting/provider/aws/models.py +++ b/koku/reporting/provider/aws/models.py @@ -169,6 +169,74 @@ class Meta: source_uuid = models.UUIDField(unique=False, null=True) +class AWSCostEntryLineItemSummaryByEC2Compute(models.Model): + """Represents a monthly aggregation of EC2 compute instance usage hours and costs. + + This table stores monthly aggregated data for EC2 compute instances, + detailing usage hours, associated costs and other key attributes. + """ + + class PartitionInfo: + partition_type = "RANGE" + partition_cols = ["usage_start"] + + class Meta: + """Meta for AWSCostEntryLineItemSummaryByEC2ComputeResource.""" + + db_table = "reporting_awscostentrylineitem_summary_by_ec2_compute" + + indexes = [ + # 'ec2c' for EC2 Compute + models.Index(fields=["usage_start"], name="ec2c_usage_start_idx"), + models.Index(fields=["usage_account_id"], name="ec2c_usage_account_id_idx"), + models.Index(fields=["account_alias"], name="ec2c_account_alias_idx"), + models.Index(fields=["resource_id"], name="ec2c_resource_id_idx"), + models.Index(fields=["instance_name"], name="ec2c_instance_name_idx"), + models.Index(fields=["instance_type"], name="ec2c_instance_type_idx"), + models.Index(fields=["region"], name="ec2c_region_idx"), + models.Index(fields=["operating_system"], name="ec2c_os_idx"), + GinIndex(fields=["tags"], name="ec2c_tags_idx"), + GinIndex(fields=["cost_category"], name="ec2c_cost_category_idx"), + ] + + uuid = models.UUIDField(primary_key=True) + usage_start = models.DateField(null=False) + usage_end = models.DateField(null=True) + cost_entry_bill = models.ForeignKey("AWSCostEntryBill", on_delete=models.CASCADE, null=True) + account_alias = models.ForeignKey("AWSAccountAlias", on_delete=models.PROTECT, null=True) + organizational_unit = models.ForeignKey("AWSOrganizationalUnit", on_delete=models.SET_NULL, null=True) + usage_account_id = models.CharField(max_length=50, null=False) + resource_id = models.CharField(max_length=256, null=False) + instance_name = models.CharField(max_length=50, null=True) + instance_type = models.CharField(max_length=50, null=True) + operating_system = models.CharField(max_length=50, null=True) + availability_zone = models.CharField(max_length=50, null=True) + region = models.CharField(max_length=50, null=True) + vcpu = models.IntegerField(null=True) + memory = models.CharField(max_length=50, null=True) + unit = models.CharField(max_length=63, null=True) + usage_amount = models.DecimalField(max_digits=24, decimal_places=9, null=True) + normalization_factor = models.FloatField(null=True) + normalized_usage_amount = models.FloatField(null=True) + currency_code = models.CharField(max_length=10) + unblended_rate = models.DecimalField(max_digits=24, decimal_places=9, null=True) + unblended_cost = models.DecimalField(max_digits=24, decimal_places=9, null=True) + markup_cost = models.DecimalField(max_digits=24, decimal_places=9, null=True) + blended_rate = models.DecimalField(max_digits=24, decimal_places=9, null=True) + blended_cost = models.DecimalField(max_digits=24, decimal_places=9, null=True) + markup_cost_blended = models.DecimalField(max_digits=33, decimal_places=15, null=True) + savingsplan_effective_cost = models.DecimalField(max_digits=24, decimal_places=9, null=True) + markup_cost_savingsplan = models.DecimalField(max_digits=33, decimal_places=15, null=True) + calculated_amortized_cost = models.DecimalField(max_digits=33, decimal_places=9, null=True) + markup_cost_amortized = models.DecimalField(max_digits=33, decimal_places=9, null=True) + public_on_demand_cost = models.DecimalField(max_digits=24, decimal_places=9, null=True) + public_on_demand_rate = models.DecimalField(max_digits=24, decimal_places=9, null=True) + tax_type = models.TextField(null=True) + tags = JSONField(null=True) + source_uuid = models.UUIDField(unique=False, null=True) + cost_category = JSONField(null=True) + + class AWSAccountAlias(models.Model): """The alias table for AWS accounts."""