: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
feat(data-warehouse): log why the repartition controller skips a table (#67737)
Tom Owersfac475b5f8e3
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/repartition_controller.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/repartition_controller.pyindex 9b44d97183b9..29e83004339d 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/repartition_controller.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/repartition_controller.py@@ -106,15 +106,16 @@ def capture_repartition_event(event: str, props: dict[str, Any]) -> None:posthoganalytics.capture(distinct_id=get_machine_id(), event=event, properties=props)-def _cooldown_active(schema: ExternalDataSchema) -> bool:+def _cooldown_seconds_remaining(schema: ExternalDataSchema) -> float:+ """Seconds until the per-table repartition cooldown expires; 0 when no cooldown is active."""last = schema.last_repartition_atif not last:- return False+ return 0.0try:last_dt = parser.parse(last)except (ValueError, TypeError):- return False- return (timezone.now() - last_dt).total_seconds() < REPARTITION_COOLDOWN_SECONDS+ return 0.0+ return max(0.0, REPARTITION_COOLDOWN_SECONDS - (timezone.now() - last_dt).total_seconds())async def maybe_flag_for_repartition(@@ -133,6 +134,9 @@ async def maybe_flag_for_repartition(try:partition_bytes = await asyncio.to_thread(measure_partition_bytes, delta_table)if not partition_bytes:+ await logger.adebug(+ "repartition: skipped, no partition measurements in the delta log", schema_id=str(schema.id)+ )returnmax_bytes = max(partition_bytes.values())@@ -140,17 +144,44 @@ async def maybe_flag_for_repartition(budget = target_partition_bytes()if max_bytes <= budget:+ await logger.adebug(+ "repartition: not needed, largest partition within budget",+ schema_id=str(schema.id),+ max_partition_bytes=max_bytes,+ budget_bytes=budget,+ partition_count=len(partition_bytes),+ )returnif not await asyncio.to_thread(is_auto_repartition_enabled, schema):- await logger.adebug("repartition: over budget but controller disabled", schema_id=str(schema.id))+ await logger.adebug(+ "repartition: over budget but skipped, controller disabled by feature flag",+ schema_id=str(schema.id),+ max_partition_bytes=max_bytes,+ budget_bytes=budget,+ )returnif schema.repartition_pending is not None:- return # Already queued for the next run.+ await logger.adebug(+ "repartition: over budget but already queued for the next run",+ schema_id=str(schema.id),+ max_partition_bytes=max_bytes,+ budget_bytes=budget,+ repartition_pending=schema.repartition_pending,+ )+ return- if _cooldown_active(schema):- await logger.adebug("repartition: over budget but in cooldown", schema_id=str(schema.id))+ cooldown_remaining = _cooldown_seconds_remaining(schema)+ if cooldown_remaining > 0:+ await logger.adebug(+ "repartition: over budget but skipped, in post-repartition cooldown",+ schema_id=str(schema.id),+ max_partition_bytes=max_bytes,+ budget_bytes=budget,+ last_repartition_at=schema.last_repartition_at,+ cooldown_seconds_remaining=int(cooldown_remaining),+ )returntarget, reason = select_repartition_target(schema, partition_bytes, budget)@@ -161,6 +192,16 @@ async def maybe_flag_for_repartition(props = base_event_props(schema, source, str(job.id))props.update({"max_partition_bytes_before": max_bytes, "reason": reason})await asyncio.to_thread(capture_repartition_event, "warehouse_repartition_skipped", props)+ await logger.adebug(+ "repartition: over budget but skipped, no finer partitioning target available",+ schema_id=str(schema.id),+ reason=reason,+ max_partition_bytes=max_bytes,+ budget_bytes=budget,+ partition_mode=schema.partition_mode,+ partition_format=schema.partition_format,+ partition_count=len(partition_bytes),+ )capture_exception(Exception(f"Repartition needed but skipped for schema {schema.id}: {reason}"))return@@ -179,11 +220,15 @@ async def maybe_flag_for_repartition(})await asyncio.to_thread(capture_repartition_event, "warehouse_repartition_flagged", props)- await logger.ainfo(+ await logger.adebug("repartition: flagged for next run",schema_id=str(schema.id),max_partition_bytes=max_bytes,+ budget_bytes=budget,target_mode=target.partition_mode,+ target_format=target.partition_format,+ target_count=target.partition_count,+ target_size=target.partition_size,)except Exception as e:# Detection is best-effort; never fail post-load over it.