Skip to content
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

Listen on instance updates of a running prebuild #10646

Merged
merged 1 commit into from
Jun 15, 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
28 changes: 28 additions & 0 deletions components/server/ee/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,34 @@ export class GitpodServerEEImpl extends GitpodServerImpl {

return;
}

// (AT) At this point we found a running/building prebuild, which might also include
// image build in current state.
//
// The owner's client connection is automatically registered to listen on instance updates.
// For the remaining client connections which would handle `createWorkspace` and end up here, it
// also would be reasonable to listen on the instance updates of a running prebuild, or image build.
Copy link
Member

@geropl geropl Jun 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Would love to see these additional lines as comment:

We need to be forwarded the WorkspaceInstanceUpdates in the frontend, because we do not have any other means to reliably learn about the status about image builds, yet. Once we have those, we should remove this.

//
// We need to be forwarded the WorkspaceInstanceUpdates in the frontend, because we do not have
// any other means to reliably learn about the status about image builds, yet.
// Once we have those, we should remove this.
//
const ws = await this.workspaceDb.trace(ctx).findById(workspaceID);
if (!!ws && !!wsi && ws.ownerId !== this.user?.id) {
const resetListener = this.localMessageBroker.listenForWorkspaceInstanceUpdates(
ws.ownerId,
(ctx, instance) => {
if (instance.id === wsi.id) {
this.forwardInstanceUpdateToClient(ctx, instance);
if (instance.status.phase === "stopped") {
resetListener.dispose();
}
}
},
);
this.disposables.push(resetListener);
}

const result = makeResult(wsi.id);

const inSameCluster = wsi.region === this.config.installationShortname;
Expand Down
24 changes: 14 additions & 10 deletions components/server/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,20 +276,24 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
// to clients who might not otherwise have access to that information.
this.disposables.push(
this.localMessageBroker.listenForWorkspaceInstanceUpdates(this.user.id, (ctx, instance) =>
TraceContext.withSpan(
"forwardInstanceUpdateToClient",
(ctx) => {
traceClientMetadata(ctx, this.clientMetadata);
TraceContext.setJsonRPCMetadata(ctx, "onInstanceUpdate");

this.client?.onInstanceUpdate(this.censorInstance(instance));
},
ctx,
),
this.forwardInstanceUpdateToClient(ctx, instance),
geropl marked this conversation as resolved.
Show resolved Hide resolved
),
);
}

protected forwardInstanceUpdateToClient(ctx: TraceContext, instance: WorkspaceInstance) {
TraceContext.withSpan(
"forwardInstanceUpdateToClient",
(ctx) => {
traceClientMetadata(ctx, this.clientMetadata);
TraceContext.setJsonRPCMetadata(ctx, "onInstanceUpdate");

this.client?.onInstanceUpdate(this.censorInstance(instance));
},
ctx,
);
}

setClient(ctx: TraceContext, client: GitpodApiClient | undefined): void {
throw new Error("Unsupported operation. Use initialize.");
}
Expand Down