: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-warehouse): stop alerting on expected repartition skips (#104471)
Tom Owers7bb33a560937
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/repartition_controller.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/repartition_controller.pyindex ae84a9b4ba4c..9108b9b10c87 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/repartition_controller.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/repartition_controller.py@@ -72,6 +72,15 @@ REPARTITION_COOLDOWN_SECONDS = 24 * 60 * 60# permanently-failing table doesn't re-attempt the rewrite on every sync forever.MAX_REPARTITION_ATTEMPTS = 3+# Reasons `select_repartition_target` gives that describe the table instead of a defect: its data+# carries no key to partition on, or its scheme is already as fine as that scheme goes. The+# controller decided correctly in each case and nobody can act on the result, so these are counted+# on DELTA_REPARTITION_SKIP_TOTAL and reported on `warehouse_repartition_skipped` but never sent to+# error tracking. Every other reason means the schema row disagrees with itself (numerical mode with+# no `partition_size`) or the selector saw a state the caller should have filtered out first+# (`no_partitions`, `within_budget`), which is a bug in us, so it still alerts.+EXPECTED_SKIP_REASONS = frozenset({"unpartitionable_no_keys", "datetime_at_finest_tier", "numerical_cannot_shrink"})+def target_partition_bytes() -> int:return int(getattr(settings, "DATA_WAREHOUSE_TARGET_PARTITION_BYTES", 500_000_000))@@ -377,7 +386,7 @@ async def maybe_flag_for_repartition(# below). Refuse when that result would fall under the floor: partition size cannot be what is# killing a table whose partitions are already that small, and without this guard oom_history# drives the scheme finer tier by tier until it bottoms out (e.g. datetime at hour) and then- # emits a skipped event plus an exception on every cooldown expiry forever.+ # re-measures and re-emits the skip on every cooldown expiry forever.split_budget = budget if over_budget else max(1, max_bytes // 2)floor = min_splittable_partition_bytes()if not over_budget and split_budget < floor:@@ -492,10 +501,11 @@ async def maybe_flag_for_repartition(partition_format=schema.partition_format,partition_count=len(partition_bytes),)- capture_exception(Exception(f"Repartition needed but skipped for schema {schema.id}: {reason}"))+ if reason not in EXPECTED_SKIP_REASONS:+ capture_exception(Exception(f"Repartition needed but skipped for schema {schema.id}: {reason}"))# Engage the cooldown even though no rewrite happened: the trigger (over budget or repeated# OOMs) is still true next sync and the table's scheme can't go finer, so without this we- # re-measure, re-emit the skip event, and re-alert on every 5-minute sync forever. The+ # re-measure and re-emit the skip event on every 5-minute sync forever. The# cooldown re-evaluates at most daily; a real change to the table clears it via a later# successful repartition.await asyncio.to_thread(schema.stamp_last_repartition_at)diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test_repartition_controller.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test_repartition_controller.pyindex 23a67dc42e2d..e7dad5a98747 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test_repartition_controller.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test_repartition_controller.py@@ -215,23 +215,50 @@ class TestRepartitionDetection:schema.refresh_from_db()assert schema.repartition_pending is None- def test_unpartitionable_over_budget_skips_with_reason(self, team):- # An unpartitioned table with no usable key can't be repartitioned — we must surface the specific- # reason (so a human is alerted) rather than silently flag a target that would fail.- schema = _make_schema(team, {})+ @pytest.mark.parametrize(+ "sync_type_config,expected_reason,alerts",+ [+ ({}, "unpartitionable_no_keys", False),+ (+ {+ "partitioning_enabled": True,+ "partition_mode": "datetime",+ "partition_format": "hour",+ "partitioning_keys": ["ts"],+ },+ "datetime_at_finest_tier",+ False,+ ),+ (+ {"partitioning_enabled": True, "partition_mode": "numerical", "partitioning_keys": ["id"]},+ "numerical_no_size",+ True,+ ),+ ],+ )+ def test_over_budget_without_target_skips_and_alerts_only_when_unexpected(+ self, team, sync_type_config, expected_reason, alerts+ ):+ # A table with no usable key, and one already at the finest datetime tier, are facts about the+ # customer's data that nobody can act on, so they must stay out of error tracking while still+ # being counted on the skip event. A numerical schema with no partition_size is our own row+ # contradicting itself, so that one must still alert.+ schema = _make_schema(team, sync_type_config)with tempfile.TemporaryDirectory() as d:delta = _write_unpartitioned_delta(f"{d}/u")with (patch.object(ctrl, "target_partition_bytes", return_value=1),patch.object(ctrl, "is_auto_repartition_enabled", return_value=True),patch.object(ctrl, "capture_repartition_event") as capture,+ patch.object(ctrl, "capture_exception") as mock_capture_exception,):self._detect(team, schema, delta)schema.refresh_from_db()assert schema.repartition_pending is Noneassert capture.call_args.args[0] == "warehouse_repartition_skipped"- assert capture.call_args.args[1]["reason"] == "unpartitionable_no_keys"+ assert capture.call_args.args[1]["reason"] == expected_reason+ assert mock_capture_exception.call_count == (1 if alerts else 0)# A table with no usable partition target must engage the cooldown, otherwise detection# re-measures and re-emits the skip on every 5-minute sync forever (the loop we're fixing).assert schema.last_repartition_at is not None