Skip to content

Commit

Permalink
Collect telemetry on connection outcomes (#60773)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmarti committed Jan 28, 2019
1 parent 0fc0db3 commit 43c36fb
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"vscode-chokidar": "1.6.5",
"vscode-debugprotocol": "1.33.0",
"vscode-nsfw": "1.1.1",
"vscode-proxy-agent": "0.2.0",
"vscode-proxy-agent": "0.3.0",
"vscode-ripgrep": "^1.2.5",
"vscode-sqlite3": "4.0.7",
"vscode-textmate": "^4.0.1",
Expand Down
43 changes: 40 additions & 3 deletions src/vs/workbench/services/extensions/node/proxyResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ import { toErrorMessage } from 'vs/base/common/errorMessage';
import { ExtHostExtensionService } from 'vs/workbench/api/node/extHostExtensionService';
import { URI } from 'vs/base/common/uri';

interface ConnectionResult {
proxy: string;
connection: string;
code: string;
count: number;
}

export function connectProxyResolver(
extHostWorkspace: ExtHostWorkspace,
configProvider: ExtHostConfigProvider,
Expand Down Expand Up @@ -83,6 +90,7 @@ function createProxyAgents(
let envCount = 0;
let settingsCount = 0;
let localhostCount = 0;
let results: ConnectionResult[] = [];
function logEvent() {
timeout = undefined;
/* __GDPR__
Expand All @@ -95,14 +103,16 @@ function createProxyAgents(
"cacheRolls": { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth", "isMeasurement": true },
"envCount": { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth", "isMeasurement": true },
"settingsCount": { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth", "isMeasurement": true },
"localhostCount": { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth", "isMeasurement": true }
"localhostCount": { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth", "isMeasurement": true },
"results": { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }
}
*/
mainThreadTelemetry.$publicLog('resolveProxy', { count, duration, errorCount, cacheCount, cacheSize: cache.size, cacheRolls, envCount, settingsCount, localhostCount });
mainThreadTelemetry.$publicLog('resolveProxy', { count, duration, errorCount, cacheCount, cacheSize: cache.size, cacheRolls, envCount, settingsCount, localhostCount, results });
count = duration = errorCount = cacheCount = envCount = settingsCount = localhostCount = 0;
results = [];
}

function resolveProxy(url: string, callback: (proxy?: string) => void) {
function resolveProxy(req: http.ClientRequest, opts: http.RequestOptions, url: string, callback: (proxy?: string) => void) {
if (!timeout) {
timeout = setTimeout(logEvent, 10 * 60 * 1000);
}
Expand Down Expand Up @@ -135,6 +145,7 @@ function createProxyAgents(
const proxy = getCachedProxy(key);
if (proxy) {
cacheCount++;
collectResult(results, proxy, parsedUrl.protocol === 'https:' ? 'HTTPS' : 'HTTP', req);
callback(proxy);
extHostLogService.trace('ProxyResolver#resolveProxy cached', url, proxy);
return;
Expand All @@ -144,6 +155,7 @@ function createProxyAgents(
extHostWorkspace.resolveProxy(url) // Use full URL to ensure it is an actually used one.
.then(proxy => {
cacheProxy(key, proxy);
collectResult(results, proxy, parsedUrl.protocol === 'https:' ? 'HTTPS' : 'HTTP', req);
callback(proxy);
extHostLogService.debug('ProxyResolver#resolveProxy', url, proxy);
}).then(() => {
Expand All @@ -163,6 +175,31 @@ function createProxyAgents(
return { http: httpAgent, https: httpsAgent };
}

function collectResult(results: ConnectionResult[], resolveProxy: string, connection: string, req: http.ClientRequest) {
const proxy = resolveProxy ? String(resolveProxy).trim().split(/\s+/, 1)[0] : 'EMPTY';
req.on('response', res => {
const code = `HTTP_${res.statusCode}`;
const result = findOrCreateResult(results, proxy, connection, code);
result.count++;
});
req.on('error', err => {
const code = err && typeof (<any>err).code === 'string' && (<any>err).code || 'UNKNOWN_ERROR';
const result = findOrCreateResult(results, proxy, connection, code);
result.count++;
});
}

function findOrCreateResult(results: ConnectionResult[], proxy: string, connection: string, code: string): ConnectionResult | undefined {
for (const result of results) {
if (result.proxy === proxy && result.connection === connection && result.code === code) {
return result;
}
}
const result = { proxy, connection, code, count: 0 };
results.push(result);
return result;
}

function proxyFromConfigURL(configURL: string) {
const url = (configURL || '').trim();
const i = url.indexOf('://');
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9399,10 +9399,10 @@ vscode-nsfw@1.1.1:
lodash.isundefined "^3.0.1"
nan "^2.10.0"

vscode-proxy-agent@0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/vscode-proxy-agent/-/vscode-proxy-agent-0.2.0.tgz#5ae6e1f8e1b8715a4058fafb6d10cd2409d72620"
integrity sha512-x6RUOUkV18iM78+6S70VjiwiHuY7qmk3CU9+u+0y4c1Y/X8/IcTJfPsngoAXrrojoKcplyLdp3YCZbj1rFNo/Q==
vscode-proxy-agent@0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/vscode-proxy-agent/-/vscode-proxy-agent-0.3.0.tgz#b5c8bea5046761966e1fa71f89d9cef11c457894"
integrity sha512-R6qz8Sc0ocNfeFPOp3k6QLP/Y8HzK1yqXwfgB1f0GakVzUGMDmniRe8RLxIiCAqlxGaWMn2yqpTSNUYZ1obPsQ==
dependencies:
debug "3.1.0"
http-proxy-agent "2.1.0"
Expand Down

0 comments on commit 43c36fb

Please sign in to comment.