Skip to content

Commit

Permalink
Run experiment with default viewlet shown/hidden (fixes #12414)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmarti committed Sep 21, 2016
1 parent f279a63 commit 12d000e
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 8 deletions.
30 changes: 29 additions & 1 deletion src/vs/platform/telemetry/common/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import {TPromise} from 'vs/base/common/winjs.base';
import {createDecorator} from 'vs/platform/instantiation/common/instantiation';
import {IStorageService} from 'vs/platform/storage/common/storage';

export const ITelemetryService = createDecorator<ITelemetryService>('telemetryService');

Expand All @@ -15,6 +16,10 @@ export interface ITelemetryInfo {
instanceId: string;
}

export interface ITelemetryExperiments {
showDefaultViewlet: boolean;
}

export interface ITelemetryService {

_serviceBrand: any;
Expand All @@ -28,10 +33,17 @@ export interface ITelemetryService {
getTelemetryInfo(): TPromise<ITelemetryInfo>;

isOptedIn: boolean;

getExperiments(): ITelemetryExperiments;
}

export const NullTelemetryService: ITelemetryService = {
export const defaultExperiments: ITelemetryExperiments = {
showDefaultViewlet: false
};

export const NullTelemetryService = {
_serviceBrand: undefined,
_experiments: defaultExperiments,
publicLog(eventName: string, data?: any) {
return TPromise.as<void>(null);
},
Expand All @@ -42,9 +54,25 @@ export const NullTelemetryService: ITelemetryService = {
sessionId: 'someValue.sessionId',
machineId: 'someValue.machineId'
});
},
getExperiments(): ITelemetryExperiments {
return this._experiments;
}
};

export function loadExperiments(storageService: IStorageService): ITelemetryExperiments {
const key = 'experiments.randomness';
let valueString = storageService.get(key);
if (!valueString) {
valueString = Math.random().toString();
storageService.store(key, valueString);
}
const value = parseFloat(valueString);
return {
showDefaultViewlet: value < 0.5
};
}

export interface ITelemetryAppender {
log(eventName: string, data: any): void;
}
Expand Down
9 changes: 8 additions & 1 deletion src/vs/platform/telemetry/common/telemetryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import {localize} from 'vs/nls';
import {escapeRegExpCharacters} from 'vs/base/common/strings';
import {ITelemetryService, ITelemetryAppender, ITelemetryInfo} from 'vs/platform/telemetry/common/telemetry';
import {ITelemetryService, ITelemetryAppender, ITelemetryInfo, ITelemetryExperiments, defaultExperiments} from 'vs/platform/telemetry/common/telemetry';
import {optional} from 'vs/platform/instantiation/common/instantiation';
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';
import {IConfigurationRegistry, Extensions} from 'vs/platform/configuration/common/configurationRegistry';
Expand All @@ -21,6 +21,7 @@ export interface ITelemetryServiceConfig {
commonProperties?: TPromise<{ [name: string]: any }>;
piiPaths?: string[];
userOptIn?: boolean;
experiments?: ITelemetryExperiments;
}

export class TelemetryService implements ITelemetryService {
Expand All @@ -34,6 +35,7 @@ export class TelemetryService implements ITelemetryService {
private _commonProperties: TPromise<{ [name: string]: any; }>;
private _piiPaths: string[];
private _userOptIn: boolean;
private _experiments: ITelemetryExperiments;

private _disposables: IDisposable[] = [];
private _cleanupPatterns: [RegExp, string][] = [];
Expand All @@ -46,6 +48,7 @@ export class TelemetryService implements ITelemetryService {
this._commonProperties = config.commonProperties || TPromise.as({});
this._piiPaths = config.piiPaths || [];
this._userOptIn = typeof config.userOptIn === 'undefined' ? true : config.userOptIn;
this._experiments = config.experiments || defaultExperiments;

// static cleanup patterns for:
// #1 `file:///DANGEROUS/PATH/resources/app/Useful/Information`
Expand Down Expand Up @@ -76,6 +79,10 @@ export class TelemetryService implements ITelemetryService {
return this._userOptIn;
}

getExperiments(): ITelemetryExperiments {
return this._experiments;
}

getTelemetryInfo(): TPromise<ITelemetryInfo> {
return this._commonProperties.then(values => {
// well known properties
Expand Down
6 changes: 5 additions & 1 deletion src/vs/workbench/api/node/extHostTelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import {notImplemented} from 'vs/base/common/errors';
import {TPromise} from 'vs/base/common/winjs.base';
import {ITelemetryService, ITelemetryInfo} from 'vs/platform/telemetry/common/telemetry';
import {ITelemetryService, ITelemetryInfo, ITelemetryExperiments} from 'vs/platform/telemetry/common/telemetry';
import {IThreadService} from 'vs/workbench/services/thread/common/threadService';
import {MainContext, MainThreadTelemetryShape} from './extHost.protocol';

Expand All @@ -26,6 +26,10 @@ export class RemoteTelemetryService implements ITelemetryService {
throw notImplemented();
}

getExperiments(): ITelemetryExperiments {
throw notImplemented();
}

getTelemetryInfo(): TPromise<ITelemetryInfo> {
return this._proxy.$getTelemetryInfo();
}
Expand Down
9 changes: 6 additions & 3 deletions src/vs/workbench/electron-browser/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {ContextViewService} from 'vs/platform/contextview/browser/contextViewSer
import timer = require('vs/base/common/timer');
import {Workbench} from 'vs/workbench/electron-browser/workbench';
import {Storage, inMemoryLocalStorageInstance} from 'vs/workbench/common/storage';
import {ITelemetryService, NullTelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {ITelemetryService, NullTelemetryService, loadExperiments} from 'vs/platform/telemetry/common/telemetry';
import {ITelemetryAppenderChannel, TelemetryAppenderClient} from 'vs/platform/telemetry/common/telemetryIpc';
import {TelemetryService, ITelemetryServiceConfig} from 'vs/platform/telemetry/common/telemetryService';
import {IdleMonitor, UserStatus} from 'vs/platform/telemetry/browser/idleMonitor';
Expand Down Expand Up @@ -197,7 +197,8 @@ export class WorkbenchShell {
emptyWorkbench: !this.contextService.getWorkspace(),
customKeybindingsCount,
theme: this.themeService.getColorTheme(),
language: platform.language
language: platform.language,
experiments: this.telemetryService.getExperiments()
});

const workspaceStats: WorkspaceStats = <WorkspaceStats>this.workbench.getInstantiationService().createInstance(WorkspaceStats);
Expand Down Expand Up @@ -249,7 +250,8 @@ export class WorkbenchShell {
const config: ITelemetryServiceConfig = {
appender: new TelemetryAppenderClient(channel),
commonProperties: resolveWorkbenchCommonProperties(this.storageService, commit, version),
piiPaths: [this.environmentService.appRoot, this.environmentService.extensionsPath]
piiPaths: [this.environmentService.appRoot, this.environmentService.extensionsPath],
experiments: loadExperiments(this.storageService)
};

const telemetryService = instantiationService.createInstance(TelemetryService, config);
Expand All @@ -266,6 +268,7 @@ export class WorkbenchShell {

disposables.add(telemetryService, errorTelemetry, listener, idleMonitor);
} else {
NullTelemetryService._experiments = loadExperiments(this.storageService);
this.telemetryService = NullTelemetryService;
}

Expand Down
4 changes: 3 additions & 1 deletion src/vs/workbench/electron-browser/workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import {IMenuService} from 'vs/platform/actions/common/actions';
import {MenuService} from 'vs/platform/actions/common/menuService';
import {IContextMenuService} from 'vs/platform/contextview/browser/contextView';
import {IEnvironmentService} from 'vs/platform/environment/common/environment';
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';

export const MessagesVisibleContext = new RawContextKey<boolean>('globalMessageVisible', false);
export const EditorsVisibleContext = new RawContextKey<boolean>('editorIsOpen', false);
Expand Down Expand Up @@ -154,6 +155,7 @@ export class Workbench implements IPartService {
@ILifecycleService private lifecycleService: ILifecycleService,
@IMessageService private messageService: IMessageService,
@IThreadService private threadService: IThreadService,
@ITelemetryService private telemetryService: ITelemetryService,
@IEnvironmentService private environmentService: IEnvironmentService
) {
this.container = container;
Expand Down Expand Up @@ -418,7 +420,7 @@ export class Workbench implements IPartService {
// Sidebar visibility
this.sideBarHidden = this.storageService.getBoolean(Workbench.sidebarHiddenSettingKey, StorageScope.WORKSPACE, false);
if (!this.contextService.getWorkspace()) {
this.sideBarHidden = true; // we hide sidebar in single-file-mode
this.sideBarHidden = !this.telemetryService.getExperiments().showDefaultViewlet;
}

const viewletRegistry = (<ViewletRegistry>Registry.as(ViewletExtensions.Viewlets));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {WorkspaceContextService, IWorkspaceContextService} from 'vs/platform/wor
import {createSyncDescriptor} from 'vs/platform/instantiation/common/descriptors';
import {IEditorGroupService} from 'vs/workbench/services/group/common/groupService';
import {ISearchService} from 'vs/platform/search/common/search';
import {ITelemetryService, ITelemetryInfo} from 'vs/platform/telemetry/common/telemetry';
import {ITelemetryService, ITelemetryInfo, ITelemetryExperiments, defaultExperiments} from 'vs/platform/telemetry/common/telemetry';
import {IUntitledEditorService, UntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import * as minimist from 'minimist';
Expand Down Expand Up @@ -156,4 +156,8 @@ class TestTelemetryService implements ITelemetryService {
machineId: 'someValue.machineId'
});
}

public getExperiments(): ITelemetryExperiments {
return defaultExperiments;
}
};

0 comments on commit 12d000e

Please sign in to comment.