Skip to content

Commit a5b622f

Browse files
committed
Add telemetry for resolving proxies
1 parent ff388f3 commit a5b622f

1 file changed

Lines changed: 70 additions & 1 deletion

File tree

src/vs/workbench/api/node/proxyResolver.ts

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ export function connectProxyResolver(
4444
const fallbackToLocalKerberos = useHostProxyDefault;
4545
const loadLocalCertificates = useHostProxyDefault;
4646
const isUseHostProxyEnabled = () => !isRemote || configProvider.getConfiguration('http').get<boolean>('useLocalProxyConfiguration', useHostProxyDefault);
47+
const timedResolveProxy = createTimedResolveProxy(extHostWorkspace, mainThreadTelemetry);
4748
const params: ProxyAgentParams = {
48-
resolveProxy: url => extHostWorkspace.resolveProxy(url),
49+
resolveProxy: timedResolveProxy,
4950
lookupProxyAuthorization: lookupProxyAuthorization.bind(undefined, extHostWorkspace, extHostLogService, mainThreadTelemetry, configProvider, {}, {}, initData.remote.isRemote, fallbackToLocalKerberos),
5051
getProxyURL: () => getExtHostConfigValue<string>(configProvider, isRemote, 'http.proxy'),
5152
getProxySupport: () => getExtHostConfigValue<ProxySupportSetting>(configProvider, isRemote, 'http.proxySupport') || 'off',
@@ -240,6 +241,74 @@ function recordFetchFeatureUse(mainThreadTelemetry: MainThreadTelemetryShape, fe
240241
}
241242
}
242243

244+
type ProxyResolveStatsClassification = {
245+
owner: 'chrmarti';
246+
comment: 'Performance statistics for proxy resolution';
247+
count: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'Number of proxy resolution calls' };
248+
totalDuration: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'Total time spent in proxy resolution (ms)' };
249+
minDuration: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'Minimum resolution time (ms)' };
250+
maxDuration: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'Maximum resolution time (ms)' };
251+
avgDuration: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'Average resolution time (ms)' };
252+
};
253+
254+
type ProxyResolveStatsEvent = {
255+
count: number;
256+
totalDuration: number;
257+
minDuration: number;
258+
maxDuration: number;
259+
avgDuration: number;
260+
};
261+
262+
const proxyResolveStats = {
263+
count: 0,
264+
totalDuration: 0,
265+
minDuration: Number.MAX_SAFE_INTEGER,
266+
maxDuration: 0,
267+
lastSentTime: 0,
268+
};
269+
270+
const telemetryInterval = 60 * 60 * 1000; // 1 hour
271+
272+
function sendProxyResolveStats(mainThreadTelemetry: MainThreadTelemetryShape) {
273+
if (proxyResolveStats.count > 0) {
274+
const avgDuration = proxyResolveStats.totalDuration / proxyResolveStats.count;
275+
mainThreadTelemetry.$publicLog2<ProxyResolveStatsEvent, ProxyResolveStatsClassification>('proxyResolveStats', {
276+
count: proxyResolveStats.count,
277+
totalDuration: proxyResolveStats.totalDuration,
278+
minDuration: proxyResolveStats.minDuration,
279+
maxDuration: proxyResolveStats.maxDuration,
280+
avgDuration,
281+
});
282+
// Reset stats after sending
283+
proxyResolveStats.count = 0;
284+
proxyResolveStats.totalDuration = 0;
285+
proxyResolveStats.minDuration = Number.MAX_SAFE_INTEGER;
286+
proxyResolveStats.maxDuration = 0;
287+
}
288+
proxyResolveStats.lastSentTime = Date.now();
289+
}
290+
291+
function createTimedResolveProxy(extHostWorkspace: IExtHostWorkspaceProvider, mainThreadTelemetry: MainThreadTelemetryShape) {
292+
return async (url: string): Promise<string | undefined> => {
293+
const startTime = performance.now();
294+
try {
295+
return await extHostWorkspace.resolveProxy(url);
296+
} finally {
297+
const duration = performance.now() - startTime;
298+
proxyResolveStats.count++;
299+
proxyResolveStats.totalDuration += duration;
300+
proxyResolveStats.minDuration = Math.min(proxyResolveStats.minDuration, duration);
301+
proxyResolveStats.maxDuration = Math.max(proxyResolveStats.maxDuration, duration);
302+
303+
// Send telemetry if at least an hour has passed since last send
304+
const now = Date.now();
305+
if (now - proxyResolveStats.lastSentTime >= telemetryInterval) {
306+
sendProxyResolveStats(mainThreadTelemetry);
307+
}
308+
}
309+
};
310+
}
311+
243312
function createPatchedModules(params: ProxyAgentParams, resolveProxy: ResolveProxyWithRequest) {
244313

245314
function mergeModules(module: any, patch: any) {

0 commit comments

Comments
 (0)