From 13efa5826fdfefeac1998ce4a0486d74449c8d31 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Sun, 17 Jan 2021 13:26:01 +0100 Subject: [PATCH] telemetry - fix layer breakers --- .../parts/sandbox/electron-browser/preload.js | 1 + .../parts/sandbox/electron-sandbox/globals.ts | 6 ++++++ .../sharedProcess/sharedProcessMain.ts | 2 +- src/vs/code/electron-main/app.ts | 2 +- src/vs/code/node/cliProcessMain.ts | 2 +- .../telemetry/common/commonProperties.ts | 21 +++++++++++-------- .../electron-browser/telemetryService.ts | 3 ++- .../workbenchCommonProperties.ts | 3 ++- .../electron-browser/commonProperties.test.ts | 8 +++---- 9 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/vs/base/parts/sandbox/electron-browser/preload.js b/src/vs/base/parts/sandbox/electron-browser/preload.js index a56dc129c85..11984805df6 100644 --- a/src/vs/base/parts/sandbox/electron-browser/preload.js +++ b/src/vs/base/parts/sandbox/electron-browser/preload.js @@ -125,6 +125,7 @@ */ process: { get platform() { return process.platform; }, + get arch() { return process.arch; }, get env() { return process.env; }, get versions() { return process.versions; }, get type() { return 'renderer'; }, diff --git a/src/vs/base/parts/sandbox/electron-sandbox/globals.ts b/src/vs/base/parts/sandbox/electron-sandbox/globals.ts index c548c2045ea..36fda091beb 100644 --- a/src/vs/base/parts/sandbox/electron-sandbox/globals.ts +++ b/src/vs/base/parts/sandbox/electron-sandbox/globals.ts @@ -14,6 +14,12 @@ export interface ISandboxNodeProcess extends INodeProcess { */ readonly platform: 'win32' | 'linux' | 'darwin'; + /** + * The process.arch property returns a string identifying the CPU architecture + * on which the Node.js process is running. + */ + readonly arch: string; + /** * The type will always be Electron renderer. */ diff --git a/src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts b/src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts index 52621f0de03..345404e4499 100644 --- a/src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts +++ b/src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts @@ -214,7 +214,7 @@ class SharedProcessMain extends Disposable { telemetryService = new TelemetryService({ appender: telemetryAppender, - commonProperties: resolveCommonProperties(fileService, release(), product.commit, product.version, this.configuration.machineId, product.msftInternalDomains, installSourcePath), + commonProperties: resolveCommonProperties(fileService, release(), process.arch, product.commit, product.version, this.configuration.machineId, product.msftInternalDomains, installSourcePath), sendErrorTelemetry: true, piiPaths: [appRoot, extensionsPath] }, configurationService); diff --git a/src/vs/code/electron-main/app.ts b/src/vs/code/electron-main/app.ts index 25e51cf711f..6a893ef49d3 100644 --- a/src/vs/code/electron-main/app.ts +++ b/src/vs/code/electron-main/app.ts @@ -537,7 +537,7 @@ export class CodeApplication extends Disposable { if (!this.environmentService.isExtensionDevelopment && !this.environmentService.args['disable-telemetry'] && !!product.enableTelemetry) { const channel = getDelayedChannel(sharedProcessReady.then(client => client.getChannel('telemetryAppender'))); const appender = new TelemetryAppenderClient(channel); - const commonProperties = resolveCommonProperties(this.fileService, release(), product.commit, product.version, machineId, product.msftInternalDomains, this.environmentService.installSourcePath); + const commonProperties = resolveCommonProperties(this.fileService, release(), process.arch, product.commit, product.version, machineId, product.msftInternalDomains, this.environmentService.installSourcePath); const piiPaths = [this.environmentService.appRoot, this.environmentService.extensionsPath]; const config: ITelemetryServiceConfig = { appender, commonProperties, piiPaths, sendErrorTelemetry: true }; diff --git a/src/vs/code/node/cliProcessMain.ts b/src/vs/code/node/cliProcessMain.ts index 2830e7d458f..6fbc68199d0 100644 --- a/src/vs/code/node/cliProcessMain.ts +++ b/src/vs/code/node/cliProcessMain.ts @@ -425,7 +425,7 @@ export async function main(argv: NativeParsedArgs): Promise { const config: ITelemetryServiceConfig = { appender: combinedAppender(...appenders), sendErrorTelemetry: false, - commonProperties: resolveCommonProperties(fileService, release(), product.commit, product.version, stateService.getItem('telemetry.machineId'), product.msftInternalDomains, installSourcePath), + commonProperties: resolveCommonProperties(fileService, release(), process.arch, product.commit, product.version, stateService.getItem('telemetry.machineId'), product.msftInternalDomains, installSourcePath), piiPaths: [appRoot, extensionsPath] }; diff --git a/src/vs/platform/telemetry/common/commonProperties.ts b/src/vs/platform/telemetry/common/commonProperties.ts index 9680c205afd..46f08b5d3ce 100644 --- a/src/vs/platform/telemetry/common/commonProperties.ts +++ b/src/vs/platform/telemetry/common/commonProperties.ts @@ -4,13 +4,15 @@ *--------------------------------------------------------------------------------------------*/ import { IFileService } from 'vs/platform/files/common/files'; -import * as Platform from 'vs/base/common/platform'; -import * as uuid from 'vs/base/common/uuid'; +import { isLinuxSnap, PlatformToString, platform } from 'vs/base/common/platform'; +import { platform as nodePlatform, env } from 'vs/base/common/process'; +import { generateUuid } from 'vs/base/common/uuid'; import { URI } from 'vs/base/common/uri'; export async function resolveCommonProperties( fileService: IFileService, release: string, + arch: string, commit: string | undefined, version: string | undefined, machineId: string | undefined, @@ -23,7 +25,7 @@ export async function resolveCommonProperties( // __GDPR__COMMON__ "common.machineId" : { "endPoint": "MacAddressHash", "classification": "EndUserPseudonymizedInformation", "purpose": "FeatureInsight" } result['common.machineId'] = machineId; // __GDPR__COMMON__ "sessionID" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" } - result['sessionID'] = uuid.generateUuid() + Date.now(); + result['sessionID'] = generateUuid() + Date.now(); // __GDPR__COMMON__ "commitHash" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" } result['commitHash'] = commit; // __GDPR__COMMON__ "version" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" } @@ -31,11 +33,11 @@ export async function resolveCommonProperties( // __GDPR__COMMON__ "common.platformVersion" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" } result['common.platformVersion'] = (release || '').replace(/^(\d+)(\.\d+)?(\.\d+)?(.*)/, '$1$2$3'); // __GDPR__COMMON__ "common.platform" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" } - result['common.platform'] = Platform.PlatformToString(Platform.platform); + result['common.platform'] = PlatformToString(platform); // __GDPR__COMMON__ "common.nodePlatform" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" } - result['common.nodePlatform'] = process.platform; + result['common.nodePlatform'] = nodePlatform; // __GDPR__COMMON__ "common.nodeArch" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" } - result['common.nodeArch'] = process.arch; + result['common.nodeArch'] = arch; // __GDPR__COMMON__ "common.product" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" } result['common.product'] = product || 'desktop'; @@ -66,7 +68,7 @@ export async function resolveCommonProperties( } }); - if (Platform.isLinuxSnap) { + if (isLinuxSnap) { // __GDPR__COMMON__ "common.snap" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" } result['common.snap'] = 'true'; } @@ -84,10 +86,11 @@ export async function resolveCommonProperties( } function verifyMicrosoftInternalDomain(domainList: readonly string[]): boolean { - if (!process || !process.env || !process.env['USERDNSDOMAIN']) { + const userDnsDomain = env['USERDNSDOMAIN']; + if (!userDnsDomain) { return false; } - const domain = process.env['USERDNSDOMAIN']!.toLowerCase(); + const domain = userDnsDomain.toLowerCase(); return domainList.some(msftDomain => domain === msftDomain); } diff --git a/src/vs/workbench/services/telemetry/electron-browser/telemetryService.ts b/src/vs/workbench/services/telemetry/electron-browser/telemetryService.ts index 40ca288cfe6..d7d7122a6bb 100644 --- a/src/vs/workbench/services/telemetry/electron-browser/telemetryService.ts +++ b/src/vs/workbench/services/telemetry/electron-browser/telemetryService.ts @@ -3,6 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import { process } from 'vs/base/parts/sandbox/electron-sandbox/globals'; import { ITelemetryService, ITelemetryInfo, ITelemetryData } from 'vs/platform/telemetry/common/telemetry'; import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; @@ -39,7 +40,7 @@ export class TelemetryService extends Disposable implements ITelemetryService { const channel = sharedProcessService.getChannel('telemetryAppender'); const config: ITelemetryServiceConfig = { appender: new TelemetryAppenderClient(channel), - commonProperties: resolveWorkbenchCommonProperties(storageService, fileService, environmentService.os.release, productService.commit, productService.version, environmentService.machineId, productService.msftInternalDomains, environmentService.installSourcePath, environmentService.remoteAuthority), + commonProperties: resolveWorkbenchCommonProperties(storageService, fileService, environmentService.os.release, process.arch, productService.commit, productService.version, environmentService.machineId, productService.msftInternalDomains, environmentService.installSourcePath, environmentService.remoteAuthority), piiPaths: [environmentService.appRoot, environmentService.extensionsPath], sendErrorTelemetry: true }; diff --git a/src/vs/workbench/services/telemetry/electron-sandbox/workbenchCommonProperties.ts b/src/vs/workbench/services/telemetry/electron-sandbox/workbenchCommonProperties.ts index 6f0321bfa6e..e7aa4bbafa0 100644 --- a/src/vs/workbench/services/telemetry/electron-sandbox/workbenchCommonProperties.ts +++ b/src/vs/workbench/services/telemetry/electron-sandbox/workbenchCommonProperties.ts @@ -14,6 +14,7 @@ export async function resolveWorkbenchCommonProperties( storageService: IStorageService, fileService: IFileService, release: string, + arch: string, commit: string | undefined, version: string | undefined, machineId: string, @@ -21,7 +22,7 @@ export async function resolveWorkbenchCommonProperties( installSourcePath: string, remoteAuthority?: string ): Promise<{ [name: string]: string | boolean | undefined }> { - const result = await resolveCommonProperties(fileService, release, commit, version, machineId, msftInternalDomains, installSourcePath, undefined); + const result = await resolveCommonProperties(fileService, release, arch, commit, version, machineId, msftInternalDomains, installSourcePath, undefined); const instanceId = storageService.get(instanceStorageKey, StorageScope.GLOBAL)!; const firstSessionDate = storageService.get(firstSessionDateStorageKey, StorageScope.GLOBAL)!; const lastSessionDate = storageService.get(lastSessionDateStorageKey, StorageScope.GLOBAL)!; diff --git a/src/vs/workbench/services/telemetry/test/electron-browser/commonProperties.test.ts b/src/vs/workbench/services/telemetry/test/electron-browser/commonProperties.test.ts index 627abe2546f..4af075eb1fa 100644 --- a/src/vs/workbench/services/telemetry/test/electron-browser/commonProperties.test.ts +++ b/src/vs/workbench/services/telemetry/test/electron-browser/commonProperties.test.ts @@ -45,7 +45,7 @@ suite('Telemetry - common properties', function () { test('default', async function () { await mkdirp(parentDir); fs.writeFileSync(installSource, 'my.install.source'); - const props = await resolveWorkbenchCommonProperties(testStorageService, testFileService, os.release(), commit, version, 'someMachineId', undefined, installSource); + const props = await resolveWorkbenchCommonProperties(testStorageService, testFileService, os.release(), process.arch, commit, version, 'someMachineId', undefined, installSource); assert.ok('commitHash' in props); assert.ok('sessionID' in props); assert.ok('timestamp' in props); @@ -66,7 +66,7 @@ suite('Telemetry - common properties', function () { assert.ok('common.instanceId' in props, 'instanceId'); assert.ok('common.machineId' in props, 'machineId'); fs.unlinkSync(installSource); - const props_1 = await resolveWorkbenchCommonProperties(testStorageService, testFileService, os.release(), commit, version, 'someMachineId', undefined, installSource); + const props_1 = await resolveWorkbenchCommonProperties(testStorageService, testFileService, os.release(), process.arch, commit, version, 'someMachineId', undefined, installSource); assert.ok(!('common.source' in props_1)); }); @@ -74,14 +74,14 @@ suite('Telemetry - common properties', function () { testStorageService.store('telemetry.lastSessionDate', new Date().toUTCString(), StorageScope.GLOBAL, StorageTarget.MACHINE); - const props = await resolveWorkbenchCommonProperties(testStorageService, testFileService, os.release(), commit, version, 'someMachineId', undefined, installSource); + const props = await resolveWorkbenchCommonProperties(testStorageService, testFileService, os.release(), process.arch, commit, version, 'someMachineId', undefined, installSource); assert.ok('common.lastSessionDate' in props); // conditional, see below assert.ok('common.isNewSession' in props); assert.equal(props['common.isNewSession'], 0); }); test('values chance on ask', async function () { - const props = await resolveWorkbenchCommonProperties(testStorageService, testFileService, os.release(), commit, version, 'someMachineId', undefined, installSource); + const props = await resolveWorkbenchCommonProperties(testStorageService, testFileService, os.release(), process.arch, commit, version, 'someMachineId', undefined, installSource); let value1 = props['common.sequence']; let value2 = props['common.sequence']; assert.ok(value1 !== value2, 'seq'); -- GitLab