Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add distro info to telemetry on linux #185261

Merged
merged 1 commit into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
"electron",
"events",
"fs",
"fs/promises",
"graceful-fs",
"http",
"https",
Expand All @@ -244,6 +245,7 @@
"os",
"path",
"perf_hooks",
"readline",
"stream",
"string_decoder",
"tas-client-umd",
Expand Down
73 changes: 73 additions & 0 deletions src/vs/base/node/osReleaseInfo.ts
Original file line number Diff line number Diff line change
@@ -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;
}
27 changes: 26 additions & 1 deletion src/vs/server/node/remoteExtensionHostAgentServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 = {
Expand All @@ -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']) {
Expand Down