Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9dd9fed

Browse files
committed
Implement strict prebuilds eligibility
Seecoder/internal#372Signed-off-by: Danny Kopping <danny@coder.com>
1 parente9fdd86 commit9dd9fed

File tree

6 files changed

+159
-75
lines changed

6 files changed

+159
-75
lines changed

‎coderd/database/dump.sql

Lines changed: 95 additions & 39 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/migrations/000294_prebuilds.up.sql

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,18 @@ VALUES ('c42fdf75-3097-471c-8c33-fb52454d81c0', 'prebuilds@system', 'prebuilds',
44
'active','{}','none', true);
55

66
-- TODO: do we *want* to use the default org here? how do we handle multi-org?
7-
WITH default_orgAS (
8-
SELECT idFROM organizationsWHERE is_default= trueLIMIT1
9-
)
10-
INSERT INTO organization_members (organization_id, user_id, created_at, updated_at)
11-
SELECT
12-
default_org.id,
13-
'c42fdf75-3097-471c-8c33-fb52454d81c0',
14-
NOW(),
15-
NOW()
7+
WITH default_orgAS (SELECT id
8+
FROM organizations
9+
WHERE is_default= true
10+
LIMIT1)
11+
INSERT
12+
INTO organization_members (organization_id, user_id, created_at, updated_at)
13+
SELECTdefault_org.id,
14+
'c42fdf75-3097-471c-8c33-fb52454d81c0',
15+
NOW(),
16+
NOW()
1617
FROM default_org;
1718

18-
CREATEVIEWworkspace_prebuildsAS
19-
SELECT*
20-
FROM workspaces
21-
WHERE owner_id='c42fdf75-3097-471c-8c33-fb52454d81c0';
22-
23-
CREATEVIEWworkspace_prebuild_buildsAS
24-
SELECT*
25-
FROM workspace_builds
26-
WHERE initiator_id='c42fdf75-3097-471c-8c33-fb52454d81c0';
27-
2819
CREATEVIEWworkspace_latest_buildAS
2920
SELECT wb.*
3021
FROM (SELECTtv.template_id,
@@ -38,3 +29,22 @@ FROM (SELECT tv.template_id,
3829
ANDwb.build_number=wbmax.max_build_number
3930
);
4031

32+
CREATEVIEWworkspace_prebuildsAS
33+
WITH all_prebuildsAS (SELECT w.*
34+
FROM workspaces w
35+
WHEREw.owner_id='c42fdf75-3097-471c-8c33-fb52454d81c0'),
36+
workspace_agentsAS (SELECTw.idAS workspace_id,wa.idAS agent_id,wa.lifecycle_state,wa.ready_at
37+
FROM workspaces w
38+
INNER JOIN workspace_latest_build wlbONwlb.workspace_id=w.id
39+
INNER JOIN workspace_resources wrONwr.job_id=wlb.job_id
40+
INNER JOIN workspace_agents waONwa.resource_id=wr.id
41+
WHEREw.owner_id='c42fdf75-3097-471c-8c33-fb52454d81c0'
42+
GROUP BYw.id,wa.id)
43+
SELECT p.*,a.agent_id,a.lifecycle_state,a.ready_at
44+
FROM all_prebuilds p
45+
LEFT JOIN workspace_agents aONa.workspace_id=p.id;
46+
47+
CREATEVIEWworkspace_prebuild_buildsAS
48+
SELECT*
49+
FROM workspace_builds
50+
WHERE initiator_id='c42fdf75-3097-471c-8c33-fb52454d81c0';

‎coderd/database/models.go

Lines changed: 19 additions & 16 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries.sql.go

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

‎coderd/database/queries/prebuilds.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ WITH
66
tvp_curr.idAS current_preset_id,
77
tvp_desired.idAS desired_preset_id,
88
COUNT(*)AS count,
9+
SUM(CASE
10+
WHENp.lifecycle_state='ready'::workspace_agent_lifecycle_state THEN1
11+
ELSE0 END)AS eligible,
912
STRING_AGG(p.id::text,',')AS ids
1013
FROM workspace_prebuilds p
1114
INNER JOIN workspace_latest_build bONb.workspace_id=p.id
@@ -56,6 +59,8 @@ SELECT t.template_id,
5659
ELSE'' END)::textAS running_prebuild_ids,
5760
COALESCE(MAX(CASE WHENt.using_active_version THENp.count ELSE0 END),
5861
0)::intAS actual,-- running prebuilds for active version
62+
COALESCE(MAX(CASE WHENt.using_active_version THENp.eligible ELSE0 END),
63+
0)::intAS eligible,-- prebuilds which can be claimed
5964
MAX(CASE WHENt.using_active_version THENt.desired_instances ELSE0 END)::intAS desired,-- we only care about the active version's desired instances
6065
COALESCE(MAX(CASE
6166
WHENp.template_version_id=t.template_version_idAND
@@ -106,6 +111,7 @@ WHERE w.id IN (SELECT p.id
106111
ANDpj.job_statusIN ('succeeded'::provisioner_job_status))
107112
ANDb.template_version_id=t.active_version_id
108113
ANDb.template_version_preset_id= @preset_id::uuid
114+
ANDp.lifecycle_state='ready'::workspace_agent_lifecycle_state
109115
ORDER BY random()
110116
LIMIT1 FORUPDATE OF p SKIP LOCKED)
111117
RETURNINGw.id,w.name;

‎enterprise/coderd/prebuilds/controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,8 @@ func (c *Controller) reconcileTemplate(ctx context.Context, template database.Te
328328
slog.F("to_create",len(actions.createIDs)),slog.F("to_delete",len(actions.deleteIDs)),
329329
slog.F("desired",actions.meta.Desired),slog.F("actual",actions.meta.Actual),
330330
slog.F("outdated",actions.meta.Outdated),slog.F("extraneous",actions.meta.Extraneous),
331-
slog.F("starting",actions.meta.Starting),slog.F("stopping",actions.meta.Stopping),slog.F("deleting",actions.meta.Deleting))
331+
slog.F("starting",actions.meta.Starting),slog.F("stopping",actions.meta.Stopping),
332+
slog.F("deleting",actions.meta.Deleting),slog.F("eligible",actions.meta.Eligible))
332333

333334
// Provision workspaces within the same tx so we don't get any timing issues here.
334335
// i.e. we hold the advisory lock until all reconciliatory actions have been taken.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp