Skip to content

Commit

Permalink
[COST-3814] Azure subs processing start 2 days prior to source creati…
Browse files Browse the repository at this point in the history
…on (#4836)

* source creation minus 2 days for Azure default
  • Loading branch information
cgoodfred authored Dec 14, 2023
1 parent 9bb8c30 commit a7902d3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
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 a7902d3

Please sign in to comment.