: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 tracking a transient S3 blip in calculate_table_size as a bug (#108894)
Tom Owersd4f49261d2a5
diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/calculate_table_size.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/calculate_table_size.pyindex a553c121efd4..56eb1adc728e 100644--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/calculate_table_size.py+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/calculate_table_size.py@@ -1,4 +1,3 @@-import errnoimport dataclassesfrom django.conf import settings@@ -7,7 +6,6 @@ from django.db import DatabaseError, close_old_connectionsfrom structlog.contextvars import bind_contextvarsfrom temporalio import activity-from posthog.temporal.common.errors import NonReportableErrorfrom posthog.temporal.common.logger import get_loggerfrom products.data_warehouse.backend.facade.api import get_size_of_folder@@ -118,14 +116,20 @@ def calculate_table_size_activity(inputs: CalculateTableSizeActivityInputs) -> Nif total_mib is None:total_mib = get_size_of_folder(s3_folder)except OSError as e:- if e.errno not in (errno.EMFILE, errno.ENFILE):+ from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.delta.errors import ( # noqa: PLC0415 — keeps the heavy deltalake dep off this activity module's import path+ TransientObjectStoreError,+ is_transient_object_store_error,+ )++ if not is_transient_object_store_error(e):raise- # Fd pressure on this worker (e.g. botocore loading a data file while building the S3- # client) — the same transient-capacity class postgres.py's _is_too_many_open_files_error- # already recognizes on the connect path. A descriptor frees the moment another- # connection/client in this worker closes, so it's never a defect in this activity.- logger.warning("Too many open files calculating table size in S3", exc_info=e)- raise NonReportableError("Too many open files calculating table size in S3") from e+ # Covers this worker's own fd pressure (EMFILE/ENFILE, e.g. botocore loading a data file+ # while building the S3 client) and known-transient S3/object-store blips (IMDS/STS hiccups,+ # dropped connections) hit opening the Delta log (_live_delta_size_mib) or listing the query+ # folder (get_size_of_folder) — see is_transient_object_store_error. A retry recovers on its+ # own, so it shouldn't page anyone.+ logger.warning("Transient object-store error calculating table size in S3", exc_info=e)+ raise TransientObjectStoreError(str(e)) from elogger.debug(f"Total size in MiB = {total_mib:.2f}")diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_calculate_table_size.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_calculate_table_size.pyindex 3452be707808..7ad8af64efa5 100644--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_calculate_table_size.py+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_calculate_table_size.py@@ -17,6 +17,9 @@ from products.warehouse_sources.backend.models.external_data_job import Externalfrom products.warehouse_sources.backend.models.external_data_schema import ExternalDataSchemafrom products.warehouse_sources.backend.models.external_data_source import ExternalDataSourcefrom products.warehouse_sources.backend.models.table import DataWarehouseTable+from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.delta.errors import (+ TransientObjectStoreError,+)from products.warehouse_sources.backend.temporal.data_imports.workflow_activities import calculate_table_size as calcfrom products.warehouse_sources.backend.temporal.data_imports.workflow_activities.calculate_table_size import (CalculateTableSizeActivityInputs,@@ -132,6 +135,26 @@ class TestCalculateTableSizeActivity:)assert not isinstance(exc_info.value, NonReportableError)+ def test_reraises_transient_object_store_blip_as_non_reportable(self, tmp_path: Path) -> None:+ # Opening the Delta log (_live_delta_size_mib) can hit a transient object-store blip talking+ # to our own bucket (dropped connection, IMDS/STS hiccup) - delta-rs surfaces it as a bare+ # OSError naming the object-store crate, not this worker's fd table. A retry recovers on its+ # own, so it must not reach error tracking as a fresh bug.+ team = _team()+ schema, _table, job = _schema_table_job(+ team, table_format="DeltaS3Wrapper", queryable_folder="stripe_charge__query_a"+ )++ with (+ override_settings(BUCKET_URL=str(tmp_path)),+ patch(f"{_DELTA_TABLE_MODULE}.delta_storage_options", return_value={}),+ patch("deltalake.DeltaTable", side_effect=OSError("Generic S3 error: connection reset")),+ ):+ with pytest.raises(TransientObjectStoreError):+ calculate_table_size_activity(+ CalculateTableSizeActivityInputs(team_id=team.id, schema_id=str(schema.id), job_id=str(job.id))+ )+def test_reads_the_size_of_the_live_files_from_the_delta_log(self, tmp_path: Path) -> None:# An S3 listing of the query folder pages through every object and takes minutes on a large# table. The Delta log already carries the size of each live file, and the query folder holds