: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
feat(engineering-analytics): add depot ci minutes to repo overview (#111982)
Raúl Negrón-Oteroed729752b79b
diff --git a/products/engineering_analytics/backend/facade/contracts.py b/products/engineering_analytics/backend/facade/contracts.pyindex 73b03f85bc43..6118735c6e67 100644--- a/products/engineering_analytics/backend/facade/contracts.py+++ b/products/engineering_analytics/backend/facade/contracts.py@@ -1462,6 +1462,9 @@ class RepoOverview:# changes show up as their own delta instead of hiding inside the total.merge_queue_billable_minutes: float | Nonemerge_queue_billable_minutes_prev: float | None+ # The slice of billable_minutes whose jobs ran on the Depot CI engine, not on GitHub Actions.+ depot_ci_billable_minutes: float | None+ depot_ci_billable_minutes_prev: float | None# Merge-queue landing stats, over merged PRs with at least one corroborated gate run# (logic/merge_queue.py). All authors, bots included: these measure the queue's mechanics,# not author behavior.diff --git a/products/engineering_analytics/backend/logic/queries/pr_cost.py b/products/engineering_analytics/backend/logic/queries/pr_cost.pyindex dd3991a8c68f..d24914250ab5 100644--- a/products/engineering_analytics/backend/logic/queries/pr_cost.py+++ b/products/engineering_analytics/backend/logic/queries/pr_cost.py@@ -381,9 +381,10 @@ def query_author_workflow_costs(# The window-cost shape twice over — the current window and the equal-length one before it — as# per-window conditional aggregates on one cost-source scan, so the repo hub's delta doesn't pay the# scan twice. The previous window is half-open ([prev_from, date_from)) so no run lands in both.-# __QUEUE_AGG__ rides the same scan: the merge-queue slice of each window's billable seconds.+# __QUEUE_AGG__ and __DEPOT_CI_AGG__ ride the same scan: the merge-queue and Depot CI engine slices+# of each window's billable seconds._WINDOW_COST_WITH_PREV_SELECT = """- SELECT c.workflow_name AS workflow_name, __CUR_AGG__, __PREV_AGG__, __QUEUE_AGG__+ SELECT c.workflow_name AS workflow_name, __CUR_AGG__, __PREV_AGG__, __QUEUE_AGG__, __DEPOT_CI_AGG__FROM __COST_SOURCE__ AS cWHERE c.run_started_at >= {prev_from} __DATE_TO__GROUP BY c.workflow_name@@ -393,18 +394,25 @@ _WINDOW_COST_WITH_PREV_SELECT = """@dataclass(frozen=True, kw_only=True)class WindowCostsWithPrev:- """Per-workflow cost aggregates for a window and its previous twin, plus the merge-queue slice- of each window's billable seconds — carried on the same scan so queue spend never needs a- second pass over the cost source."""+ """Per-workflow cost aggregates for a window and its previous twin, plus the merge-queue and+ Depot CI engine slices of each window's billable seconds. The slices come from the same scan,+ so they never need a second pass over the cost source."""by_workflow: dict[str, PRCostAggregate]by_workflow_prev: dict[str, PRCostAggregate]merge_queue_billable_seconds: floatmerge_queue_billable_seconds_prev: float+ depot_ci_billable_seconds: float+ depot_ci_billable_seconds_prev: float_EMPTY_WINDOW_COSTS = WindowCostsWithPrev(- by_workflow={}, by_workflow_prev={}, merge_queue_billable_seconds=0.0, merge_queue_billable_seconds_prev=0.0+ by_workflow={},+ by_workflow_prev={},+ merge_queue_billable_seconds=0.0,+ merge_queue_billable_seconds_prev=0.0,+ depot_ci_billable_seconds=0.0,+ depot_ci_billable_seconds_prev=0.0,)@@ -430,6 +438,7 @@ def query_workflow_window_costs_with_prev("prev_from": ast.Constant(value=prev_from),# Floored off prev_from, the earlier of the two window starts — this scan carries both."job_created_floor": run_windowed_job_created_floor_constant(prev_from),+ "depot_ci_engine": ast.Constant(value=CIEngine.DEPOT_CI.value),}windows = window_pair_predicates("c.run_started_at", date_to=date_to)date_to_clause = ""@@ -441,15 +450,19 @@ def query_workflow_window_costs_with_prev(# in merge_queue_overview.py use the narrower corroborated population; the two answer different# questions, so don't unify them casually.queue = in_merge_queue_namespace_expr("c.head_branch")- queue_agg = (- f"sumIf(ifNull(c.billable_seconds, 0), {queue} AND {windows.current}) AS queue_billable_seconds, "- f"sumIf(ifNull(c.billable_seconds, 0), {queue} AND {windows.previous}) AS queue_billable_seconds_prev"- )++ def slice_aggregates(predicate: str, alias: str) -> str:+ return (+ f"sumIf(ifNull(c.billable_seconds, 0), {predicate} AND {windows.current}) AS {alias}, "+ f"sumIf(ifNull(c.billable_seconds, 0), {predicate} AND {windows.previous}) AS {alias}_prev"+ )+sql = (_WINDOW_COST_WITH_PREV_SELECT.replace("__COST_SOURCE__", cost_source).replace("__CUR_AGG__", _cost_aggregates(when=windows.current)).replace("__PREV_AGG__", _cost_aggregates(when=windows.previous, suffix="_prev"))- .replace("__QUEUE_AGG__", queue_agg)+ .replace("__QUEUE_AGG__", slice_aggregates(queue, "queue_billable_seconds"))+ .replace("__DEPOT_CI_AGG__", slice_aggregates("c.ci_engine = {depot_ci_engine}", "depot_ci_billable_seconds")).replace("__DATE_TO__", date_to_clause))response = curated.run(@@ -457,7 +470,7 @@ def query_workflow_window_costs_with_prev()by_workflow_cur: dict[str, PRCostAggregate] = {}by_workflow_prev: dict[str, PRCostAggregate] = {}- queue_billable = queue_billable_prev = 0.0+ slice_seconds = [0.0, 0.0, 0.0, 0.0]for workflow_name, *columns in response.results or []:workflow = workflow_name or ""cur_agg = _aggregate(*columns[0:5])@@ -466,13 +479,15 @@ def query_workflow_window_costs_with_prev(by_workflow_cur[workflow] = cur_aggif _has_jobs(prev_agg):by_workflow_prev[workflow] = prev_agg- queue_billable += float(columns[10] or 0.0)- queue_billable_prev += float(columns[11] or 0.0)+ slice_seconds = [total + float(value or 0.0) for total, value in zip(slice_seconds, columns[10:14])]+ queue_billable, queue_billable_prev, depot_ci_billable, depot_ci_billable_prev = slice_secondsreturn WindowCostsWithPrev(by_workflow=by_workflow_cur,by_workflow_prev=by_workflow_prev,merge_queue_billable_seconds=queue_billable,merge_queue_billable_seconds_prev=queue_billable_prev,+ depot_ci_billable_seconds=depot_ci_billable,+ depot_ci_billable_seconds_prev=depot_ci_billable_prev,)diff --git a/products/engineering_analytics/backend/logic/queries/repo_overview.py b/products/engineering_analytics/backend/logic/queries/repo_overview.pyindex 16ebba7cb93a..09b4a4870a8a 100644--- a/products/engineering_analytics/backend/logic/queries/repo_overview.py+++ b/products/engineering_analytics/backend/logic/queries/repo_overview.py@@ -441,6 +441,8 @@ class _CostHeadlines:cost_per_merge_usd_prev: float | Nonemerge_queue_billable_minutes: float | Nonemerge_queue_billable_minutes_prev: float | None+ depot_ci_billable_minutes: float | None+ depot_ci_billable_minutes_prev: float | Nonedef _derive_cost_headlines(costs: WindowCostsWithPrev, *, merged_count: int, merged_count_prev: int) -> _CostHeadlines:@@ -459,9 +461,11 @@ def _derive_cost_headlines(costs: WindowCostsWithPrev, *, merged_count: int, mercost_per_merge_usd_prev=opt_float(cost_usd_prev / merged_count_prev)if cost_usd_prev is not None and merged_count_prevelse None,- # The queue slice mirrors billable_minutes' null gating so both go null together.+ # The queue and Depot CI slices mirror billable_minutes' null gating so all go null together.merge_queue_billable_minutes=costs.merge_queue_billable_seconds / 60 if cost_cur else None,merge_queue_billable_minutes_prev=costs.merge_queue_billable_seconds_prev / 60 if cost_prev else None,+ depot_ci_billable_minutes=costs.depot_ci_billable_seconds / 60 if cost_cur else None,+ depot_ci_billable_minutes_prev=costs.depot_ci_billable_seconds_prev / 60 if cost_prev else None,)@@ -538,6 +542,8 @@ def query_repo_overview(cost_per_merge_usd_prev=costs.cost_per_merge_usd_prev,merge_queue_billable_minutes=costs.merge_queue_billable_minutes,merge_queue_billable_minutes_prev=costs.merge_queue_billable_minutes_prev,+ depot_ci_billable_minutes=costs.depot_ci_billable_minutes,+ depot_ci_billable_minutes_prev=costs.depot_ci_billable_minutes_prev,merge_queue_merged_pr_count=queue.merged_pr_count,merge_queue_merged_pr_count_prev=queue.merged_pr_count_prev,merge_queue_median_first_gate_to_merge_seconds=queue.median_first_gate_to_merge_seconds,diff --git a/products/engineering_analytics/backend/presentation/serializers/workflows.py b/products/engineering_analytics/backend/presentation/serializers/workflows.pyindex 26008cfbcf23..99acf56d26d2 100644--- a/products/engineering_analytics/backend/presentation/serializers/workflows.py+++ b/products/engineering_analytics/backend/presentation/serializers/workflows.py@@ -795,6 +795,16 @@ class RepoOverviewSerializer(DataclassSerializer):"source isn't synced.","allow_null": True,},+ "depot_ci_billable_minutes": {+ "help_text": "Slice of billable_minutes from jobs that ran on the Depot CI engine; null "+ "when the job-level source isn't synced.",+ "allow_null": True,+ },+ "depot_ci_billable_minutes_prev": {+ "help_text": "Depot CI billable minutes over the previous window; null when the job-level "+ "source isn't synced.",+ "allow_null": True,+ },"merge_queue_merged_pr_count": {"help_text": "PRs merged in the window with at least one corroborated merge-queue gate run: ""the population behind every merge_queue_* landing stat. All authors, bots included."diff --git a/products/engineering_analytics/backend/tests/test_logic_workflows.py b/products/engineering_analytics/backend/tests/test_logic_workflows.pyindex 9e30d78cb942..913642650977 100644--- a/products/engineering_analytics/backend/tests/test_logic_workflows.py+++ b/products/engineering_analytics/backend/tests/test_logic_workflows.py@@ -296,6 +296,26 @@ class TestWorkflowEndpointsWarehouse(_EndpointsWarehouseMixin, BaseTest):# included: the merge population that triggered the spend) while the median keeps the# locked bots/drafts-excluded recipe, plus job-backed billable minutes, with every# chart series empty. The default call keeps the series for the UI.++ # 180s, unlike the 120s merge-queue job, so the Depot CI slice cannot pass by reading the queue slice.+ depot_started, depot_completed = _ago_with_duration(2, 180)+ self._create_depot_table(+ [+ _depot_attempt_row(+ ref="refs/heads/master",+ sha="sha-depot",+ workflow_name="CI",+ workflow_status="finished",+ workflow_created_at=depot_started,+ workflow_started_at=depot_started,+ workflow_finished_at=depot_completed,+ job_key="ci.yml:lint",+ attempt_status="finished",+ attempt_started_at=depot_started,+ attempt_finished_at=depot_completed,+ )+ ]+ )self._create_table("github_pull_requests",PULL_REQUESTS_COLUMNS,@@ -342,14 +362,17 @@ class TestWorkflowEndpointsWarehouse(_EndpointsWarehouseMixin, BaseTest):assert overview.merged_pr_count == 2 # 80 and 81; 82 merged long before the windowassert overview.merged_pr_count_prev == 0assert overview.median_open_to_merge_seconds == pytest.approx(8 * 86400) # bot PR 81 excluded- assert overview.run_count == 10- assert overview.success_rate == pytest.approx(0.5) # 3 successes of 6 conclusive runs+ assert overview.run_count == 11+ assert overview.success_rate == pytest.approx(4 / 7) # 4 successes of 7 conclusive runsassert overview.rerun_cycles == 1- assert overview.billable_minutes == pytest.approx(4.0) # two 120s jobs on a billable tier- assert overview.estimated_cost_usd == pytest.approx(0.032) # 4 min x $0.004 x 2 (4-core)- assert overview.cost_per_merge_usd == pytest.approx(0.016) # the window's cost over its 2 merges+ assert overview.billable_minutes == pytest.approx(7.0) # two 120s jobs and one 180s Depot CI attempt+ # 4 min x $0.004 x 2 (4-core) on GitHub Actions, plus 3 min x $0.004 on the default Depot CI sandbox+ assert overview.estimated_cost_usd == pytest.approx(0.044)+ assert overview.cost_per_merge_usd == pytest.approx(0.022) # the window's cost over its 2 mergesassert overview.merge_queue_billable_minutes == pytest.approx(2.0) # only the trunk-merge/** jobassert overview.merge_queue_billable_minutes_prev is None # no prev-window jobs, like billable_minutes_prev+ assert overview.depot_ci_billable_minutes == pytest.approx(3.0) # only the Depot CI attempt+ assert overview.depot_ci_billable_minutes_prev is Noneassert overview.median_ready_to_merge_seconds is None # issue events unsynced: not observed, never zeroassert overview.cost_series == []assert overview.time_to_green_series == []@@ -366,7 +389,7 @@ class TestWorkflowEndpointsWarehouse(_EndpointsWarehouseMixin, BaseTest):observed_pass_rates = [bucket.success_rate for bucket in with_series.success_rate_series if bucket.success_rate is not None]- assert observed_pass_rates == [pytest.approx(0.5)]+ assert observed_pass_rates == [pytest.approx(4 / 7)]def test_time_to_green_measures_push_rounds_not_runs(self) -> None:# A per-run median would read this fixture as ~5 min. The round definition asks a differentdiff --git a/products/engineering_analytics/backend/tests/test_presentation.py b/products/engineering_analytics/backend/tests/test_presentation.pyindex 49364e965499..676910a44d23 100644--- a/products/engineering_analytics/backend/tests/test_presentation.py+++ b/products/engineering_analytics/backend/tests/test_presentation.py@@ -148,6 +148,8 @@ def _repo_overview() -> contracts.RepoOverview:cost_per_merge_usd_prev=0.275,merge_queue_billable_minutes=30.0,merge_queue_billable_minutes_prev=0.0,+ depot_ci_billable_minutes=20.0,+ depot_ci_billable_minutes_prev=0.0,merge_queue_merged_pr_count=38,merge_queue_merged_pr_count_prev=35,merge_queue_median_first_gate_to_merge_seconds=1920.0,@@ -409,6 +411,7 @@ class TestEngineeringAnalyticsAPI(APIBaseTest):assert data["merged_pr_count"] == 42assert data["merged_pr_count_prev"] == 40assert data["merge_queue_billable_minutes"] == 30.0 # the digest's queue row reads this key+ assert data["depot_ci_billable_minutes"] == 20.0 # the digest's Depot CI row reads this keyassert data["merge_queue_merged_pr_count"] == 38assert data["merge_queue_median_first_gate_to_merge_seconds"] == 1920.0assert data["merge_queue_failed_or_cancelled_share"] == 0.044diff --git a/products/engineering_analytics/frontend/generated/api.schemas.ts b/products/engineering_analytics/frontend/generated/api.schemas.tsindex 0873e7b3a054..4b8c2888e9d4 100644--- a/products/engineering_analytics/frontend/generated/api.schemas.ts+++ b/products/engineering_analytics/frontend/generated/api.schemas.ts@@ -2030,6 +2030,16 @@ export interface RepoOverviewApi {* @nullable*/merge_queue_billable_minutes_prev: number | null+ /**+ * Slice of billable_minutes from jobs that ran on the Depot CI engine; null when the job-level source isn't synced.+ * @nullable+ */+ depot_ci_billable_minutes: number | null+ /**+ * Depot CI billable minutes over the previous window; null when the job-level source isn't synced.+ * @nullable+ */+ depot_ci_billable_minutes_prev: number | null/** PRs merged in the window with at least one corroborated merge-queue gate run: the population behind every merge_queue_* landing stat. All authors, bots included. */merge_queue_merged_pr_count: number/** Queue-landed merges over the previous window. */diff --git a/products/engineering_analytics/frontend/scenes/RepoOverviewScene.stories.tsx b/products/engineering_analytics/frontend/scenes/RepoOverviewScene.stories.tsxindex 112b13c014fb..aa8e7af44d0a 100644--- a/products/engineering_analytics/frontend/scenes/RepoOverviewScene.stories.tsx+++ b/products/engineering_analytics/frontend/scenes/RepoOverviewScene.stories.tsx@@ -42,6 +42,8 @@ const OVERVIEW: RepoOverviewApi = {// A slice of billable_minutes above, not an addition to it.merge_queue_billable_minutes: 1180,merge_queue_billable_minutes_prev: 940,+ depot_ci_billable_minutes: 2610,+ depot_ci_billable_minutes_prev: 1730,merge_queue_merged_pr_count: 48,merge_queue_merged_pr_count_prev: 41,merge_queue_median_first_gate_to_merge_seconds: 32 * 60,diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex f6a532379138..5747fca17d3d 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -95256,6 +95256,16 @@ export namespace Schemas {* @nullable*/merge_queue_billable_minutes_prev: number | null;+ /**+ * Slice of billable_minutes from jobs that ran on the Depot CI engine; null when the job-level source isn't synced.+ * @nullable+ */+ depot_ci_billable_minutes: number | null;+ /**+ * Depot CI billable minutes over the previous window; null when the job-level source isn't synced.+ * @nullable+ */+ depot_ci_billable_minutes_prev: number | null;/** PRs merged in the window with at least one corroborated merge-queue gate run: the population behind every merge_queue_* landing stat. All authors, bots included. */merge_queue_merged_pr_count: number;/** Queue-landed merges over the previous window. */