: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(metrics): emit gap instead of quantile 0 when window has no bucket increase (#68088)
Daniel Visca60674f727fa7
diff --git a/products/metrics/backend/metric_query_runner.py b/products/metrics/backend/metric_query_runner.pyindex 9575d98895e7..ba8b7eb9364a 100644--- a/products/metrics/backend/metric_query_runner.py+++ b/products/metrics/backend/metric_query_runner.py@@ -322,6 +322,11 @@ class MetricQueryRunner:for row in response.results:bounds = list(row[1 + group_count])counts = list(row[3 + group_count])+ if sum(counts) <= 0:+ # No computable increase in this bucket (e.g. a cumulative+ # series' first sample has nothing to diff against). A gap is+ # honest; a fabricated quantile of 0 reads as "p95 is 0s".+ continuerows.append({"time": row[0].isoformat() if isinstance(row[0], dt.datetime) else row[0],diff --git a/products/metrics/backend/tests/test_metric_query_runner.py b/products/metrics/backend/tests/test_metric_query_runner.pyindex 31dd7fbb4526..387eb95f36e0 100644--- a/products/metrics/backend/tests/test_metric_query_runner.py+++ b/products/metrics/backend/tests/test_metric_query_runner.py@@ -921,6 +921,14 @@ class TestHistogramQuantileRunner(ClickhouseTestMixin, APIBaseTest):self.assertEqual(len(rows), 1)self.assertAlmostEqual(rows[0]["value"], 0.3)+ def test_cumulative_lone_sample_emits_no_point(self):+ # A cumulative histogram's first (and only) sample has no predecessor+ # to diff against — the window has no computable increase. That must+ # be a gap, not a fabricated p95 of 0 (which reads as "p95 is 0s").+ self._seed_histogram([(self.anchor, [1, 1, 1, 0])], temporality="cumulative")+ rows = self._run(0.95)+ self.assertEqual(rows, [])+def test_mismatched_bounds_raise(self):self._seed_histogram([(self.anchor + dt.timedelta(seconds=0), [1, 1, 1, 0])], temporality="delta")self._seed_histogram(