Skip to content

Commit d61aab3

Browse files
iQQBotmustard-mh
authored andcommitted
[supervisor-frontend] add error counter and client counter
Co-authored-by: Huiwen <[email protected]>
1 parent 4efa175 commit d61aab3

File tree

9 files changed

+727
-24
lines changed

9 files changed

+727
-24
lines changed

components/gitpod-protocol/src/util/gitpod-host-url.ts

+17
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,21 @@ export class GitpodHostUrl {
175175
asApiLogout(): GitpodHostUrl {
176176
return this.withApi((url) => ({ pathname: "/logout/" }));
177177
}
178+
179+
asIDEProxy(): GitpodHostUrl {
180+
const hostSegments = this.url.host.split(".");
181+
if (hostSegments[0] === "ide") {
182+
return this;
183+
}
184+
return this.with((url) => ({ host: "ide." + url.host }));
185+
}
186+
187+
asIDEMetrics(): GitpodHostUrl {
188+
let newUrl: GitpodHostUrl = this;
189+
const hostSegments = this.url.host.split(".");
190+
if (hostSegments[0] !== "ide") {
191+
newUrl = newUrl.asIDEProxy();
192+
}
193+
return newUrl.with((url) => ({ pathname: "/metrics-api" }));
194+
}
178195
}

components/supervisor/frontend/BUILD.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ packages:
1010
deps:
1111
- components/gitpod-protocol:lib
1212
- components/supervisor-api/typescript-grpc:lib
13+
- components/ide-metrics-api/typescript-grpcweb:lib
1314
config:
1415
dontTest: true
1516
yarnLock: ${coreYarnLockBase}/../yarn.lock

components/supervisor/frontend/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"version": "0.0.0",
66
"dependencies": {
77
"@gitpod/gitpod-protocol": "0.1.5",
8-
"@gitpod/supervisor-api-grpc": "0.1.5"
8+
"@gitpod/supervisor-api-grpc": "0.1.5",
9+
"@gitpod/ide-metrics-api-grpcweb": "0.0.1"
910
},
1011
"devDependencies": {
1112
"@babel/core": "^7.10.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License-AGPL.txt in the project root for license information.
5+
*/
6+
7+
import { MetricsServicePromiseClient } from '@gitpod/ide-metrics-api-grpcweb/lib/idemetrics_grpc_web_pb'
8+
import { AddCounterRequest, AddCounterResponse } from '@gitpod/ide-metrics-api-grpcweb/lib/idemetrics_pb'
9+
import { serverUrl } from '../shared/urls';
10+
11+
const client = new MetricsServicePromiseClient(serverUrl.asIDEMetrics().toString())
12+
13+
export enum MetricsName {
14+
SupervisorFrontendClientTotal = "gitpod_supervisor_frontend_client_total",
15+
SupervisorFrontendErrorTotal = "gitpod_supervisor_frontend_error_total"
16+
}
17+
18+
export class IDEMetricsServiceClient {
19+
20+
static async addCounter(metricsName: string, labels?: Map<string, string>, value?: number) : Promise<AddCounterResponse> {
21+
const req = new AddCounterRequest()
22+
req.setName(metricsName)
23+
if (value) {
24+
req.setValue(value)
25+
}
26+
if (labels) {
27+
const m = req.getLabelsMap()
28+
for (const [name, value] of labels) {
29+
m.set(name, value)
30+
}
31+
}
32+
return client.addCounter(req)
33+
}
34+
}

components/supervisor/frontend/src/index.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
* <script type="text/javascript" src="/_supervisor/frontend/main.js" charset="utf-8"></script> should be inserted to index.html as first body script,
99
* all other IDE scripts should go afterwards, head element should not have scripts
1010
*/
11-
11+
import { IDEMetricsServiceClient, MetricsName } from "./ide/ide-metrics-service-client";
12+
IDEMetricsServiceClient.addCounter(MetricsName.SupervisorFrontendClientTotal).catch(() => {})
13+
window.addEventListener('error', () => {
14+
IDEMetricsServiceClient.addCounter(MetricsName.SupervisorFrontendErrorTotal).catch(() => {})
15+
})
1216
require('../src/shared/index.css');
1317

1418
import { createGitpodService, WorkspaceInstancePhase } from "@gitpod/gitpod-protocol";

0 commit comments

Comments
 (0)