|
2 | 2 | <!DOCTYPE html>
|
3 | 3 | <html>
|
4 | 4 | <head>
|
| 5 | + <script> |
| 6 | + async function gitpodMetricsAddCounter(metricsName, labels, value) { |
| 7 | + function getMetricsUrl() { |
| 8 | + const gitpodHost = "{{GITPOD_HOST}}"; |
| 9 | + if (!gitpodHost) { |
| 10 | + return ''; |
| 11 | + } |
| 12 | + return `https://ide.${gitpodHost}/metrics-api`; |
| 13 | + } |
| 14 | + try { |
| 15 | + const metricsUrl = getMetricsUrl(); |
| 16 | + if (!metricsUrl) { |
| 17 | + return false; |
| 18 | + } |
| 19 | + const url = `${metricsUrl}/metrics/counter/add/${metricsName}`; |
| 20 | + const params = { value, labels }; |
| 21 | + const response = await fetch(url, { |
| 22 | + method: 'POST', |
| 23 | + body: JSON.stringify(params), |
| 24 | + credentials: 'omit', |
| 25 | + }); |
| 26 | + if (!response.ok) { |
| 27 | + const data = await response.json(); // { code: number; message: string; } |
| 28 | + console.error(`Cannot report metrics with addCounter: ${response.status} ${response.statusText}`, data); |
| 29 | + return false; |
| 30 | + } |
| 31 | + return true; |
| 32 | + } catch (err) { |
| 33 | + console.error('Cannot report metrics with addCounter, error:', err); |
| 34 | + return false; |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + // sum(rate(gitpod_vscode_web_load_total{status='failed'}[2m]))/sum(rate(gitpod_vscode_web_load_total{status='loading'}[2m])) |
| 39 | + const gitpodVSCodeWebLoadTotal = 'gitpod_vscode_web_load_total'; |
| 40 | + |
| 41 | + gitpodMetricsAddCounter(gitpodVSCodeWebLoadTotal, { status: 'loading' }); |
| 42 | + gitpodMetricsAddCounter('gitpod_supervisor_frontend_client_total'); |
| 43 | + |
| 44 | + let vscodeWebFailedToLoad = false; |
| 45 | + const onVsCodeWorkbenchError = (event) => { |
| 46 | + if (!vscodeWebFailedToLoad) { |
| 47 | + vscodeWebFailedToLoad = true; |
| 48 | + gitpodMetricsAddCounter(gitpodVSCodeWebLoadTotal, { status: 'failed' }); |
| 49 | + } |
| 50 | + |
| 51 | + // If the error is not an element loading error, we only increase the total error count |
| 52 | + if (typeof event?.target?.getAttribute !== 'function') { |
| 53 | + gitpodMetricsAddCounter('gitpod_supervisor_frontend_error_total'); |
| 54 | + return; |
| 55 | + } |
| 56 | + const labels = {}; |
| 57 | + |
| 58 | + // We take a look at the resource that was attempted to load |
| 59 | + const resourceSource = event.target.getAttribute('src') || event.target.getAttribute('href'); |
| 60 | + |
| 61 | + if (resourceSource) { |
| 62 | + if (resourceSource.match(new RegExp(/\/build\/ide\/code:.+\/__files__\//g))) { |
| 63 | + // TODO(ak) reconsider how to hide knowledge of VS Code from supervisor frontend, i.e instrument amd loader instead |
| 64 | + labels['resource'] = 'vscode-web-workbench'; |
| 65 | + } |
| 66 | + labels['error'] = 'LoadError'; |
| 67 | + } else { |
| 68 | + labels['error'] = 'Unknown'; |
| 69 | + } |
| 70 | + gitpodMetricsAddCounter('gitpod_supervisor_frontend_error_total', labels); |
| 71 | + }; |
| 72 | + |
| 73 | + window.addEventListener('error', onVsCodeWorkbenchError); |
| 74 | + </script> |
5 | 75 | <script>
|
6 | 76 | performance.mark('code/didStartRenderer')
|
7 | 77 | </script>
|
|
34 | 104 | </body>
|
35 | 105 |
|
36 | 106 | <!-- Startup (do not modify order of script tags!) -->
|
37 |
| - <script src="{{WORKBENCH_WEB_BASE_URL}}/out/vs/loader.js"></script> |
38 |
| - <script src="{{WORKBENCH_WEB_BASE_URL}}/out/vs/webPackagePaths.js"></script> |
| 107 | + <script src="{{WORKBENCH_WEB_BASE_URL}}/out/vs/loader.js" onerror="onVsCodeWorkbenchError(event)"></script> |
| 108 | + <script src="{{WORKBENCH_WEB_BASE_URL}}/out/vs/webPackagePaths.js" onerror="onVsCodeWorkbenchError(event)"></script> |
39 | 109 | <script>
|
40 | 110 | const baseUrl = new URL('{{WORKBENCH_WEB_BASE_URL}}', window.location.origin).toString();
|
41 | 111 | Object.keys(self.webPackagePaths).map(function (key, index) {
|
|
65 | 135 | performance.mark('code/willLoadWorkbenchMain');
|
66 | 136 | </script>
|
67 | 137 | <script>
|
68 |
| - require(['vs/gitpod/browser/workbench/workbench'], function() {}); |
| 138 | + require(['vs/gitpod/browser/workbench/workbench'], () => {}); |
69 | 139 | </script>
|
70 | 140 | </html>
|
0 commit comments