8000 Properly label and filter metrics for prebuilds · coder/coder@7a8ec49 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7a8ec49

Browse files
committed
Properly label and filter metrics for prebuilds
1 parent 8fd34ab commit 7a8ec49

File tree

9 files changed

+146
-150
lines changed

9 files changed

+146
-150
lines changed

coderd/database/dump.sql

Lines changed: 73 additions & 88 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/migrations/000310_prebuilds.up.sql renamed to coderd/database/migrations/000312_prebuilds.up.sql

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,32 @@ WITH
1919
-- and therefore we can't rely on (say) the latest build's chosen template_version_preset_id.
2020
--
2121
-- See https://github.com/coder/internal/issues/398
22-
latest_prebuild_builds AS (
22+
workspaces_with_latest_presets AS (
2323
SELECT DISTINCT ON (workspace_id) workspace_id, template_version_preset_id
2424
FROM workspace_builds
2525
WHERE template_version_preset_id IS NOT NULL
2626
ORDER BY workspace_id, build_number DESC
2727
),
28-
-- All workspace agents belonging to the workspaces owned by the "prebuilds" user.
29-
workspace_agents AS (
30-
SELECT w.id AS workspace_id, wa.id AS agent_id, wa.lifecycle_state, wa.ready_at
28+
-- workspaces_with_agents_status contains workspaces owned by the "prebuilds" user,
29+
-- along with the readiness status of their agents.
30+
-- A workspace is marked as 'ready' only if ALL of its agents are ready.
31+
workspaces_with_agents_status AS (
32+
SELECT w.id AS workspace_id,
33+
BOOL_AND(wa.lifecycle_state = 'ready'::workspace_agent_lifecycle_state) AS ready
3134
FROM workspaces w
3235
INNER JOIN workspace_latest_builds wlb ON wlb.workspace_id = w.id
3336
INNER JOIN workspace_resources wr ON wr.job_id = wlb.job_id
3437
INNER JOIN workspace_agents wa ON wa.resource_id = wr.id
3538
WHERE w.owner_id = 'c42fdf75-3097-471c-8c33-fb52454d81c0' -- The system user responsible for prebuilds.
36-
GROUP BY w.id, wa.id
39+
GROUP BY w.id
3740
),
38-
current_presets AS (SELECT w.id AS prebuild_id, lpb.template_version_preset_id
41+
current_presets AS (SELECT w.id AS prebuild_id, wlp.template_version_preset_id
3942
FROM workspaces w
40-
INNER JOIN latest_prebuild_builds lpb ON lpb.workspace_id = w.id
43+
INNER JOIN workspaces_with_latest_presets wlp ON wlp.workspace_id = w.id
4144
WHERE w.owner_id = 'c42fdf75-3097-471c-8c33-fb52454d81c0') -- The system user responsible for prebuilds.
42-
SELECT p.id, p.name, p.template_id, p.created_at, a.agent_id, a.lifecycle_state, a.ready_at, cp.template_version_preset_id AS current_preset_id
45+
SELECT p.id, p.name, p.template_id, p.created_at, COALESCE(a.ready, false) AS ready, cp.template_version_preset_id AS current_preset_id
4346
FROM all_prebuilds p
44-
LEFT JOIN workspace_agents a ON a.workspace_id = p.id
47+
LEFT JOIN workspaces_with_agents_status a ON a.workspace_id = p.id
4548
INNER JOIN current_presets cp ON cp.prebuild_id = p.id;
4649

4750
CREATE VIEW workspace_prebuild_builds AS

coderd/database/models.go

Lines changed: 6 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 34 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0