Skip to content

Commit e916bf2

Browse files
authored
[dashboard] improve metrics reporting (#18755)
* [dashboard] add session id to error reporting * [public-api] fix conversion to seconds * [public-api] don't try server-stream test if not authenticated
1 parent 1f1d840 commit e916bf2

File tree

4 files changed

+37
-20
lines changed

4 files changed

+37
-20
lines changed

components/dashboard/resolver.js

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,23 @@
33
* Licensed under the GNU Affero General Public License (AGPL).
44
* See License.AGPL.txt in the project root for license information.
55
*/
6+
7+
/*
8+
* Resolver allows to reconstruct stack traces from obfuscated stack traces for the dashboard.
9+
* Usage:
10+
* node resolver.js < obfuscated-stack-trace.txt
11+
*
12+
* OR
13+
*
14+
* node resolver.js <<EOF
15+
* obfuscated stack trace
16+
* EOF
17+
*/
18+
619
//@ts-check
7-
const path = require('path');
8-
const fetch = require('node-fetch').default;
9-
const { SourceMapConsumer } = require('source-map');
20+
const path = require("path");
21+
const fetch = require("node-fetch").default;
22+
const { SourceMapConsumer } = require("source-map");
1023

1124
const sourceMapCache = {};
1225

@@ -27,10 +40,10 @@ async function fetchSourceMap(jsUrl) {
2740
// Extract source map URL from the JS file
2841
const mapUrlMatch = jsContent.match(/\/\/#\s*sourceMappingURL=(.+)/);
2942
if (!mapUrlMatch) {
30-
throw new Error('Source map URL not found');
43+
throw new Error("Source map URL not found");
3144
}
3245

33-
const mapUrl = new URL(mapUrlMatch[1], jsUrl).href; // Resolve relative URL
46+
const mapUrl = new URL(mapUrlMatch[1], jsUrl).href; // Resolve relative URL
3447
const mapResponse = await fetch(mapUrl);
3548
const mapData = await mapResponse.json();
3649

@@ -40,7 +53,7 @@ async function fetchSourceMap(jsUrl) {
4053
return mapData;
4154
}
4255

43-
const BASE_PATH = '/workspace/gitpod/components';
56+
const BASE_PATH = "/workspace/gitpod/components";
4457

4558
async function resolveLine(line) {
4659
const jsUrl = extractJsUrlFromLine(line);
@@ -53,7 +66,7 @@ async function resolveLine(line) {
5366
return line;
5467
}
5568

56-
const functionName = matches[1] || '';
69+
const functionName = matches[1] || "";
5770
const lineNum = Number(matches[3]);
5871
const colNum = Number(matches[4]);
5972

@@ -69,18 +82,17 @@ async function resolveLine(line) {
6982
return line;
7083
}
7184

85+
let obfuscatedTrace = "";
7286

73-
let obfuscatedTrace = '';
74-
75-
process.stdin.on('data', function(data) {
87+
process.stdin.on("data", function (data) {
7688
obfuscatedTrace += data;
7789
});
7890

79-
process.stdin.on('end', async function() {
80-
const lines = obfuscatedTrace.split('\n');
91+
process.stdin.on("end", async function () {
92+
const lines = obfuscatedTrace.split("\n");
8193
const resolvedLines = await Promise.all(lines.map(resolveLine));
82-
const resolvedTrace = resolvedLines.join('\n');
83-
console.log('\nResolved Stack Trace:\n');
94+
const resolvedTrace = resolvedLines.join("\n");
95+
console.log("\nResolved Stack Trace:\n");
8496
console.log(resolvedTrace);
8597
});
8698

components/dashboard/src/service/metrics.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import { GitpodHostUrl } from "@gitpod/gitpod-protocol/lib/util/gitpod-host-url";
88
import { MetricsReporter } from "@gitpod/public-api/lib/metrics";
99
import { getExperimentsClient } from "../experiments/client";
10+
import { v4 } from "uuid";
1011

1112
const originalConsoleError = console.error;
1213

@@ -40,7 +41,9 @@ console.error = function (...args) {
4041
reportError(...args);
4142
};
4243

43-
let commonDetails = {};
44+
const commonDetails = {
45+
sessionId: v4(),
46+
};
4447
export function updateCommonErrorDetails(update: { [key: string]: string | undefined }) {
4548
Object.assign(commonDetails, update);
4649
}

components/dashboard/src/service/service.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,12 @@ function testPublicAPI(service: any): void {
116116

117117
// emulates server side streaming with public API
118118
while (true) {
119-
const isTest = await getExperimentsClient().getValueAsync("public_api_dummy_reliability_test", false, {
120-
user,
121-
gitpodHost: window.location.host,
122-
});
119+
const isTest =
120+
!!user &&
121+
(await getExperimentsClient().getValueAsync("public_api_dummy_reliability_test", false, {
122+
user,
123+
gitpodHost: window.location.host,
124+
}));
123125
if (isTest) {
124126
try {
125127
let previousCount = 0;

components/public-api/typescript/src/metrics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class PrometheusClientCallMetrics {
131131
const start = performance.now();
132132
return (endLabels) => {
133133
const delta = performance.now() - start;
134-
const value = delta / 1e9;
134+
const value = delta / 1000;
135135
this.handledSecondsHistogram.labels(Object.assign(startLabels, endLabels)).observe(value);
136136
return value;
137137
};

0 commit comments

Comments
 (0)