:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(data-imports): stop AWS Cost Explorer utilization syncs from requesting today's date (#76542)
Tom Owersf46ea3d19214
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_cost_explorer/aws_cost_explorer.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_cost_explorer/aws_cost_explorer.pyindex c6037f5510c1..e2d741dbd5ce 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_cost_explorer/aws_cost_explorer.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_cost_explorer/aws_cost_explorer.py@@ -369,8 +369,11 @@ def get_rows(session = make_session(aws_secret_access_key, aws_session_token)credentials = Credentials(aws_access_key_id, aws_secret_access_key, aws_session_token or None)- # `End` is exclusive, so tomorrow captures today's partial (flagged estimated) too.- end = dt.datetime.now(dt.UTC).date() + dt.timedelta(days=1)+ # `End` is exclusive. Cost-and-usage operations report today's partial figures (flagged+ # estimated), so their window reaches into tomorrow; the utilization operations have no+ # data for the current, still-in-progress day and reject a window that includes it.+ today = dt.datetime.now(dt.UTC).date()+ end = today + dt.timedelta(days=1) if endpoint_config.includes_current_day else todaystart = resolve_start_date(start_date, endpoint_config, should_use_incremental_field, db_incremental_field_last_value, end)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_cost_explorer/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_cost_explorer/settings.pyindex 52c2afe9ef94..9acf1ebae2c8 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_cost_explorer/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_cost_explorer/settings.py@@ -47,6 +47,10 @@ class CostExplorerEndpointConfig:# Response sub-structures to flatten into the row, as (member name, column prefix) pairs.# An empty prefix keeps the sub-structure's own field names.nested_keys: tuple[tuple[str, str], ...] = field(default_factory=tuple)+ # Only cost-and-usage operations return a flagged-`Estimated` figure for the current,+ # still-in-progress day. The utilization operations have no such concept and reject a+ # request whose window includes today with DataUnavailableException.+ includes_current_day: bool = FalseAWS_COST_EXPLORER_ENDPOINTS: dict[str, CostExplorerEndpointConfig] = {@@ -61,6 +65,7 @@ AWS_COST_EXPLORER_ENDPOINTS: dict[str, CostExplorerEndpointConfig] = {group_by=("SERVICE", "LINKED_ACCOUNT"),window_days=92,restatement_lookback_days=7,+ includes_current_day=True,),"cost_and_usage_monthly": CostExplorerEndpointConfig(name="cost_and_usage_monthly",@@ -73,6 +78,7 @@ AWS_COST_EXPLORER_ENDPOINTS: dict[str, CostExplorerEndpointConfig] = {group_by=("SERVICE", "LINKED_ACCOUNT"),window_days=366,restatement_lookback_days=45,+ includes_current_day=True,),"reservation_utilization_daily": CostExplorerEndpointConfig(name="reservation_utilization_daily",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_cost_explorer/tests/test_aws_cost_explorer.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_cost_explorer/tests/test_aws_cost_explorer.pyindex 1a487aa3c4fe..4dcac5654a2d 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_cost_explorer/tests/test_aws_cost_explorer.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_cost_explorer/tests/test_aws_cost_explorer.py@@ -510,6 +510,16 @@ class TestGetRows:assert send.call_args_list[0][0][3]["TimePeriod"]["End"] == "2024-03-04"+ @pytest.mark.parametrize("endpoint", ["reservation_utilization_daily", "savings_plans_utilization_daily"])+ def test_utilization_endpoints_stop_at_today_because_aws_has_no_data_for_it_yet(self, endpoint: str) -> None:+ # Unlike cost-and-usage, AWS rejects a utilization request whose window reaches into+ # the current, still-in-progress day with DataUnavailableException.+ manager = FakeResumeManager()++ _, send = self._run([{}], manager, endpoint=endpoint)++ assert send.call_args_list[0][0][3]["TimePeriod"]["End"] == "2024-03-03"+def test_wide_ranges_are_split_into_windows_walked_oldest_first(self) -> None:manager = FakeResumeManager()