Skip to content

Commit da8a7a4

Browse files
committed
[server] Move regionCode handling into WorkspaceService.startWorkspace
1 parent d3739c2 commit da8a7a4

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
@@ -191,7 +191,7 @@ import { OrganizationService } from "../orgs/organization-service";
191191
import { RedisSubscriber } from "../messaging/redis-subscriber";
192192
import { UsageService } from "../orgs/usage-service";
193193
import { UserService } from "../user/user-service";
194-
import { WorkspaceService } from "./workspace-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
@@ -934,13 +934,11 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
934934
// no matter if the workspace is shared or not, you cannot create a new instance
935935
await this.guardAccess({ kind: "workspaceInstance", subject: undefined, workspace }, "create");
936936

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

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

14281424
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)