Skip to content

[server] Every time we stop a workspace instance, log the reason why #12963

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 1 commit into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion components/server/ee/src/prebuilds/prebuild-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,14 @@ export class PrebuildManager {
for (const instance of prebuild.instances) {
log.info(
{ userId: user.id, instanceId: instance.id, workspaceId: instance.workspaceId },
"Aborting Prebuild workspace because a newer commit was pushed to the same branch.",
"Cancelling Prebuild workspace because a newer commit was pushed to the same branch.",
);
results.push(
this.workspaceStarter.stopWorkspaceInstance(
{ span },
instance.id,
instance.region,
"prebuild cancelled because a newer commit was pushed to the same branch",
StopWorkspacePolicy.ABORT,
),
);
Expand Down
3 changes: 2 additions & 1 deletion components/server/ee/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
ctx,
instance.id,
instance.region,
"user blocked by admin",
StopWorkspacePolicy.IMMEDIATELY,
),
);
Expand Down Expand Up @@ -867,7 +868,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {

const workspace = await this.workspaceDb.trace(ctx).findById(workspaceId);
if (workspace) {
await this.internalStopWorkspace(ctx, workspace, StopWorkspacePolicy.IMMEDIATELY, true);
await this.internalStopWorkspace(ctx, workspace, "stopped by admin", StopWorkspacePolicy.IMMEDIATELY, true);
}
}

Expand Down
4 changes: 4 additions & 0 deletions components/server/src/user/user-deletion-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ export class UserDeletionService {
runningWorkspaces.map(async (info) => {
const wsi = info.latestInstance;

log.info({ workspaceId: info.workspace.id, instanceId: wsi.id }, "Stopping workspace instance", {
reason: "deleting user",
});

const req = new StopWorkspaceRequest();
req.setId(wsi.id);
req.setPolicy(StopWorkspacePolicy.NORMALLY);
Expand Down
8 changes: 5 additions & 3 deletions components/server/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -748,14 +748,15 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
await this.guardAccess({ kind: "workspace", subject: workspace }, "get");
}

this.internalStopWorkspace(ctx, workspace).catch((err) => {
this.internalStopWorkspace(ctx, workspace, "stopped via API").catch((err) => {
log.error(logCtx, "stopWorkspace error: ", err);
});
}

protected async internalStopWorkspace(
ctx: TraceContext,
workspace: Workspace,
reason: string,
policy?: StopWorkspacePolicy,
admin: boolean = false,
): Promise<void> {
Expand All @@ -782,7 +783,8 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
await this.guardAccess({ kind: "workspaceInstance", subject: instance, workspace }, "update");
}
}
await this.workspaceStarter.stopWorkspaceInstance(ctx, instance.id, instance.region, policy);

await this.workspaceStarter.stopWorkspaceInstance(ctx, instance.id, instance.region, reason, policy);
}

protected async guardAdminAccess(method: string, params: any, requiredPermission: PermissionName) {
Expand Down Expand Up @@ -834,7 +836,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
await this.guardAccess({ kind: "workspace", subject: ws }, "delete");

// for good measure, try and stop running instances
await this.internalStopWorkspace(ctx, ws);
await this.internalStopWorkspace(ctx, ws, "deleted via API");

// actually delete the workspace
await this.workspaceDeletionService.softDeleteWorkspace(ctx, ws, "user");
Expand Down
4 changes: 4 additions & 0 deletions components/server/src/workspace/workspace-starter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,12 @@ export class WorkspaceStarter {
ctx: TraceContext,
instanceId: string,
instanceRegion: string,
reason: string,
policy?: StopWorkspacePolicy,
): Promise<void> {
ctx.span?.setTag("stopWorkspaceReason", reason);
log.info({ instanceId }, "Stopping workspace instance", { reason });

const req = new StopWorkspaceRequest();
req.setId(instanceId);
req.setPolicy(policy || StopWorkspacePolicy.NORMALLY);
Expand Down