Files
coder/scripts/workspace-runtime-audit
Ethan 86ea5d4c4e ci: bump paralleltestctx to detect timeout contexts used through closures (#31039)
#31011 fixed a flake where a closure in `TestProjectSkillQueries` used
the parent test's `testutil.Context` from parallel subtests. Once that
deadline passed, the closure's `require.NoError` called `FailNow` on the
parent `t`, which panics and takes down the whole `coderd/database`
package. `paralleltestctx` only checked direct references to the
context, so it missed this. coder/paralleltestctx#6 now follows calls to
local closures too.

This pins `paralleltestctx` to the current `main` commit, as there's no
tag yet. That commit also brings in the outer variable reassignment
check from coder/paralleltestctx#4 and the `x/tools` bump from
coder/paralleltestctx#5. The closure check flagged the `loadPrompt`
helper in `TestMediaToolResultRoundTrip`, so it now makes its own
context from the subtest's `t`. The `TestGraph` and `TestRuntimeAudit`
fixes for the outer variable check are the same as in #30288, so that PR
only needs to repin.
2026-10-20 15:41:25 +11: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