: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(engineering-analytics): expose created_at_raw on the job cost view (#91944)
Julian Bez1b2318549b22
diff --git a/products/engineering_analytics/SPEC.md b/products/engineering_analytics/SPEC.mdindex b4a325921b49..0b5e6417781a 100644--- a/products/engineering_analytics/SPEC.md+++ b/products/engineering_analytics/SPEC.md@@ -107,7 +107,7 @@ They are non-materialized: the rendered SQL is persisted per team and re-synced- Cost runs off Depot's billed clock, not `duration_seconds` (§6). `billable_seconds` is that clock; `duration_seconds` stays the full wall-clock GitHub reports.- Cost is defined once, in `logic/cost.py`, rendered to HogQL; a ClickHouse-backed parity test asserts the view equals the Python model. The endpoint cost queries read the same rendered SELECT (via `_curated.job_cost_source()`), so there is no second cost path to drift.- `is_merge_queue` splits merge-queue gate spend from the rest without anyone re-deriving what a gate branch is. Both this view and `ci_job_history` carry it, so neither answers "what does the queue cost" by pattern-matching a branch name.-- **The view carries no scan floor, so filter it tightly.** It is stored SQL with no window of its own, so an unfiltered `SELECT` reads the team's whole job history, and the `is_rerun_copy` duplicate scan always aggregates all of it. Insights and `execute-sql` should bound `created_at` (and, for a scan the engine can actually prune, keep the bound close). The product's own endpoint queries pass `created_floor` instead (§6). Memory stays bounded either way: the flag comes from a narrow duplicate-key join, never a window function, because a window sorts every column of the whole scan in memory.+- **The view carries no scan floor, so filter it tightly.** It is stored SQL with no window of its own, so an unfiltered `SELECT` reads the team's whole job history, and the `is_rerun_copy` duplicate scan always aggregates all of it. Insights and `execute-sql` should bound `created_at`, and pair it with a coarse `created_at_raw >= '<YYYY-MM-DD>'` floor: a predicate on the parsed `created_at` cannot prune the parquet scan, so the raw twin is what lets the scan skip. The view exposes `created_at_raw` for exactly that, the way `ci_job_history` does. The product's own endpoint queries pass `created_floor` instead (§6). Memory stays bounded either way: the flag comes from a narrow duplicate-key join, never a window function, because a window sorts every column of the whole scan in memory.#### `engineering_analytics_ci_job_history`diff --git a/products/engineering_analytics/backend/logic/views/job_costs.py b/products/engineering_analytics/backend/logic/views/job_costs.pyindex 84ef16eb9aab..53085eea7277 100644--- a/products/engineering_analytics/backend/logic/views/job_costs.py+++ b/products/engineering_analytics/backend/logic/views/job_costs.py@@ -109,6 +109,12 @@ FIELDS: dict[str, FieldOrTable] = {# "non-billable tier", completed_at says "unsettled", this says "never executed" — so a consumer# can still tell the three apart, and can drop copies from duration metrics too."is_rerun_copy": BooleanDatabaseField(name="is_rerun_copy"),+ # The unparsed ISO-8601 twin of created_at, for pruning rather than for reading. A predicate on+ # the parsed created_at cannot prune the parquet scan, so a consumer that windows this view pairs+ # its precise created_at bound with a coarse `created_at_raw >= '<YYYY-MM-DD>'` floor, the way+ # ci_job_history's consumers already do. Appended, because the column order is the saved-query+ # schema contract.+ "created_at_raw": StringDatabaseField(name="created_at_raw", nullable=True),}@@ -160,7 +166,9 @@ def build_query(should pass it: the window predicate reads the RUN's attributes, so it can never prune the jobsside, and without a floor the ``is_rerun_copy`` duplicate scan aggregates the team's whole jobhistory on every call. The public saved view can't take one — it is stored SQL with no window of- its own — so it is built without it and its consumers filter it themselves.+ its own — so it is built without it and its consumers filter it themselves, pairing their precise+ ``created_at`` bound with a coarse ``created_at_raw`` floor, which is the predicate the scan can+ prune on and the reason the view exposes that column."""jobs = workflow_jobs.build_query(jobs_table, created_floor=created_floor)runs = workflow_runs.build_query(runs_table)@@ -198,7 +206,8 @@ def build_query({render_billable_seconds("provider", "os", "is_rerun_copy", "billed_seconds")} AS billable_seconds,{render_estimated_cost_usd("provider", "os", "vcpu", "is_rerun_copy", "billed_seconds")} AS estimated_cost_usd,is_merge_queue,- is_rerun_copy{run_columns}+ is_rerun_copy,+ created_at_raw{run_columns}FROM (SELECTrepo_owner,@@ -220,6 +229,7 @@ def build_query(billed_seconds,is_merge_queue,is_rerun_copy,+ created_at_raw,{render_provider("depot_label", "hosted_label")} AS provider,{render_os("depot_label", "hosted_label")} AS os,{render_vcpu("depot_label", "hosted_label")} AS vcpu{run_columns}@@ -244,6 +254,7 @@ def build_query(billed_seconds,is_merge_queue,is_rerun_copy,+ created_at_raw,{render_depot_label("labels_arr")} AS depot_label,{render_hosted_label("labels_arr")} AS hosted_label{run_columns}FROM (@@ -271,6 +282,7 @@ def build_query({billed_seconds} AS billed_seconds,r.is_merge_queue AS is_merge_queue,j.is_rerun_copy AS is_rerun_copy,+ j.created_at_raw AS created_at_raw,{labels_array} AS labels_arr{inner_run_columns}FROM ({jobs}) AS jLEFT JOIN ({runs}) AS r ON j.run_id = r.id