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): show wasted cost of failed precompute builds (#69702)

Juraj Majerik3ad9331df65b
diff --git a/frontend/src/scenes/instance/QueryPerformance/PrecomputeOverview.tsx b/frontend/src/scenes/instance/QueryPerformance/PrecomputeOverview.tsx
index 70d8049444c5..849c507a5e33 100644
--- a/frontend/src/scenes/instance/QueryPerformance/PrecomputeOverview.tsx
+++ b/frontend/src/scenes/instance/QueryPerformance/PrecomputeOverview.tsx
@@ -31,6 +31,8 @@ const EXCEPTION_CODE_LABELS: Record<string, string> = {
'159': 'timeout',
'241': 'out of memory',
'202': 'cluster busy',
+ '164': 'readonly',
+ '47': 'unknown identifier',
}
const formatMs = (ms: number | null): string => {
@@ -312,6 +314,23 @@ export function PrecomputeOverview(): JSX.Element {
}
tooltip="Total bytes scanned and time spent by precompute-build INSERTs. This is the investment; the read-path savings are the return."
/>
+ <StatCard
+ title="Wasted on failed builds"
+ value={builds ? humanizeBytes(builds.failed_read_bytes ?? 0) : '–'}
+ subtitle={
+ builds
+ ? `${humanFriendlyDuration((builds.failed_duration_ms ?? 0) / 1000)} ClickHouse time on builds that failed`
+ : undefined
+ }
+ tooltip="Bytes scanned and time spent by precompute-build INSERTs that errored. Pure waste: the read then falls back to a full events scan on top. Should stay near zero."
+ type={
+ builds &&
+ builds.total_read_bytes > 0 &&
+ (builds.failed_read_bytes ?? 0) / builds.total_read_bytes > 0.05
+ ? 'danger'
+ : undefined
+ }
+ />
<StatCard
title="Metric-events precompute"
value={metricEvents ? formatPercent(metricEvents.precomputed, meApplicable) : '–'}
diff --git a/frontend/src/scenes/instance/QueryPerformance/QueryPerformance.tsx b/frontend/src/scenes/instance/QueryPerformance/QueryPerformance.tsx
index ef375b05df99..abe1e4eb98f3 100644
--- a/frontend/src/scenes/instance/QueryPerformance/QueryPerformance.tsx
+++ b/frontend/src/scenes/instance/QueryPerformance/QueryPerformance.tsx
@@ -55,6 +55,8 @@ const EXCEPTION_CODE_OPTIONS = [
{ value: '159', label: '159 (timeout)' },
{ value: '241', label: '241 (memory)' },
{ value: '202', label: '202 (cluster busy)' },
+ { value: '164', label: '164 (readonly)' },
+ { value: '47', label: '47 (unknown identifier)' },
]
// Group total = the read plus its precompute-build sub-queries (the user paid for all of them),
@@ -92,6 +94,8 @@ const EXCEPTION_CODE_LABELS: Record<number, string> = {
159: 'timeout',
241: 'out of memory',
202: 'cluster busy',
+ 164: 'readonly',
+ 47: 'unknown identifier',
}
const codeLabel = (code: number): string => EXCEPTION_CODE_LABELS[code] ?? `error ${code}`
diff --git a/frontend/src/scenes/instance/QueryPerformance/queryPerformanceLogic.ts b/frontend/src/scenes/instance/QueryPerformance/queryPerformanceLogic.ts
index ee0670ddb9fa..b1c57c41884f 100644
--- a/frontend/src/scenes/instance/QueryPerformance/queryPerformanceLogic.ts
+++ b/frontend/src/scenes/instance/QueryPerformance/queryPerformanceLogic.ts
@@ -37,6 +37,9 @@ export interface PrecomputeBuildStats {
failed: number
total_duration_ms: number
total_read_bytes: number
+ // Optional: responses served by a backend from before these fields existed omit them.
+ failed_duration_ms?: number
+ failed_read_bytes?: number
by_table: Record<string, { succeeded: number; failed: number }>
failures_by_code: Record<string, number>
}
diff --git a/posthog/api/debug_ch_queries.py b/posthog/api/debug_ch_queries.py
index 53d2a981f6af..06393ad09e40 100644
--- a/posthog/api/debug_ch_queries.py
+++ b/posthog/api/debug_ch_queries.py
@@ -849,6 +849,10 @@ class DebugCHQueries(viewsets.ViewSet):
"failed": 0,
"total_duration_ms": 0,
"total_read_bytes": 0,
+ # Spend on builds that failed: pure waste (the read then falls back to a full
+ # events scan on top). The number that should stay near zero.
+ "failed_duration_ms": 0,
+ "failed_read_bytes": 0,
"by_table": {},
"failures_by_code": {},
}
@@ -864,6 +868,8 @@ class DebugCHQueries(viewsets.ViewSet):
else:
builds["failed"] += count
table_entry["failed"] += count
+ builds["failed_duration_ms"] += total_duration_ms
+ builds["failed_read_bytes"] += total_read_bytes
code_key = str(exception_code)
builds["failures_by_code"][code_key] = builds["failures_by_code"].get(code_key, 0) + count