Skip to content

Commit

Permalink
[supervisor-frontend] add error counter and client counter
Browse files Browse the repository at this point in the history
Co-authored-by: Huiwen <mhqnwt@gmail.com>
  • Loading branch information
iQQBot and mustard-mh committed Aug 5, 2022
1 parent 5bfb308 commit 28848d7
Show file tree
Hide file tree
Showing 8 changed files with 3,928 additions and 3,541 deletions.
17 changes: 17 additions & 0 deletions components/gitpod-protocol/src/util/gitpod-host-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,21 @@ export class GitpodHostUrl {
asApiLogout(): GitpodHostUrl {
return this.withApi((url) => ({ pathname: "/logout/" }));
}

asIDEProxy(): GitpodHostUrl {
const hostSegments = this.url.host.split(".");
if (hostSegments[0] === "ide") {
return this;
}
return this.with((url) => ({ host: "ide." + url.host }));
}

asIDEMetrics(): GitpodHostUrl {
let newUrl: GitpodHostUrl = this;
const hostSegments = this.url.host.split(".");
if (hostSegments[0] !== "ide") {
newUrl = newUrl.asIDEProxy();
}
return newUrl.with((url) => ({ pathname: "/metrics-api" }));
}
}
1 change: 1 addition & 0 deletions components/supervisor/frontend/BUILD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ packages:
deps:
- components/gitpod-protocol:lib
- components/supervisor-api/typescript-grpc:lib
- components/ide-metrics-api/typescript-grpcweb:lib
config:
dontTest: true
yarnLock: ${coreYarnLockBase}/../yarn.lock
3 changes: 2 additions & 1 deletion components/supervisor/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"version": "0.0.0",
"dependencies": {
"@gitpod/gitpod-protocol": "0.1.5",
"@gitpod/supervisor-api-grpc": "0.1.5"
"@gitpod/supervisor-api-grpc": "0.1.5",
"@gitpod/ide-metrics-api-grpcweb": "0.0.1"
},
"devDependencies": {
"@babel/core": "^7.10.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* 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 { MetricsServicePromiseClient } from '@gitpod/ide-metrics-api-grpcweb/lib/idemetrics_grpc_web_pb'
import { AddCounterRequest, AddCounterResponse } from '@gitpod/ide-metrics-api-grpcweb/lib/idemetrics_pb'
import { serverUrl } from '../shared/urls';

const client = new MetricsServicePromiseClient(serverUrl.asIDEMetrics().toString())

export enum MetricsName {
SupervisorFrontendClientTotal = "gitpod_supervisor_frontend_client_total",
SupervisorFrontendErrorTotal = "gitpod_supervisor_frontend_error_total"
}

export class IDEMetricsServiceClient {

static async addCounter(metricsName: string, labels?: Map<string, string>, value?: number) : Promise<AddCounterResponse> {
const req = new AddCounterRequest()
req.setName(metricsName)
if (value) {
req.setValue(value)
}
if (labels) {
const m = req.getLabelsMap()
for (const [name, value] of labels) {
m.set(name, value)
}
}
return client.addCounter(req)
}
}
6 changes: 5 additions & 1 deletion components/supervisor/frontend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
* <script type="text/javascript" src="/_supervisor/frontend/main.js" charset="utf-8"></script> should be inserted to index.html as first body script,
* all other IDE scripts should go afterwards, head element should not have scripts
*/

import { IDEMetricsServiceClient, MetricsName } from "./ide/ide-metrics-service-client";
IDEMetricsServiceClient.addCounter(MetricsName.SupervisorFrontendClientTotal).catch(() => {})
window.addEventListener('error', () => {
IDEMetricsServiceClient.addCounter(MetricsName.SupervisorFrontendErrorTotal).catch(() => {})
})
require('../src/shared/index.css');

import { createGitpodService, WorkspaceInstancePhase } from "@gitpod/gitpod-protocol";
Expand Down
Loading

0 comments on commit 28848d7

Please sign in to comment.