Skip to content

Commit

Permalink
[server] Every time we stop a workspace instance, log the reason why
Browse files Browse the repository at this point in the history
  • Loading branch information
jankeromnes authored and roboquat committed Sep 16, 2022
1 parent 243ee21 commit 3ac0c02
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
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 @@ -664,6 +664,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
ctx,
instance.id,
instance.region,
"user blocked by admin",
StopWorkspacePolicy.IMMEDIATELY,
),
);
Expand Down Expand Up @@ -897,7 +898,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 @@ -436,8 +436,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

0 comments on commit 3ac0c02

Please sign in to comment.