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.

fix(experiments): remove unused values from the recalculation query progress (#69830)

Rodrigo Ilorobd7dba6842d5
diff --git a/frontend/src/scenes/experiments/MetricsView/shared/RecalculationStatus.tsx b/frontend/src/scenes/experiments/MetricsView/shared/RecalculationStatus.tsx
index b09bb514f79a..883114fa2276 100644
--- a/frontend/src/scenes/experiments/MetricsView/shared/RecalculationStatus.tsx
+++ b/frontend/src/scenes/experiments/MetricsView/shared/RecalculationStatus.tsx
@@ -2,11 +2,12 @@ import { useActions, useValues } from 'kea'
import { IconBell, IconCheck, IconInfo } from '@posthog/icons'
import { LemonButton, Tooltip } from '@posthog/lemon-ui'
+import { useAnimatedNumber } from '@posthog/quill-charts'
-import { TZLabel } from 'lib/components/TZLabel'
import { LemonDivider } from 'lib/lemon-ui/LemonDivider'
import { Spinner } from 'lib/lemon-ui/Spinner'
import { humanFriendlyNumber } from 'lib/utils/numbers'
+import { ExperimentLastRefreshText } from 'scenes/experiments/ExperimentView/ExperimentReloadAction'
import { experimentMetricsLogic } from '~/scenes/experiments/experimentMetricsLogic'
import { experimentResultsNotificationLogic } from '~/scenes/experiments/experimentResultsNotificationLogic'
@@ -69,8 +70,8 @@ export function RecalculationStatus({ experiment }: { experiment: Experiment }):
<>
<LemonDivider vertical className="h-3.5" />
<span className="flex items-center gap-1 whitespace-nowrap text-muted text-xs [&_span]:align-baseline">
- <span>Refreshed</span>
- <TZLabel time={currentRecalculation.completed_at} timestampStyle="relative" />
+ <span>Results calculated </span>
+ <ExperimentLastRefreshText lastRefresh={currentRecalculation.completed_at} />
</span>
</>
)}
@@ -179,10 +180,14 @@ function CountsSegment({
function ClimbingRows({ rowsRead, estimatedRows }: { rowsRead: number; estimatedRows?: number }): JSX.Element {
const showCeiling = estimatedRows !== undefined && estimatedRows >= rowsRead
+
+ const animatedRowsRead = useAnimatedNumber(rowsRead, 350)
+ const animatedEstimatedTotal = useAnimatedNumber(estimatedRows ?? 0, 350)
+
return (
<span className="text-muted text-xs whitespace-nowrap">
- · {humanFriendlyNumber(rowsRead, 0)}
- {showCeiling && ` / ${humanFriendlyNumber(estimatedRows, 0)}`} rows
+ · {humanFriendlyNumber(animatedRowsRead, 0)}
+ {showCeiling && ` / ${humanFriendlyNumber(animatedEstimatedTotal, 0)}`} rows read
</span>
)
}
diff --git a/products/experiments/backend/presentation/serializers.py b/products/experiments/backend/presentation/serializers.py
index 64bd878b2511..ac90455556a5 100644
--- a/products/experiments/backend/presentation/serializers.py
+++ b/products/experiments/backend/presentation/serializers.py
@@ -1234,18 +1234,6 @@ class ExperimentMetricsRecalculationSerializer(serializers.Serializer):
required=False,
help_text="Per-metric results computed by this run, scoped by the run's recalc fingerprint",
)
- # Live ClickHouse progress, present only on the GET poll path while the run is in_progress (in-flight
- # queries from system.processes plus queries finished during the run from system.query_log, matched by
- # query_id prefix; see get_live_query_progress). build_job_payload omits these keys entirely for terminal
- # or just-created runs, so they are genuinely optional in the response — NOT read_only=True, which
- # drf-spectacular would force into the schema's `required` list (making the generated TypeScript
- # `number | null` instead of the honest `number | null | undefined`). The serializer is output-only
- # (never .is_valid()), so omitting read_only costs no input-validation safety.
- running_metrics = serializers.IntegerField(
- required=False,
- allow_null=True,
- help_text="Count of metric queries currently running in ClickHouse (bounded by worker-pool concurrency)",
- )
rows_read = serializers.IntegerField(
required=False,
allow_null=True,
@@ -1263,19 +1251,6 @@ class ExperimentMetricsRecalculationSerializer(serializers.Serializer):
"reliable signal"
),
)
- bytes_read = serializers.IntegerField(
- required=False,
- allow_null=True,
- help_text="Bytes read by the run's metric queries so far, both finished and currently running",
- )
- active_cpu_time = serializers.IntegerField(
- required=False,
- allow_null=True,
- help_text=(
- "Active CPU time (microseconds) consumed by the run's metric queries so far, both finished and "
- "currently running"
- ),
- )
class RunningTimeBaselineStatsSerializer(serializers.Serializer):
diff --git a/products/experiments/backend/recalculation.py b/products/experiments/backend/recalculation.py
index 8d5132284ea2..591aa0f96b55 100644
--- a/products/experiments/backend/recalculation.py
+++ b/products/experiments/backend/recalculation.py
@@ -95,9 +95,8 @@ def get_live_query_progress(recalc: ExperimentMetricsRecalculation) -> dict | No
alone reads zero for most of the run; the query_log branch keeps finished queries counted, making
rows_read cumulative and roughly monotonic across the run (modulo query_log flush lag).
- `running_metrics` counts only the currently in-flight queries (bounded by the workflow's worker-pool
- concurrency). `estimated_rows_total` is ClickHouse's own total_rows_approx for in-flight queries (revised
- upward mid-scan) plus the final read_rows of finished ones, so it can trail rows_read; treat rows_read as
+ `estimated_rows_total` is ClickHouse's own total_rows_approx for in-flight queries (revised upward
+ mid-scan) plus the final read_rows of finished ones, so it can trail rows_read; treat rows_read as
the primary signal. Temporal retries of a metric produce one query_log row per attempt and each attempt's
rows are summed; that overcount is accepted for a decorative counter.
"""
@@ -122,27 +121,18 @@ def get_live_query_progress(recalc: ExperimentMetricsRecalculation) -> dict | No
"""
SELECT
sum(rows_read) AS rows_read,
- sum(estimated_rows_total) AS estimated_rows_total,
- sum(bytes_read) AS bytes_read,
- sum(active_cpu_time) AS active_cpu_time,
- countIf(is_running = 1) AS running_metrics
+ sum(estimated_rows_total) AS estimated_rows_total
FROM
(
SELECT
read_rows AS rows_read,
- total_rows_approx AS estimated_rows_total,
- read_bytes AS bytes_read,
- ProfileEvents['OSCPUVirtualTimeMicroseconds'] AS active_cpu_time,
- 1 AS is_running
+ total_rows_approx AS estimated_rows_total
FROM clusterAllReplicas(%(cluster)s, system.processes)
WHERE query_id LIKE %(prefix)s
UNION ALL
SELECT
read_rows AS rows_read,
- read_rows AS estimated_rows_total,
- read_bytes AS bytes_read,
- ProfileEvents['OSCPUVirtualTimeMicroseconds'] AS active_cpu_time,
- 0 AS is_running
+ read_rows AS estimated_rows_total
FROM clusterAllReplicas(%(cluster)s, system.query_log)
WHERE query_id LIKE %(prefix)s
AND type = 'QueryFinish'
@@ -161,16 +151,13 @@ def get_live_query_progress(recalc: ExperimentMetricsRecalculation) -> dict | No
capture_exception()
return None
- rows_read, estimated_rows_total, bytes_read, active_cpu_time, running_metrics = rows[0]
+ rows_read, estimated_rows_total = rows[0]
# All-zeros is a real, non-terminal state (queries not started yet, or finished but not flushed to
# query_log), distinct from "run finished". Return the zeros so the poll can tell "in-flight, nothing
# visible yet" from terminal null.
return {
"rows_read": int(rows_read or 0),
"estimated_rows_total": int(estimated_rows_total or 0),
- "bytes_read": int(bytes_read or 0),
- "active_cpu_time": int(active_cpu_time or 0),
- "running_metrics": int(running_metrics or 0),
}
diff --git a/products/experiments/backend/test/test_recalculation_service.py b/products/experiments/backend/test/test_recalculation_service.py
index 574feb53b5f6..0c3e8032847c 100644
--- a/products/experiments/backend/test/test_recalculation_service.py
+++ b/products/experiments/backend/test/test_recalculation_service.py
@@ -453,15 +453,12 @@ class TestLiveQueryProgress(BaseTest):
with team_scope(self.team.id, canonical=True):
with patch(
"products.experiments.backend.recalculation.sync_execute",
- return_value=[(1_284_512, 9_800_000, 41_000_000, 250_000, 3)],
+ return_value=[(1_284_512, 9_800_000)],
):
progress = get_live_query_progress(recalc)
assert progress == {
"rows_read": 1_284_512,
"estimated_rows_total": 9_800_000,
- "bytes_read": 41_000_000,
- "active_cpu_time": 250_000,
- "running_metrics": 3,
}
def test_maps_all_zero_row_to_zeros_while_in_progress(self):
@@ -471,15 +468,12 @@ class TestLiveQueryProgress(BaseTest):
with team_scope(self.team.id, canonical=True):
with patch(
"products.experiments.backend.recalculation.sync_execute",
- return_value=[(0, 0, 0, 0, 0)],
+ return_value=[(0, 0)],
):
progress = get_live_query_progress(recalc)
assert progress == {
"rows_read": 0,
"estimated_rows_total": 0,
- "bytes_read": 0,
- "active_cpu_time": 0,
- "running_metrics": 0,
}
def test_returns_none_when_clickhouse_read_raises(self):
@@ -520,4 +514,3 @@ class TestLiveQueryProgressFinishedQueries(BaseTest, ClickhouseTestMixin):
assert progress is not None
assert progress["rows_read"] == 1000
assert progress["estimated_rows_total"] == 1000
- assert progress["running_metrics"] == 0
diff --git a/products/experiments/frontend/generated/api.schemas.ts b/products/experiments/frontend/generated/api.schemas.ts
index 8a0415937229..a7f0142c76f3 100644
--- a/products/experiments/frontend/generated/api.schemas.ts
+++ b/products/experiments/frontend/generated/api.schemas.ts
@@ -1859,11 +1859,6 @@ export interface ExperimentMetricsRecalculationApi {
readonly result_source: ResultSourceEnumApi
/** Per-metric results computed by this run, scoped by the run's recalc fingerprint */
readonly results: readonly MetricRecalculationResultApi[]
- /**
- * Count of metric queries currently running in ClickHouse (bounded by worker-pool concurrency)
- * @nullable
- */
- running_metrics?: number | null
/**
* Rows read by the run's metric queries so far, both finished and currently running. Cumulative and roughly monotonic across the run; the primary live progress signal
* @nullable
@@ -1874,16 +1869,6 @@ export interface ExperimentMetricsRecalculationApi {
* @nullable
*/
estimated_rows_total?: number | null
- /**
- * Bytes read by the run's metric queries so far, both finished and currently running
- * @nullable
- */
- bytes_read?: number | null
- /**
- * Active CPU time (microseconds) consumed by the run's metric queries so far, both finished and currently running
- * @nullable
- */
- active_cpu_time?: number | null
}
export interface ShipVariantApi {
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 87dded0eb15c..b6e74226be56 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -23501,11 +23501,6 @@ export namespace Schemas {
readonly result_source: ResultSourceEnum;
/** Per-metric results computed by this run, scoped by the run's recalc fingerprint */
readonly results: readonly MetricRecalculationResult[];
- /**
- * Count of metric queries currently running in ClickHouse (bounded by worker-pool concurrency)
- * @nullable
- */
- running_metrics?: number | null;
/**
* Rows read by the run's metric queries so far, both finished and currently running. Cumulative and roughly monotonic across the run; the primary live progress signal
* @nullable
@@ -23516,16 +23511,6 @@ export namespace Schemas {
* @nullable
*/
estimated_rows_total?: number | null;
- /**
- * Bytes read by the run's metric queries so far, both finished and currently running
- * @nullable
- */
- bytes_read?: number | null;
- /**
- * Active CPU time (microseconds) consumed by the run's metric queries so far, both finished and currently running
- * @nullable
- */
- active_cpu_time?: number | null;
}
export type ExperimentResultsWidgetCatalogEntryOpenApiWidgetType = typeof ExperimentResultsWidgetCatalogEntryOpenApiWidgetType[keyof typeof ExperimentResultsWidgetCatalogEntryOpenApiWidgetType];