-
Notifications
You must be signed in to change notification settings - Fork 838
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
feat: add migrations and queries to support prebuilds #16891
Conversation
@@ -12,6 +12,8 @@ const ( | |||
LockIDDBPurge | |||
LockIDNotificationsReportGenerator | |||
LockIDCryptoKeyRotation | |||
LockIDReconcileTemplatePrebuilds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need two separate locks because we'll have a wider reconciliation loop which must hold a global lock, and an inner lock which is used to protect the piece where we determine the state. The latter can be called outside of a reconciliation loop (as in the metrics collection).
e1b1e36
to
81ba8d2
Compare
2024110
to
390a1fd
Compare
Do we want to add unit-tests on DB level in this PR to make sure VIEWs and SQL queries are correct? |
Feels like overkill to me, since we have tests which rely on the views indirectly, but if you feel it'd add value then go ahead 👍 |
70ecdcc
to
7e062e2
Compare
Signed-off-by: Danny Kopping <[email protected]>
Signed-off-by: Danny Kopping <[email protected]>
Signed-off-by: Danny Kopping <[email protected]>
Signed-off-by: Danny Kopping <[email protected]>
appeasing linter Signed-off-by: Danny Kopping <[email protected]>
Signed-off-by: Danny Kopping <[email protected]>
Signed-off-by: Danny Kopping <[email protected]>
c92fb1b
to
e7e9c27
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 on the RBAC checks. @spikecurtis no ResourceSystem is now used.
Resource<Type>.All()
is used in almost all of these because there is no filter for orgs or a user. The reconciliation loop queries across all orgs.
The queries should succeed or fail as an entire set, rather then be filtered. Based on how they are used. In the future, if we add more views for prebuilds, we can update these queries to filter and apply the appropriate checks. Similar to how we filter workspaces & templates today.
workspaceObject := rbac.ResourceWorkspace.WithOwner(arg.NewUserID.String()).InOrg(preset.OrganizationID) | ||
err = q.authorizeContext(ctx, policy.ActionCreate, workspaceObject.RBACObject()) | ||
if err != nil { | ||
return empty, err | ||
} | ||
|
||
tpl, err := q.GetTemplateByID(ctx, preset.TemplateID.UUID) | ||
if err != nil { | ||
return empty, xerrors.Errorf("verify template by id: %w", err) | ||
} | ||
if err := q.authorizeContext(ctx, policy.ActionUse, tpl); err != nil { | ||
return empty, xerrors.Errorf("use template for workspace: %w", err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just leave a comment this should match InsertWorkspace
func (q *querier) CountInProgressPrebuilds(ctx context.Context) ([]database.CountInProgressPrebuildsRow, error) { | ||
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceWorkspace.All()); err != nil { | ||
return nil, err | ||
} | ||
return q.db.CountInProgressPrebuilds(ctx) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This query spans all organizations, and prebuilds are just workspaces 👍
func (q *querier) GetPresetsBackoff(ctx context.Context, lookback time.Time) ([]database.GetPresetsBackoffRow, error) { | ||
// GetPresetsBackoff returns a list of template version presets along with metadata such as the number of failed prebuilds. | ||
if err := q.authorizeContext(ctx, policy.ActionViewInsights, rbac.ResourceTemplate.All()); err != nil { | ||
return nil, err | ||
} | ||
return q.db.GetPresetsBackoff(ctx, lookback) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@spikecurtis we decided to just lump in the preset metrics with template insights. Since template insights are metrics related to a template, prebuild metrics metadata is essentially the same imo.
Depends on #16916 (change base to
main
once it is merged)Closes coder/internal#514
This is one of several PRs to decompose the
dk/prebuilds
feature branch into separate PRs to merge intomain
.