Skip to content

Commit 7cc9468

Browse files
committed
[server] Move regionCode handling into WorkspaceService.startWorkspace
1 parent a19f3e7 commit 7cc9468

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

components/server/src/workspace/gitpod-server-impl.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ import { OrganizationService } from "../orgs/organization-service";
190190
import { RedisSubscriber } from "../messaging/redis-subscriber";
191191
import { UsageService } from "../orgs/usage-service";
192192
import { UserService } from "../user/user-service";
193-
import { WorkspaceService } from "./workspace-service";
194193
import { SSHKeyService } from "../user/sshkey-service";
194+
import { StartWorkspaceOptions, WorkspaceService } from "./workspace-service";
195195

196196
// shortcut
197197
export const traceWI = (ctx: TraceContext, wi: Omit<LogContext, "userId">) => TraceContext.setOWI(ctx, wi); // userId is already taken care of in WebsocketConnectionManager
@@ -935,13 +935,11 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
935935
// no matter if the workspace is shared or not, you cannot create a new instance
936936
await this.guardAccess({ kind: "workspaceInstance", subject: undefined, workspace }, "create");
937937

938-
options.region = await this.workspaceService.determineWorkspaceRegion(
939-
user.id,
940-
workspaceId,
941-
options.region || "",
942-
this.clientHeaderFields.clientRegion,
943-
);
944-
const result = await this.workspaceService.startWorkspace(ctx, user, workspaceId, options);
938+
const opts: StartWorkspaceOptions = {
939+
...options,
940+
clientRegionCode: this.clientHeaderFields?.clientRegion,
941+
};
942+
const result = await this.workspaceService.startWorkspace(ctx, user, workspaceId, opts);
945943
traceWI(ctx, { instanceId: result.instanceID });
946944
return result;
947945
}
@@ -1417,13 +1415,11 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
14171415
logContext.workspaceId = workspace.id;
14181416
traceWI(ctx, { workspaceId: workspace.id });
14191417

1420-
options.region = await this.workspaceService.determineWorkspaceRegion(
1421-
user.id,
1422-
workspace.id,
1423-
options.region || "",
1424-
this.clientHeaderFields.clientRegion,
1425-
);
1426-
const startWorkspaceResult = await this.workspaceService.startWorkspace(ctx, user, workspace.id, options);
1418+
const opts: StartWorkspaceOptions = {
1419+
...options,
1420+
clientRegionCode: this.clientHeaderFields?.clientRegion,
1421+
};
1422+
const startWorkspaceResult = await this.workspaceService.startWorkspace(ctx, user, workspace.id, opts);
14271423
ctx.span?.log({ event: "startWorkspaceComplete", ...startWorkspaceResult });
14281424

14291425
return {

components/server/src/workspace/workspace-service.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ import { RegionService } from "./region-service";
3131
import { ProjectsService } from "../projects/projects-service";
3232
import { EnvVarService } from "./env-var-service";
3333

34+
export interface StartWorkspaceOptions extends GitpodServer.StartWorkspaceOptions {
35+
/**
36+
* This field is used to guess the workspace location using the RegionService
37+
*/
38+
clientRegionCode?: string;
39+
}
40+
3441
@injectable()
3542
export class WorkspaceService {
3643
constructor(
@@ -228,7 +235,7 @@ export class WorkspaceService {
228235
ctx: TraceContext,
229236
user: User,
230237
workspaceId: string,
231-
options?: GitpodServer.StartWorkspaceOptions,
238+
options: StartWorkspaceOptions = {},
232239
): Promise<StartWorkspaceResult> {
233240
await this.auth.checkPermissionOnWorkspace(user.id, "start", workspaceId);
234241

@@ -259,6 +266,13 @@ export class WorkspaceService {
259266

260267
await mayStartPromise;
261268

269+
options.region = await this.determineWorkspaceRegion(
270+
user.id,
271+
workspaceId,
272+
options.region || "",
273+
options.clientRegionCode,
274+
);
275+
262276
// at this point we're about to actually start a new workspace
263277
const result = await this.workspaceStarter.startWorkspace(
264278
ctx,
@@ -314,7 +328,7 @@ export class WorkspaceService {
314328
}
315329
}
316330

317-
async determineWorkspaceRegion(
331+
private async determineWorkspaceRegion(
318332
userId: string,
319333
workspaceId: string,
320334
preference: WorkspaceRegion,

0 commit comments

Comments
 (0)