From e94e00899b2690a5a5b7a53734ac8f6afe95b70a Mon Sep 17 00:00:00 2001 From: Christof Marti Date: Mon, 26 Sep 2016 15:22:38 -0700 Subject: [PATCH] #12534: Enable overrides for testing --- src/vs/platform/telemetry/common/telemetry.ts | 18 +++++++++++++++--- src/vs/workbench/electron-browser/shell.ts | 4 ++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/vs/platform/telemetry/common/telemetry.ts b/src/vs/platform/telemetry/common/telemetry.ts index 67799a3d7d0..aa1d17fc293 100644 --- a/src/vs/platform/telemetry/common/telemetry.ts +++ b/src/vs/platform/telemetry/common/telemetry.ts @@ -5,6 +5,7 @@ 'use strict'; import {TPromise} from 'vs/base/common/winjs.base'; +import {IConfigurationService} from 'vs/platform/configuration/common/configuration'; import {createDecorator} from 'vs/platform/instantiation/common/instantiation'; import {IStorageService} from 'vs/platform/storage/common/storage'; @@ -64,7 +65,7 @@ export const NullTelemetryService = { } }; -export function loadExperiments(storageService: IStorageService): ITelemetryExperiments { +export function loadExperiments(storageService: IStorageService, configurationService: IConfigurationService): ITelemetryExperiments { const key = 'experiments.randomness'; let valueString = storageService.get(key); if (!valueString) { @@ -75,11 +76,22 @@ export function loadExperiments(storageService: IStorageService): ITelemetryExpe const [random1, showDefaultViewlet] = splitRandom(random0); const [random2, showCommandsWatermark] = splitRandom(random1); const [, openUntitledFile] = splitRandom(random2); - return { + return applyOverrides(configurationService, { showDefaultViewlet, showCommandsWatermark, openUntitledFile - }; + }); +} + +export function applyOverrides(configurationService: IConfigurationService, experiments: ITelemetryExperiments): ITelemetryExperiments { + const config: any = configurationService.getConfiguration('telemetry'); + const experimentsConfig = config && config.experiments || {}; + Object.keys(experiments).forEach(key => { + if (key in experimentsConfig) { + experiments[key] = experimentsConfig[key]; + } + }); + return experiments; } function splitRandom(random: number): [number, boolean] { diff --git a/src/vs/workbench/electron-browser/shell.ts b/src/vs/workbench/electron-browser/shell.ts index 125819187f5..43efe25608d 100644 --- a/src/vs/workbench/electron-browser/shell.ts +++ b/src/vs/workbench/electron-browser/shell.ts @@ -257,7 +257,7 @@ export class WorkbenchShell { appender: new TelemetryAppenderClient(channel), commonProperties: resolveWorkbenchCommonProperties(this.storageService, commit, version), piiPaths: [this.environmentService.appRoot, this.environmentService.extensionsPath], - experiments: loadExperiments(this.storageService) + experiments: loadExperiments(this.storageService, this.configurationService) }; const telemetryService = instantiationService.createInstance(TelemetryService, config); @@ -274,7 +274,7 @@ export class WorkbenchShell { disposables.add(telemetryService, errorTelemetry, listener, idleMonitor); } else { - NullTelemetryService._experiments = loadExperiments(this.storageService); + NullTelemetryService._experiments = loadExperiments(this.storageService, this.configurationService); this.telemetryService = NullTelemetryService; } -- GitLab