-
Notifications
You must be signed in to change notification settings - Fork 943
feat: track resource replacements when claiming a prebuilt workspace #17571
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
Changes from 3 commits
b32923a
0b0830f
256395a
61ef61a
a66559f
222892b
f34e011
5168c01
41e5e0c
b29e8fa
b31ed5e
adf98d2
f24aef0
70f9a53
1e8385d
d0f00ce
11a2c5a
ce63b24
d2c5d43
22d82a4
5209aae
39ce658
ac5655f
82c3f58
7577a90
a893b79
d9c906a
471198a
7d694e6
6b7a8b7
5df2cb3
6d1c3ea
5f62702
f74d799
971f65c
bc362b0
4fbd356
b9eb8be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -630,21 +630,21 @@ func (c *StoreReconciler) provision( | |
return nil | ||
} | ||
|
||
func (c *StoreReconciler) TrackResourceReplacement(ctx context.Context, workspaceID, buildID, claimantID uuid.UUID, replacements []*sdkproto.ResourceReplacement) { | ||
func (c *StoreReconciler) TrackResourceReplacement(ctx context.Context, workspaceID, buildID uuid.UUID, replacements []*sdkproto.ResourceReplacement) { | ||
// Set authorization context since this may be called in the background (i.e. with a bare context). | ||
// nolint:gocritic // Necessary to query all the required data. | ||
ctx = dbauthz.AsSystemRestricted(ctx) | ||
// Since this may be called in a fire-and-forget fashion, we need to give up at some point. | ||
trackCtx, trackCancel := context.WithTimeout(ctx, time.Minute) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a best-effort attempt to warn operators of this situation; it's ok if it times out, we'll get a log to trace this with. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see this partially covers my earlier comment. I still think it'd be good to take shutdowns into consideration for these and define what that behavior should be (rather than undefined). Right now these routines will be rudely interrupted during shutdown rather than exiting cleanly. Likewise these can be left running even if a CompleteJob is interrupted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Good call! I've now passed in the
I believe that's already the case? |
||
defer trackCancel() | ||
|
||
if err := c.trackResourceReplacement(trackCtx, workspaceID, buildID, claimantID, replacements); err != nil { | ||
if err := c.trackResourceReplacement(trackCtx, workspaceID, buildID, replacements); err != nil { | ||
c.logger.Error(ctx, "failed to track resource replacement", slog.Error(err)) | ||
} | ||
} | ||
|
||
// nolint:revive // Shut up it's fine. | ||
func (c *StoreReconciler) trackResourceReplacement(ctx context.Context, workspaceID, buildID, claimantID uuid.UUID, replacements []*sdkproto.ResourceReplacement) error { | ||
func (c *StoreReconciler) trackResourceReplacement(ctx context.Context, workspaceID, buildID uuid.UUID, replacements []*sdkproto.ResourceReplacement) error { | ||
if err := ctx.Err(); err != nil { | ||
dannykopping marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return err | ||
} | ||
|
@@ -677,9 +677,9 @@ func (c *StoreReconciler) trackResourceReplacement(ctx context.Context, workspac | |
return xerrors.Errorf("fetch template preset for template version ID %q: %w", prebuild.TemplateVersionID.String(), err) | ||
} | ||
|
||
claimant, err := c.store.GetUserByID(ctx, claimantID) | ||
claimant, err := c.store.GetUserByID(ctx, workspace.OwnerID) // At this point, the workspace is owned by the new owner. | ||
if err != nil { | ||
return xerrors.Errorf("fetch claimant %q: %w", claimantID.String(), err) | ||
return xerrors.Errorf("fetch claimant %q: %w", workspace.OwnerID.String(), err) | ||
} | ||
|
||
// Use the claiming build here (not prebuild) because both should be equivalent, and we might as well spot inconsistencies now. | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh! 8000
There was an error while loading. Please reload this page.