Skip to content

fix: make GetWorkspacesEligibleForTransition return even less false positives #15594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
78d9bef
fix: begin impl of reducing autostart false-positive rate
DanielleMaywood Nov 18, 2024
dea0c20
chore: update dbmem.go
DanielleMaywood Nov 18, 2024
d0f1851
fix: dbmem.go impl
DanielleMaywood Nov 19, 2024
077439c
test: refactor test slightly
DanielleMaywood Nov 19, 2024
3b41985
fix: update golden files
DanielleMaywood Nov 19, 2024
1a66a14
fix: dbmem.go convertToWorkspaceRowsNoLock
DanielleMaywood Nov 19, 2024
9725ec7
fix: pass currentTick to GetWorkspacesEligibleForTransition
DanielleMaywood Nov 20, 2024
5e9b806
revert: query change
DanielleMaywood Nov 21, 2024
b2a037b
fix: ensure times are converted back to UTC
DanielleMaywood Nov 21, 2024
997c902
Merge branch 'main' into dm-experiment-autostart
DanielleMaywood Nov 21, 2024
dd05558
test: next start at is only a valid value
DanielleMaywood Nov 22, 2024
8bddfdf
fix: appease linter
DanielleMaywood Nov 22, 2024
66a01a3
chore: add an index for next_start_at
DanielleMaywood Nov 22, 2024
b7434c0
fix: run 'make gen'
DanielleMaywood Nov 22, 2024
100f54c
chore: begin impl of tests
DanielleMaywood Nov 25, 2024
d201025
Merge branch 'main' into dm-experiment-autostart
DanielleMaywood Nov 25, 2024
eac63b7
test: fix tests
DanielleMaywood Nov 25, 2024
1b31cbb
fix: use american english
DanielleMaywood Nov 25, 2024
eaf32ee
fix: make NextAllowedAutostart look up to 7 days into the future
DanielleMaywood Nov 26, 2024
1599b2a
fix: TestExecutorAutostartBlocked test
DanielleMaywood Nov 26, 2024
142e335
fix: make enterprise template schedule store use quartz.clock
DanielleMaywood Nov 26, 2024
3f17e46
fix: infinite loop
DanielleMaywood Nov 26, 2024
e993643
refactor: give template schedule store a quartz.clock
DanielleMaywood Nov 26, 2024
d349c56
fix: ensure tests give template schedule store a clock
DanielleMaywood Nov 26, 2024
a48fb99
fix: nullify next_start_at on schedule update
DanielleMaywood Nov 27, 2024
cc93075
fix: tests
DanielleMaywood Nov 27, 2024
45350d1
chore: remove clock from test
DanielleMaywood Nov 27, 2024
c1648ae
Merge branch 'main' into dm-experiment-autostart
DanielleMaywood Nov 27, 2024
03d0b7f
chore: relocate test
DanielleMaywood Nov 27, 2024
23b2ec9
chore: nits
DanielleMaywood Nov 28, 2024
18f3c8a
Merge branch 'main' into dm-experiment-autostart
DanielleMaywood Nov 28, 2024
8b1b6d9
chore: bump migration number
DanielleMaywood Nov 28, 2024
2d239a6
fix: stop query returning dormant workspaces
DanielleMaywood Nov 28, 2024
2e2f13a
Merge branch 'main' into dm-experiment-autostart
DanielleMaywood Nov 28, 2024
df74e6f
Merge branch 'main' into dm-experiment-autostart
DanielleMaywood Dec 2, 2024
dec3d6c
chore: add index to template_id on workspaces
DanielleMaywood Dec 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: begin impl of reducing autostart false-positive rate
  • Loading branch information
DanielleMaywood committed Nov 20, 2024
commit 78d9bef493133cf735494cc5594b7847a2818d35
7 changes: 7 additions & 0 deletions coderd/database/dbauthz/dbauthz.go
Original file line number Diff line number Diff line change
Expand Up @@ -4044,6 +4044,13 @@ func (q *querier) UpdateWorkspaceLastUsedAt(ctx context.Context, arg database.Up
return update(q.log, q.auth, fetch, q.db.UpdateWorkspaceLastUsedAt)(ctx, arg)
}

func (q *querier) UpdateWorkspaceNextStartAt(ctx context.Context, arg database.UpdateWorkspaceNextStartAtParams) error {
fetch := func(ctx context.Context, arg database.UpdateWorkspaceNextStartAtParams) (database.Workspace, error) {
return q.db.GetWorkspaceByID(ctx, arg.ID)
}
return update(q.log, q.auth, fetch, q.db.UpdateWorkspaceNextStartAt)(ctx, arg)
}

func (q *querier) UpdateWorkspaceProxy(ctx context.Context, arg database.UpdateWorkspaceProxyParams) (database.WorkspaceProxy, error) {
fetch := func(ctx context.Context, arg database.UpdateWorkspaceProxyParams) (database.WorkspaceProxy, error) {
return q.db.GetWorkspaceProxyByID(ctx, arg.ID)
Expand Down
7 changes: 7 additions & 0 deletions coderd/database/dbauthz/dbauthz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1887,6 +1887,13 @@ func (s *MethodTestSuite) TestWorkspace() {
ID: ws.ID,
}).Asserts(ws, policy.ActionUpdate).Returns()
}))
s.Run("UpdateWorkspaceNextStartAt", s.Subtest(func(db database.Store, check *expects) {
ws := dbgen.Workspace(s.T(), db, database.WorkspaceTable{})
check.Args(database.UpdateWorkspaceNextStartAtParams{
ID: ws.ID,
NextStartAt: sql.NullTime{Valid: true, Time: dbtime.Now()},
}).Asserts(ws, policy.ActionUpdate)
}))
s.Run("BatchUpdateWorkspaceLastUsedAt", s.Subtest(func(db database.Store, check *expects) {
ws1 := dbgen.Workspace(s.T(), db, database.WorkspaceTable{})
ws2 := dbgen.Workspace(s.T(), db, database.WorkspaceTable{})
Expand Down
23 changes: 23 additions & 0 deletions coderd/database/dbmem/dbmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -9950,6 +9950,29 @@ func (q *FakeQuerier) UpdateWorkspaceLastUsedAt(_ context.Context, arg database.
return sql.ErrNoRows
}

func (q *FakeQuerier) UpdateWorkspaceNextStartAt(ctx context.Context, arg database.UpdateWorkspaceNextStartAtParams) error {
err := validateDatabaseType(arg)
if err != nil {
return err
}

q.mutex.Lock()
defer q.mutex.Unlock()

for index, workspace := range q.workspaces {
if workspace.ID != arg.ID {
continue
}

workspace.NextStartAt = arg.NextStartAt
q.workspaces[index] = workspace

return nil
}

return sql.ErrNoRows
}

func (q *FakeQuerier) UpdateWorkspaceProxy(_ context.Context, arg database.UpdateWorkspaceProxyParams) (database.WorkspaceProxy, error) {
q.mutex.Lock()
defer q.mutex.Unlock()
Expand Down
7 changes: 7 additions & 0 deletions coderd/database/dbmetrics/querymetrics.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions coderd/database/dbmock/dbmock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion coderd/database/dump.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
DROP VIEW workspaces_expanded;

ALTER TABLE ONLY workspaces DROP COLUMN IF EXISTS next_start_at;

CREATE VIEW
workspaces_expanded
AS
SELECT
workspaces.*,
-- Owner
visible_users.avatar_url AS owner_avatar_url,
visible_users.username AS owner_username,
-- Organization
organizations.name AS organization_name,
organizations.display_name AS organization_display_name,
organizations.icon AS organization_icon,
organizations.description AS organization_description,
-- Template
templates.name AS template_name,
templates.display_name AS template_display_name,
templates.icon AS template_icon,
templates.description AS template_description
FROM
workspaces
INNER JOIN
visible_users
ON
workspaces.owner_id = visible_users.id
INNER JOIN
organizations
ON workspaces.organization_id = organizations.id
INNER JOIN
templates
ON workspaces.template_id = templates.id
;

COMMENT ON VIEW workspaces_expanded IS 'Joins in the display name information such as username, avatar, and organization name.';
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
ALTER TABLE ONLY workspaces ADD COLUMN IF NOT EXISTS next_start_at TIMESTAMPTZ DEFAULT NULL;

-- Recreate view
DROP VIEW workspaces_expanded;

CREATE VIEW
workspaces_expanded
AS
SELECT
workspaces.*,
-- Owner
visible_users.avatar_url AS owner_avatar_url,
visible_users.username AS owner_username,
-- Organization
organizations.name AS organization_name,
organizations.display_name AS organization_display_name,
organizations.icon AS organization_icon,
organizations.description AS organization_description,
-- Template
templates.name AS template_name,
templates.display_name AS template_display_name,
templates.icon AS template_icon,
templates.description AS template_description
FROM
workspaces
INNER JOIN
visible_users
ON
workspaces.owner_id = visible_users.id
INNER JOIN
organizations
ON workspaces.organization_id = organizations.id
INNER JOIN
templates
ON workspaces.template_id = templates.id
;

COMMENT ON VIEW workspaces_expanded IS 'Joins in the display name information such as username, avatar, and organization name.';
2 changes: 2 additions & 0 deletions coderd/database/modelmethods.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ func (w Workspace) WorkspaceTable() WorkspaceTable {
DeletingAt: w.DeletingAt,
AutomaticUpdates: w.AutomaticUpdates,
Favorite: w.Favorite,
NextStartAt: w.NextStartAt,
}
}

Expand Down Expand Up @@ -438,6 +439,7 @@ func ConvertWorkspaceRows(rows []GetWorkspacesRow) []Workspace {
TemplateDisplayName: r.TemplateDisplayName,
TemplateIcon: r.TemplateIcon,
TemplateDescription: r.TemplateDescription,
NextStartAt: r.NextStartAt,
}
}

Expand Down
1 change: 1 addition & 0 deletions coderd/database/modelqueries.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ func (q *sqlQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg GetWorkspa
&i.DeletingAt,
&i.AutomaticUpdates,
&i.Favorite,
&i.NextStartAt,
&i.OwnerAvatarUrl,
&i.OwnerUsername,
&i.OrganizationName,
Expand Down
4 changes: 3 additions & 1 deletion coderd/database/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions coderd/database/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading