Skip to content

: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.

feat(experiments): sharpen recalc schedule-to-start metric buckets (#113613)

Rodrigo Iloro0494c45e6012
diff --git a/products/experiments/backend/temporal/recalculation_metrics.py b/products/experiments/backend/temporal/recalculation_metrics.py
index 346c91857af7..e80a2aa2ab97 100644
--- a/products/experiments/backend/temporal/recalculation_metrics.py
+++ b/products/experiments/backend/temporal/recalculation_metrics.py
@@ -50,19 +50,30 @@ EXPERIMENT_METRICS_RECALCULATION_LATENCY_HISTOGRAM_BUCKETS = [
]
# Schedule-to-start latency is the queue-pressure signal: how long an activity sat in the task queue before
-# a worker picked it up. Buckets reach 30m (vs 5m for execution latency) because queue wait under backlog is
-# unbounded by the activity timeout; that is exactly the regime this histogram exists to observe.
+# a worker picked it up. Most waits finish in under 100ms and the p95 sits between 100ms and 1s, so the buckets
+# are dense in that range; with sparse buckets, histogram_quantile interpolates across one wide bucket and a
+# small shift in the tail moves the p95 by hundreds of milliseconds. Buckets reach 30m (vs 5m for execution
+# latency) because queue wait under backlog is unbounded by the activity timeout.
EXPERIMENT_METRICS_RECALCULATION_SCHEDULE_TO_START_HISTOGRAM_METRICS = (
"experiment_metrics_recalculation_activity_schedule_to_start_latency",
)
EXPERIMENT_METRICS_RECALCULATION_SCHEDULE_TO_START_HISTOGRAM_BUCKETS = [
+ 25.0, # 25ms
+ 50.0, # 50ms
+ 75.0, # 75ms
100.0, # 100ms
+ 150.0, # 150ms
+ 200.0, # 200ms
+ 300.0, # 300ms
500.0, # 500ms
+ 750.0, # 750ms
1_000.0, # 1s
+ 2_000.0, # 2s
5_000.0, # 5s
10_000.0, # 10s
30_000.0, # 30s
60_000.0, # 1m
+ 120_000.0, # 2m
300_000.0, # 5m
600_000.0, # 10m
1_800_000.0, # 30m
@@ -116,7 +127,11 @@ class _ActivityInboundInterceptor(ActivityInboundInterceptor):
# Queue-pressure signal (see bucket comment above). Per-attempt scheduling time, so retry backoff
# (including the intentional quota-wait delays) doesn't read as queue pressure.
if info.current_attempt_scheduled_time and info.started_time:
- meter.create_histogram_timedelta(
+ # A retry attempt waits on the queue after its backoff, so splitting it out separates retry waves
+ # from fresh fan-out that waits for a free slot.
+ meter.with_additional_attributes(
+ {"attempt_kind": "first" if info.attempt == 1 else "retry"}
+ ).create_histogram_timedelta(
name="experiment_metrics_recalculation_activity_schedule_to_start_latency",
description="Time between the current attempt's scheduling and start (task queue wait).",
unit="ms",
diff --git a/products/experiments/backend/temporal/test_recalculation_metrics.py b/products/experiments/backend/temporal/test_recalculation_metrics.py
index c13c2fb90cc7..499ce190fee0 100644
--- a/products/experiments/backend/temporal/test_recalculation_metrics.py
+++ b/products/experiments/backend/temporal/test_recalculation_metrics.py
@@ -14,6 +14,7 @@ from products.experiments.backend.temporal import recalculation_metrics
from products.experiments.backend.temporal.recalculation_metrics import (
EXPERIMENT_METRICS_RECALCULATION_LATENCY_HISTOGRAM_BUCKETS,
EXPERIMENT_METRICS_RECALCULATION_LATENCY_HISTOGRAM_METRICS,
+ EXPERIMENT_METRICS_RECALCULATION_SCHEDULE_TO_START_HISTOGRAM_BUCKETS,
ExperimentsRecalculationMetricsInterceptor,
_failure_error_type,
increment_workflow_finished,
@@ -46,8 +47,13 @@ def test_registered_on_recalculation_queue():
)
-def test_buckets_sorted_ascending_and_floats():
- buckets = EXPERIMENT_METRICS_RECALCULATION_LATENCY_HISTOGRAM_BUCKETS
+ [
+ ("execution_latency", EXPERIMENT_METRICS_RECALCULATION_LATENCY_HISTOGRAM_BUCKETS),
+ ("schedule_to_start", EXPERIMENT_METRICS_RECALCULATION_SCHEDULE_TO_START_HISTOGRAM_BUCKETS),
+ ]
+)
+def test_buckets_sorted_ascending_and_floats(name: str, buckets: list[float]):
assert buckets == sorted(buckets)
assert all(isinstance(b, float) for b in buckets)