Skip to content

Commit 151ab80

Browse files
mustard-mhjeanp413
authored andcommitted
[supervisor-frontend] implement frontend dashboard client
Co-authored-by: mustard <[email protected]> Co-authored-by: Jean Pierre <[email protected]>
1 parent eacf71e commit 151ab80

File tree

9 files changed

+293
-406
lines changed

9 files changed

+293
-406
lines changed

components/gitpod-protocol/src/typings/globals.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
interface Window {
88
// gitpod is used by supervisor/frontend and vscode browser https://github.com/gitpod-io/openvscode-server/blob/dadd40deda5959c0efdaa0c7d02ab64b6f8b5ad0/src/vs/gitpod/browser/workbench/workbench.ts#L7
99
gitpod: {
10-
service: import("../gitpod-service").GitpodService;
1110
ideService?: import("../ide-frontend-service").IDEFrontendService;
1211
loggedUserID?: string;
1312
};

components/supervisor/frontend/src/debug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const loadingIDE = new Promise((resolve) => window.addEventListener("DOMContentL
1919
const toStop = new DisposableCollection();
2020

2121
(async () => {
22-
const supervisorServiceClient = SupervisorServiceClient.get(Promise.resolve());
22+
const supervisorServiceClient = SupervisorServiceClient.get();
2323
const [ideStatus] = await Promise.all([
2424
supervisorServiceClient.ideReady,
2525
supervisorServiceClient.contentReady,

components/supervisor/frontend/src/ide/gitpod-service-client.ts

Lines changed: 0 additions & 76 deletions
This file was deleted.

components/supervisor/frontend/src/ide/heart-beat.ts

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
*/
66

77
import { DisposableCollection, Disposable } from "@gitpod/gitpod-protocol/lib/util/disposable";
8-
import { WorkspaceInfo } from "@gitpod/gitpod-protocol";
9-
import { isSaaSServerGreaterThan, isSaaS } from "./gitpod-server-compatibility";
10-
import { serverUrl } from "../shared/urls";
8+
import { FrontendDashboardServiceClient } from "../shared/frontend-dashboard-service";
119

1210
let lastActivity = 0;
1311
const updateLastActivitiy = () => {
@@ -18,28 +16,19 @@ export const track = (w: Window) => {
1816
w.document.addEventListener("keydown", updateLastActivitiy, { capture: true });
1917
};
2018

21-
let pageCloseCompatibile: boolean = false;
22-
// TODO(ak) remove
23-
isSaaSServerGreaterThan("main.4124").then((r) => {
24-
pageCloseCompatibile = r;
25-
});
26-
2719
let toCancel: DisposableCollection | undefined;
28-
export function schedule(wsInfo: WorkspaceInfo, sessionId: string): void {
20+
export function schedule(frontendDashboardServiceClient: FrontendDashboardServiceClient): void {
2921
if (toCancel) {
3022
return;
3123
}
3224
toCancel = new DisposableCollection();
3325
const sendHeartBeat = async (wasClosed?: true) => {
3426
try {
35-
await window.gitpod.service.server.sendHeartBeat({ instanceId: wsInfo.latestInstance!.id, wasClosed });
27+
frontendDashboardServiceClient.activeHeartbeat(); // wasClosed
3628
if (wasClosed) {
37-
window.gitpod.service.server.trackEvent({
29+
frontendDashboardServiceClient.trackEvent({
3830
event: "ide_close_signal",
3931
properties: {
40-
workspaceId: wsInfo.workspace.id,
41-
instanceId: wsInfo.latestInstance!.id,
42-
sessionId,
4332
clientKind: "supervisor-frontend",
4433
},
4534
});
@@ -50,28 +39,6 @@ export function schedule(wsInfo: WorkspaceInfo, sessionId: string): void {
5039
};
5140
sendHeartBeat();
5241

53-
const beaconWorkspacePageClose = () => {
54-
const instanceId = wsInfo.latestInstance!.id;
55-
const data = { sessionId };
56-
const blob = new Blob([JSON.stringify(data)], { type: "application/json" });
57-
const url = serverUrl.withApi({ pathname: `/auth/workspacePageClose/${instanceId}` }).toString();
58-
navigator.sendBeacon(url, blob);
59-
};
60-
61-
const workspacePageCloseCompatible = () => {
62-
if (isSaaS && !pageCloseCompatibile) {
63-
sendHeartBeat(true);
64-
return;
65-
}
66-
beaconWorkspacePageClose();
67-
};
68-
69-
const unloadListener = () => {
70-
workspacePageCloseCompatible();
71-
};
72-
window.addEventListener("unload", unloadListener);
73-
toCancel.push(Disposable.create(() => window.removeEventListener("unload", unloadListener)));
74-
7542
let activityInterval = 30000;
7643
const intervalHandle = setInterval(() => {
7744
// add an additional random value between 5 and 15 seconds

components/supervisor/frontend/src/ide/ide-metrics-service-client.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* See License.AGPL.txt in the project root for license information.
55
*/
66

7+
import { FrontendDashboardServiceClient } from "../shared/frontend-dashboard-service";
78
import { serverUrl, workspaceUrl } from "../shared/urls";
8-
import { GitpodServiceClient } from "./gitpod-service-client";
99
const commit = require("../../config.json").commit;
1010

1111
export enum MetricsName {
@@ -31,15 +31,15 @@ interface ReportErrorParam {
3131
properties?: Record<string, string>;
3232
}
3333
export class IDEMetricsServiceClient {
34-
static workspaceId = workspaceUrl.workspaceId;
34+
static workspaceId? = workspaceUrl.workspaceId;
3535
static debugWorkspace = workspaceUrl.debugWorkspace;
36-
static gitpodServiceClient?: GitpodServiceClient;
36+
static serviceClient: FrontendDashboardServiceClient;
3737

3838
static get instanceId(): string {
39-
return this.gitpodServiceClient?.info.latestInstance?.id ?? "";
39+
return this.serviceClient.latestStatus?.instanceId ?? "";
4040
}
4141
static get userId(): string {
42-
return this.gitpodServiceClient?.user.id ?? "";
42+
return this.serviceClient.latestStatus?.loggedUserId ?? "";
4343
}
4444

4545
static async addCounter(
@@ -101,7 +101,7 @@ export class IDEMetricsServiceClient {
101101
}
102102
}
103103

104-
static loadWorkspaceInfo(gitpodServiceClient: GitpodServiceClient) {
105-
this.gitpodServiceClient = gitpodServiceClient;
104+
static loadWorkspaceInfo(serviceClient: FrontendDashboardServiceClient) {
105+
this.serviceClient = serviceClient;
106106
}
107107
}

components/supervisor/frontend/src/ide/supervisor-service-client.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,22 @@ import {
99
IDEStatusResponse,
1010
ContentStatusResponse,
1111
} from "@gitpod/supervisor-api-grpc/lib/status_pb";
12-
import { GitpodServiceClient } from "./gitpod-service-client";
1312
import { GitpodHostUrl } from "@gitpod/gitpod-protocol/lib/util/gitpod-host-url";
1413

1514
export class SupervisorServiceClient {
1615
private static _instance: SupervisorServiceClient | undefined;
17-
static get(gitpodAuth: Promise<void>): SupervisorServiceClient {
16+
static get(): SupervisorServiceClient {
1817
if (!SupervisorServiceClient._instance) {
19-
SupervisorServiceClient._instance = new SupervisorServiceClient(gitpodAuth);
18+
SupervisorServiceClient._instance = new SupervisorServiceClient();
2019
}
2120
return SupervisorServiceClient._instance;
2221
}
2322

2423
readonly supervisorReady = this.checkReady("supervisor");
2524
readonly ideReady = this.supervisorReady.then(() => this.checkReady("ide"));
26-
readonly contentReady = Promise.all([this.supervisorReady, this.gitpodAuth]).then(() => this.checkReady("content"));
25+
readonly contentReady = Promise.all([this.supervisorReady]).then(() => this.checkReady("content"));
2726

28-
private constructor(private readonly gitpodAuth: Promise<void>) {}
27+
private constructor() {}
2928

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

0 commit comments

Comments
 (0)