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

Add support for VS Code's experiment service #11979

Merged
merged 28 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6f19e0b
Add npm package
kimadeline May 25, 2020
bf7bd56
News entry
kimadeline May 25, 2020
b5bef69
experiments.ts -> experiments/manager.ts
kimadeline May 25, 2020
9502146
Wrong issue number
kimadeline May 25, 2020
b0683b9
eexperimentGroups -> experiments/experimentGroups
kimadeline May 25, 2020
3271dc7
Move experiments.unit.tests.ts -> experiments/
kimadeline May 25, 2020
e500572
Commit new files
kimadeline May 26, 2020
89e3935
Merge branch 'master' into 10008-exp-service
kimadeline May 26, 2020
3def3dd
Merge gone sideways
kimadeline May 26, 2020
821bada
Add types
kimadeline May 26, 2020
168c028
Add opt in/out handling
kimadeline May 27, 2020
cd37cba
Activation (service registry)
kimadeline May 27, 2020
7a37473
Don't pin tas-client to one version
kimadeline May 27, 2020
79f5a24
Unit tests + fixes
kimadeline May 27, 2020
622bc96
Merge branch 'master' into 10008-exp-service
kimadeline May 27, 2020
d9ca2ca
Lol forgot to remove a comment + add headers
kimadeline May 27, 2020
e73f68e
Forgot 'use strict' in service.ts
kimadeline May 27, 2020
c303506
Use IApplicationEnvironment instead of IExtensions
kimadeline May 28, 2020
9e75931
Merge branch 'master' into 10008-exp-service
kimadeline May 28, 2020
fbe5ff3
Apply suggestions from code review
kimadeline May 28, 2020
c0a2337
Remove unnecessary formatted props
kimadeline May 28, 2020
a9e1267
n e v e r m i n d
kimadeline May 28, 2020
cc1f165
Aight fixed it
kimadeline May 28, 2020
060c062
flight -> experiment
kimadeline May 28, 2020
fc29418
Check stub calls instead of ctor impl
kimadeline May 29, 2020
fd28d4b
removed getExperimentService stub check
kimadeline May 29, 2020
ccb8f67
Set shared properties for all telemetry events
kimadeline May 29, 2020
4b2d931
Add test for shared properties
kimadeline Jun 2, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/1 Enhancements/10790.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Integrate VS Code experiment framework in the extension.
47 changes: 47 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3055,6 +3055,7 @@
"vscode-languageclient": "^6.2.0-next.2",
"vscode-languageserver": "^6.2.0-next.2",
"vscode-languageserver-protocol": "^3.16.0-next.2",
"vscode-tas-client": "^0.0.757",
"vsls": "^0.3.1291",
"winreg": "^1.2.4",
"winston": "^3.2.1",
Expand Down
101 changes: 101 additions & 0 deletions src/client/common/experiments/service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';

import { inject, named } from 'inversify';
import { Memento } from 'vscode';
import { getExperimentationService, IExperimentationService, TargetPopulation } from 'vscode-tas-client';
import { sendTelemetryEvent } from '../../telemetry';
import { EventName } from '../../telemetry/constants';
import { PVSC_EXTENSION_ID } from '../constants';
import {
GLOBAL_MEMENTO,
IConfigurationService,
IExperimentService,
IExtensions,
IMemento,
IPythonSettings
} from '../types';
import { ExperimentationTelemetry } from './telemetry';

export class ExperimentService implements IExperimentService {
kimadeline marked this conversation as resolved.
Show resolved Hide resolved
/**
* Experiments the user requested to opt into manually.
*/
public _optInto: string[] = [];
/**
* Experiments the user requested to opt out from manually.
*/
public _optOutFrom: string[] = [];

private readonly experimentationService?: IExperimentationService;
private settings!: IPythonSettings;
kimadeline marked this conversation as resolved.
Show resolved Hide resolved

constructor(
@inject(IConfigurationService) readonly configurationService: IConfigurationService,
@inject(IExtensions) readonly extensions: IExtensions,
@inject(IMemento) @named(GLOBAL_MEMENTO) readonly globalState: Memento
) {
this.settings = configurationService.getSettings(undefined);
kimadeline marked this conversation as resolved.
Show resolved Hide resolved

// Users can only opt in or out of experiment groups, not control groups.
const optInto = this.settings.experiments.optInto;
const optOutFrom = this.settings.experiments.optOutFrom;
this._optInto = optInto.filter((exp) => !exp.endsWith('control'));
this._optOutFrom = optOutFrom.filter((exp) => !exp.endsWith('control'));

// Don't initialize the experiment service if the extension's experiments setting is disabled.
const enabled = this.settings.experiments.enabled;
if (!enabled) {
return;
}

const extension = extensions.getExtension(PVSC_EXTENSION_ID)!;
const version = extension.packageJSON.version!;

let targetPopulation: TargetPopulation;

if (/dev/gi.test(version)) {
kimadeline marked this conversation as resolved.
Show resolved Hide resolved
targetPopulation = TargetPopulation.Insiders;
} else {
targetPopulation = TargetPopulation.Public;
}

const telemetryReporter = new ExperimentationTelemetry();

this.experimentationService = getExperimentationService(
PVSC_EXTENSION_ID,
version,
targetPopulation,
telemetryReporter,
globalState
);
}

public async inExperiment(flight: string): Promise<boolean> {
kimadeline marked this conversation as resolved.
Show resolved Hide resolved
if (!this.experimentationService) {
return false;
}

// Currently the service doesn't support opting in and out of experiments,
// so we need to perform these checks and send the corresponding telemetry manually.
if (this._optOutFrom.includes('All') || this._optOutFrom.includes(flight)) {
sendTelemetryEvent(EventName.PYTHON_EXPERIMENTS_OPT_IN_OUT, undefined, {
expNameOptedOutOf: flight
});

return false;
}

if (this._optInto.includes('All') || this._optInto.includes(flight)) {
sendTelemetryEvent(EventName.PYTHON_EXPERIMENTS_OPT_IN_OUT, undefined, {
expNameOptedInto: flight
});

return true;
}

return this.experimentationService.isCachedFlightEnabled(flight);
}
}
30 changes: 30 additions & 0 deletions src/client/common/experiments/telemetry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';

import { IExperimentationTelemetry } from 'vscode-tas-client';
import { sendTelemetryEvent } from '../../telemetry';

export class ExperimentationTelemetry implements IExperimentationTelemetry {
kimadeline marked this conversation as resolved.
Show resolved Hide resolved
private readonly sharedProperties: { [key: string]: string } = {};
kimadeline marked this conversation as resolved.
Show resolved Hide resolved

public setSharedProperty(name: string, value: string): void {
kimadeline marked this conversation as resolved.
Show resolved Hide resolved
this.sharedProperties[name] = value;
}
kimadeline marked this conversation as resolved.
Show resolved Hide resolved

public postEvent(eventName: string, properties: Map<string, string>): void {
// Add shared properties to telemetry props (we may overwrite existing ones).
for (const [key, value] of Object.entries(this.sharedProperties)) {
properties.set(key, value);
}
kimadeline marked this conversation as resolved.
Show resolved Hide resolved

const formattedProperties: { [key: string]: string } = {};
properties.forEach((value, key) => {
formattedProperties[key] = value;
});

// tslint:disable-next-line: no-any
sendTelemetryEvent(eventName as any, undefined, formattedProperties);
kimadeline marked this conversation as resolved.
Show resolved Hide resolved
}
}
4 changes: 3 additions & 1 deletion src/client/common/serviceRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { IExtensionSingleActivationService } from '../activation/types';
import { IFileDownloader, IHttpClient, IInterpreterPathService } from '../common/types';
import { IExperimentService, IFileDownloader, IHttpClient, IInterpreterPathService } from '../common/types';
import { LiveShareApi } from '../datascience/liveshare/liveshare';
import { INotebookExecutionLogger } from '../datascience/types';
import { IServiceManager } from '../ioc/types';
Expand Down Expand Up @@ -42,6 +42,7 @@ import { ConfigurationService } from './configuration/service';
import { CryptoUtils } from './crypto';
import { EditorUtils } from './editor';
import { ExperimentsManager } from './experiments/manager';
import { ExperimentService } from './experiments/service';
import { FeatureDeprecationManager } from './featureDeprecationManager';
import {
ExtensionInsidersDailyChannelRule,
Expand Down Expand Up @@ -149,6 +150,7 @@ export function registerTypes(serviceManager: IServiceManager) {
serviceManager.addSingleton<ILiveShareApi>(ILiveShareApi, LiveShareApi);
serviceManager.addSingleton<ICryptoUtils>(ICryptoUtils, CryptoUtils);
serviceManager.addSingleton<IExperimentsManager>(IExperimentsManager, ExperimentsManager);
serviceManager.addSingleton<IExperimentService>(IExperimentService, ExperimentService);

serviceManager.addSingleton<ITerminalHelper>(ITerminalHelper, TerminalHelper);
serviceManager.addSingleton<ITerminalActivationCommandProvider>(
Expand Down
8 changes: 8 additions & 0 deletions src/client/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,14 @@ export interface IExperimentsManager {
sendTelemetryIfInExperiment(experimentName: string): void;
}

/**
* Experiment service leveraging VS Code's experiment framework.
*/
export const IExperimentService = Symbol('IExperimentService');
export interface IExperimentService {
inExperiment(experimentName: string): Promise<boolean>;
}

export type InterpreterConfigurationScope = { uri: Resource; configTarget: ConfigurationTarget };
export type InspectInterpreterSettingType = {
globalValue?: string;
Expand Down
Loading