Files
Cian Johnston 25a0c807cb chore(coderd/database/dbfake): add support for provisioner job timestamp control (#21944)
Relates to https://github.com/coder/coder/pull/21922 /
https://github.com/coder/internal/issues/1259

* Adds `dbfake.BuilderOption func(*WorkspaceBuildBuilder)`
* Adds `BuilderOption` methods for setting various provisioner job
related fields on `WorkspaceBuildBuilder`.
* Migrates a number of existing tests that previously dependeded on
provisioner job timing to use these updated methods in the following
packages:
  * `coderd/jobreaper`
  * `coderd/notifications/reports`
  * `enterprise/coderd/schedule`
  * `enterprise/coderd/prebuilds`
  * `scripts/workspace-runtime-audit` 

🤖 Created using Mux (Opus 4.5)

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-02-06 09:44:40 +00:00
..

Workspace Runtime Audit

Warning

Do not run this script unless specifically instructed to do so by Coder support or engineering.

Always run this script from a postgres user with read-only access to the database.

A SQL script that analyzes workspace builds to determine how long each workspace spent in a "running" state. It tracks state transitions (start/stop/delete) and calculates the cumulative runtime, only counting time spent inside the audit window period.

Usage

1: Edit the date range in workspace-runtime-audit.sql:

start_time TIMESTAMPTZ := '2025-12-01 00:00:00+00';
end_time TIMESTAMPTZ := '2025-12-31 23:59:59+00';

2: Run against your Coder database:

psql -d coder -f scripts/workspace-runtime-audit/workspace-runtime-audit.sql

3: Review the output csv at workspace_usage.csv.

Output

Column Type Description
workspace_id timestamptz Name of the workspace
workspace_created_at timestamptz When the workspace was originally created
usage_hours int Total number of usage hours within the time window