chore: add distro info to telemetry on linux (#185261)

This commit is contained in:
Robo 2023-06-16 21:55:59 +09:00 committed by GitHub
parent e2470cf410
commit 10cf7f040a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 101 additions and 1 deletions

View file

@ -233,6 +233,7 @@
"electron",
"events",
"fs",
"fs/promises",
"graceful-fs",
"http",
"https",
@ -244,6 +245,7 @@
"os",
"path",
"perf_hooks",
"readline",
"stream",
"string_decoder",
"tas-client-umd",

View file

@ -0,0 +1,73 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { constants as FSConstants } from 'fs';
import { open, FileHandle } from 'fs/promises';
import { createInterface as readLines } from 'readline';
import * as Platform from 'vs/base/common/platform';
type ReleaseInfo = {
id: string;
id_like?: string;
version_id?: string;
};
export async function getOSReleaseInfo(errorLogger: (error: any) => void): Promise<ReleaseInfo | undefined> {
if (Platform.isMacintosh || Platform.isWindows) {
return;
}
// Extract release information on linux based systems
// using the identifiers specified in
// https://www.freedesktop.org/software/systemd/man/os-release.html
let handle: FileHandle | undefined;
for (const filePath of ['/etc/os-release', '/usr/lib/os-release', '/etc/lsb-release']) {
try {
handle = await open(filePath, FSConstants.R_OK);
break;
} catch (err) { }
}
if (!handle) {
errorLogger('Unable to retrieve release information from known identifier paths.');
return;
}
try {
const osReleaseKeys = new Set([
'ID',
'DISTRIB_ID',
'ID_LIKE',
'VERSION_ID',
'DISTRIB_RELEASE',
]);
const releaseInfo: ReleaseInfo = {
id: 'unknown'
};
for await (const line of readLines({ input: handle.createReadStream(), crlfDelay: Infinity })) {
if (!line.includes('=')) {
continue;
}
const key = line.split('=')[0].toUpperCase().trim();
if (osReleaseKeys.has(key)) {
const value = line.split('=')[1].replace(/"/g, '').toLowerCase().trim();
if (key === 'ID' || key === 'DISTRIB_ID') {
releaseInfo.id = value;
} else if (key === 'ID_LIKE') {
releaseInfo.id_like = value;
} else if (key === 'VERSION_ID' || key === 'DISTRIB_RELEASE') {
releaseInfo.version_id = value;
}
}
}
return releaseInfo;
} catch (err) {
errorLogger(err);
}
return;
}

View file

@ -22,6 +22,7 @@ import * as platform from 'vs/base/common/platform';
import { createRegExp, escapeRegExpCharacters } from 'vs/base/common/strings';
import { URI } from 'vs/base/common/uri';
import { generateUuid } from 'vs/base/common/uuid';
import { getOSReleaseInfo } from 'vs/base/node/osReleaseInfo';
import { findFreePort } from 'vs/base/node/ports';
import { addUNCHostToAllowlist, disableUNCAccessRestrictions } from 'vs/base/node/unc';
import { PersistentProtocol } from 'vs/base/parts/ipc/common/ipc.net';
@ -788,7 +789,7 @@ export async function createServer(address: string | net.AddressInfo | null, arg
const vscodeServerListenTime: number = (<any>global).vscodeServerListenTime;
const vscodeServerCodeLoadedTime: number = (<any>global).vscodeServerCodeLoadedTime;
instantiationService.invokeFunction((accessor) => {
instantiationService.invokeFunction(async (accessor) => {
const telemetryService = accessor.get(ITelemetryService);
type ServerStartClassification = {
@ -811,6 +812,30 @@ export async function createServer(address: string | net.AddressInfo | null, arg
codeLoadedTime: vscodeServerCodeLoadedTime,
readyTime: currentTime
});
if (platform.isLinux) {
const logService = accessor.get(ILogService);
const releaseInfo = await getOSReleaseInfo(logService.error.bind(logService));
if (releaseInfo) {
type ServerPlatformInfoClassification = {
platformId: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'A string identifying the operating system without any version information.' };
platformVersionId: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'A string identifying the operating system version excluding any name information or release code.' };
platformIdLike: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'A string identifying the operating system the current OS derivate is closely related to.' };
owner: 'deepak1556';
comment: 'Provides insight into the distro information on Linux.';
};
type ServerPlatformInfoEvent = {
platformId: string;
platformVersionId: string | undefined;
platformIdLike: string | undefined;
};
telemetryService.publicLog2<ServerPlatformInfoEvent, ServerPlatformInfoClassification>('serverPlatformInfo', {
platformId: releaseInfo.id,
platformVersionId: releaseInfo.version_id,
platformIdLike: releaseInfo.id_like
});
}
}
});
if (args['print-startup-performance']) {