Skip to content

Commit

Permalink
Merge branch 'main' into fix_default_dtypes
Browse files Browse the repository at this point in the history
  • Loading branch information
myersCody authored Dec 14, 2023
2 parents 092dbd5 + bdd582d commit 031283c
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 21 deletions.
95 changes: 74 additions & 21 deletions koku/hcs/database/sql/reporting_aws_hcs_daily_summary.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,49 @@
SELECT
*,
lineitem_resourceid,
lineitem_usagestartdate,
bill_payeraccountid,
lineitem_usageaccountid,
lineitem_legalentity,
lineitem_lineitemdescription,
bill_billingentity,
lineitem_productcode,
lineitem_availabilityzone,
lineitem_lineitemtype,
product_productfamily,
product_instancetype,
product_region,
pricing_unit,
resourcetags,
costcategory,
lineitem_usageamount,
lineitem_normalizationfactor,
lineitem_normalizedusageamount,
lineitem_currencycode,
lineitem_unblendedrate,
CASE
WHEN
(
try_cast(product_vcpu AS INT) <= 4
AND (lineitem_lineitemdescription LIKE '%Red Hat%' OR lineitem_lineitemdescription LIKE '%RHEL%')
) THEN 0.06 * lineitem_usageamount
WHEN
(
try_cast(product_vcpu AS INT) > 4
AND (lineitem_lineitemdescription LIKE '%Red Hat%' OR lineitem_lineitemdescription LIKE '%RHEL%')
) THEN 0.13 * lineitem_usageamount
ELSE lineitem_unblendedcost
END AS lineitem_unblendedcost,
lineitem_blendedrate,
lineitem_blendedcost,
pricing_publicondemandcost,
pricing_publicondemandrate,
savingsplan_savingsplaneffectivecost,
product_productname,
bill_invoiceid,
product_vcpu,
source,
year,
month,
{{ebs_acct_num}} as ebs_account_id,
{{org_id}} as org_id
FROM
Expand All @@ -9,28 +53,37 @@ WHERE
AND year = {{year}}
AND month = {{month}}
AND (
-- private offer
(
bill_billingentity = 'AWS Marketplace'
AND lineitem_legalentity like '%Red Hat%'
AND lineitem_legalentity LIKE '%Red Hat%'
)
-- alternative CCSP
OR (
lineitem_legalentity LIKE '%Amazon Web Services%'
AND product_productname LIKE '%Red Hat%'
)
OR (
lineitem_legalentity LIKE '%AWS%'
AND product_productname LIKE '%Red Hat%'
)
-- CCSP with estimated costs
OR (
lineitem_legalentity LIKE '%Amazon Web Services%'
AND lineitem_lineitemdescription LIKE '%Red Hat%'
)
OR (
lineitem_legalentity LIKE '%Amazon Web Services%'
AND lineitem_lineitemdescription LIKE '%RHEL%'
)
OR (
lineitem_legalentity LIKE '%AWS%'
AND lineitem_lineitemdescription LIKE '%Red Hat%'
)
OR (
lineitem_legalentity LIKE '%AWS%'
AND lineitem_lineitemdescription LIKE '%RHEL%'
)
-- OR (
-- lineitem_legalentity like '%Amazon Web Services%'
-- AND lineitem_lineitemdescription like '%Red Hat%'
-- )
-- OR (
-- lineitem_legalentity like '%Amazon Web Services%'
-- AND lineitem_lineitemdescription like '%RHEL%'
-- )
-- OR (
-- lineitem_legalentity like '%AWS%'
-- AND lineitem_lineitemdescription like '%Red Hat%'
-- )
-- OR (
-- lineitem_legalentity like '%AWS%'
-- AND lineitem_lineitemdescription like '%RHEL%'
-- )
)
AND lineitem_usagestartdate >= {{date}}
AND lineitem_usagestartdate < date_add(
'day', 1, {{date}}
)
AND lineitem_usagestartdate < date_add('day', 1, {{date}})
3 changes: 3 additions & 0 deletions koku/subs/subs_data_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ def __init__(self, tracing_id, context):
self.creation_processing_time = self.provider_created_timestamp.replace(
microsecond=0, second=0, minute=0, hour=0
) - timedelta(days=1)
if self.provider_type == Provider.PROVIDER_AZURE:
# Since Azure works on days with complete data, use -2 days for initial processing as -1 wont be complete
self.creation_processing_time = self.creation_processing_time - timedelta(days=1)
self.tracing_id = tracing_id
self.s3_resource = get_s3_resource(
settings.S3_SUBS_ACCESS_KEY, settings.S3_SUBS_SECRET, settings.S3_SUBS_REGION
Expand Down
17 changes: 17 additions & 0 deletions koku/subs/test/test_subs_data_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ def setUpClass(cls):
"provider_type": cls.aws_provider_type,
"provider_uuid": cls.aws_provider.uuid,
}
azure_context = {
"schema": cls.schema,
"provider_type": cls.azure_provider_type,
"provider_uuid": cls.azure_provider.uuid,
}
with patch("subs.subs_data_extractor.get_s3_resource"):
with patch("subs.subs_data_extractor.SUBSDataExtractor._execute_trino_raw_sql_query"):
cls.extractor = SUBSDataExtractor(cls.tracing_id, context)
cls.azure_extractor = SUBSDataExtractor(cls.tracing_id, azure_context)

def test_subs_s3_path(self):
"""Test that the generated s3 path is expected"""
Expand Down Expand Up @@ -281,3 +287,14 @@ def test_bulk_update_latest_processed_time(self):
)
self.assertEqual(subs_record_1.latest_processed_time, expected_time)
self.assertEqual(subs_record_2.latest_processed_time, expected_time)

def test_provider_creation_time(self):
"""Test provider processing time for different provider types."""
aws_expected = self.aws_provider.created_timestamp.replace(
microsecond=0, second=0, minute=0, hour=0
) - timedelta(days=1)
azure_expected = self.azure_provider.created_timestamp.replace(
microsecond=0, second=0, minute=0, hour=0
) - timedelta(days=2)
self.assertEqual(aws_expected, self.extractor.creation_processing_time)
self.assertEqual(azure_expected, self.azure_extractor.creation_processing_time)

0 comments on commit 031283c

Please sign in to comment.