Skip to content

[inner loop poc] debug workspace window #15490

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
Jan 9, 2023
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
2 changes: 1 addition & 1 deletion WORKSPACE.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defaultArgs:
publishToNPM: true
publishToJBMarketplace: true
localAppVersion: unknown
codeCommit: 05e928f3d900f8b27574d846d46d2ca4a10c2ffd
codeCommit: 8ee664e58e31e81e9dd9da10fb31809e249f0d61
codeVersion: 1.75.0
codeQuality: stable
noVerifyJBPlugin: false
Expand Down
2 changes: 1 addition & 1 deletion components/gitpod-cli/pkg/supervisor/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type SupervisorClientOption struct {
Address string
}

func New(ctx context.Context, options ...SupervisorClientOption) (*SupervisorClient, error) {
func New(ctx context.Context, options ...*SupervisorClientOption) (*SupervisorClient, error) {
address := util.GetSupervisorAddress()
for _, option := range options {
if option.Address != "" {
Expand Down
10 changes: 7 additions & 3 deletions components/gitpod-protocol/src/util/gitpod-host-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ const baseWorkspaceIDRegex =
"(([a-f][0-9a-f]{7}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})|([0-9a-z]{2,16}-[0-9a-z]{2,16}-[0-9a-z]{8,11}))";

// this pattern matches v4 UUIDs as well as the new generated workspace ids (e.g. pink-panda-ns35kd21)
const workspaceIDRegex = RegExp(`^${baseWorkspaceIDRegex}$`);
const workspaceIDRegex = RegExp(`^(?:debug-)?${baseWorkspaceIDRegex}$`);
Copy link
Member Author

Choose a reason for hiding this comment

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

@geropl Could someone have a look please? 🙏

it is rather only this change for webapp. It does not really affect anythin besides supervisor frontend as far as I aware.

Debug workspaces are started within a regular workspace, not via Gitpod itself.

Copy link
Member

Choose a reason for hiding this comment

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

Debug workspaces are started within a regular workspace, not via Gitpod itself.

That would be an excellent doc comment on the debugWorkspace property below.


// this pattern matches URL prefixes of workspaces
const workspaceUrlPrefixRegex = RegExp(`^([0-9]{4,6}-)?${baseWorkspaceIDRegex}\\.`);
const workspaceUrlPrefixRegex = RegExp(`^(([0-9]{4,6}|debug)-)?${baseWorkspaceIDRegex}\\.`);

export namespace StartOptions {
export const WORKSPACE_CLASS = "workspaceClass";
Expand Down Expand Up @@ -174,14 +174,18 @@ export class GitpodHostUrl {
return result;
}

get debugWorkspace(): boolean {
return this.url.host.match(workspaceUrlPrefixRegex)?.[2] === "debug";
}

get workspaceId(): string | undefined {
const hostSegs = this.url.host.split(".");
if (hostSegs.length > 1) {
const matchResults = hostSegs[0].match(workspaceIDRegex);
if (matchResults) {
// URL has a workspace prefix
// port prefixes are excluded
return matchResults[0];
return matchResults[1];
}
}

Expand Down
3 changes: 3 additions & 0 deletions components/ide/code/leeway.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ RUN yarn --cwd extensions compile \
# Check pkg/blobserve/blobserve.go, `inlineVars` method
RUN cp /vscode-web/out/vs/gitpod/browser/workbench/workbench.html /vscode-web/index.html \
&& cp /vscode-web/out/vs/gitpod/browser/workbench/callback.html /vscode-web/callback.html \
# TODO: remove next line when workbench.html changes are merged to gp-code/main
&& sed -i -e 's#static/##g' /vscode-web/index.html \
&& sed -i -e 's#baseUrl =.*;#baseUrl = window.location.origin;#g' /vscode-web/index.html \
&& sed -i -e 's#{{WORKBENCH_WEB_BASE_URL}}#.#g' /vscode-web/index.html \
&& sed -i -e "s/{{VERSION}}/$CODE_QUALITY-$CODE_COMMIT/g" /vscode-web/index.html

# cli config: alises to gitpod-code
Expand Down
12 changes: 12 additions & 0 deletions components/proxy/conf/Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,18 @@ https://*.*.{$GITPOD_DOMAIN} {
}
}

# experimental debug workspace route
@debug_workspace header_regexp host Host ^debug-(?P<workspaceID>[a-z0-9][0-9a-z\-]+).ws(?P<location>-[a-z0-9]+)?.{$GITPOD_DOMAIN}
handle @debug_workspace {
reverse_proxy https://ws-proxy.{$KUBE_NAMESPACE}.{$KUBE_DOMAIN}:9090 {
import workspace_transport
import upstream_headers

header_up X-Gitpod-WorkspaceId {re.host.workspaceID}
header_up X-WSProxy-Host {http.request.host}
}
}

@workspace header_regexp host Host ^(?P<workspaceID>[a-z0-9][0-9a-z\-]+).ws(?P<location>-[a-z0-9]+)?.{$GITPOD_DOMAIN}
handle @workspace {
reverse_proxy https://ws-proxy.{$KUBE_NAMESPACE}.{$KUBE_DOMAIN}:9090 {
Expand Down
2 changes: 1 addition & 1 deletion components/supervisor/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var runCmd = &cobra.Command{
Short: "starts the supervisor",

Run: func(cmd *cobra.Command, args []string) {
log.Init(ServiceName, Version, true, os.Getenv("SUPERVISOR_DEBUG_ENABLE") == "true")
log.Init(ServiceName, Version, !runOpts.RunGP, os.Getenv("SUPERVISOR_DEBUG_ENABLE") == "true")
common_grpc.SetupLogging()
supervisor.Version = Version
supervisor.Run(supervisor.WithRunGP(runOpts.RunGP))
Expand Down
33 changes: 33 additions & 0 deletions components/supervisor/frontend/src/debug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License.AGPL.txt in the project root for license information.
*/

import { DisposableCollection } from "@gitpod/gitpod-protocol/lib/util/disposable";
import * as IDEFrontendService from "./ide/ide-frontend-service-impl";
import * as IDEWorker from "./ide/ide-worker";
import * as IDEWebSocket from "./ide/ide-web-socket";
import { SupervisorServiceClient } from "./ide/supervisor-service-client";

Object.assign(window, { gitpod: {} });
IDEWorker.install();
IDEWebSocket.install();
IDEWebSocket.connectWorkspace();
const ideService = IDEFrontendService.create();
const loadingIDE = new Promise((resolve) => window.addEventListener("DOMContentLoaded", resolve, { once: true }));
const toStop = new DisposableCollection();

(async () => {
const supervisorServiceClient = SupervisorServiceClient.get(Promise.resolve());
const [ideStatus] = await Promise.all([
supervisorServiceClient.ideReady,
supervisorServiceClient.contentReady,
loadingIDE,
]);
// TODO(desktop support)
// const isDesktopIde = ideStatus && ideStatus.desktop && ideStatus.desktop.link;
// if (!isDesktopIde) {
toStop.push(ideService.start());
// }
})();
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ interface ReportErrorParam {
properties?: Record<string, string>;
}
export class IDEMetricsServiceClient {
static workspaceId? = workspaceUrl.workspaceId;
static workspaceId = workspaceUrl.workspaceId;
static debugWorkspace = workspaceUrl.debugWorkspace;
static gitpodServiceClient?: GitpodServiceClient;

static get instanceId(): string {
Expand Down Expand Up @@ -70,6 +71,7 @@ export class IDEMetricsServiceClient {
const p = Object.assign({}, properties);
p.error_name = error.name;
p.error_message = error.message;
p.debug_workspace = String(this.debugWorkspace);

const url = `${MetricsUrl}/reportError`;
const params: ReportErrorParam = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,18 @@ import { GitpodHostUrl } from "@gitpod/gitpod-protocol/lib/util/gitpod-host-url"

export class SupervisorServiceClient {
private static _instance: SupervisorServiceClient | undefined;
static get(gitpodServiceClient: GitpodServiceClient): SupervisorServiceClient {
static get(gitpodAuth: Promise<void>): SupervisorServiceClient {
if (!SupervisorServiceClient._instance) {
SupervisorServiceClient._instance = new SupervisorServiceClient(gitpodServiceClient);
SupervisorServiceClient._instance = new SupervisorServiceClient(gitpodAuth);
}
return SupervisorServiceClient._instance;
}

readonly supervisorReady = this.checkReady("supervisor");
readonly ideReady = this.supervisorReady.then(() => this.checkReady("ide"));
readonly contentReady = Promise.all([this.supervisorReady, this.gitpodServiceClient.auth]).then(() =>
this.checkReady("content"),
);
readonly contentReady = Promise.all([this.supervisorReady, this.gitpodAuth]).then(() => this.checkReady("content"));

private constructor(private readonly gitpodServiceClient: GitpodServiceClient) {}
private constructor(private readonly gitpodAuth: Promise<void>) {}

private async checkReady(kind: "content" | "ide" | "supervisor", delay?: boolean): Promise<any> {
if (delay) {
Expand Down
Loading