forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for VS Code's experiment service (#11979)
* Add npm package * News entry * experiments.ts -> experiments/manager.ts * Wrong issue number * eexperimentGroups -> experiments/experimentGroups * Move experiments.unit.tests.ts -> experiments/ * Commit new files * Merge gone sideways * Add types * Add opt in/out handling * Activation (service registry) * Don't pin tas-client to one version * Unit tests + fixes * Lol forgot to remove a comment + add headers * Forgot 'use strict' in service.ts * Use IApplicationEnvironment instead of IExtensions * Apply suggestions from code review Co-authored-by: Don Jayamanne <don.jayamanne@yahoo.com> * Remove unnecessary formatted props * n e v e r m i n d * Aight fixed it * flight -> experiment * Check stub calls instead of ctor impl * removed getExperimentService stub check * Set shared properties for all telemetry events * Add test for shared properties Co-authored-by: Don Jayamanne <don.jayamanne@yahoo.com>
- Loading branch information
1 parent
5cef0d9
commit c821c9e
Showing
13 changed files
with
565 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Integrate VS Code experiment framework in the extension. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// 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 { IApplicationEnvironment } from '../application/types'; | ||
import { GLOBAL_MEMENTO, IConfigurationService, IExperimentService, IMemento, IPythonSettings } from '../types'; | ||
import { ExperimentationTelemetry } from './telemetry'; | ||
|
||
export class ExperimentService implements IExperimentService { | ||
/** | ||
* 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 readonly settings: IPythonSettings; | ||
|
||
constructor( | ||
@inject(IConfigurationService) readonly configurationService: IConfigurationService, | ||
@inject(IApplicationEnvironment) private readonly appEnvironment: IApplicationEnvironment, | ||
@inject(IMemento) @named(GLOBAL_MEMENTO) readonly globalState: Memento | ||
) { | ||
this.settings = configurationService.getSettings(undefined); | ||
|
||
// 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; | ||
} | ||
|
||
let targetPopulation: TargetPopulation; | ||
|
||
if (this.appEnvironment.channel === 'insiders') { | ||
targetPopulation = TargetPopulation.Insiders; | ||
} else { | ||
targetPopulation = TargetPopulation.Public; | ||
} | ||
|
||
const telemetryReporter = new ExperimentationTelemetry(); | ||
|
||
this.experimentationService = getExperimentationService( | ||
this.appEnvironment.extensionName, | ||
this.appEnvironment.packageJson.version!, | ||
targetPopulation, | ||
telemetryReporter, | ||
globalState | ||
); | ||
} | ||
|
||
public async inExperiment(experiment: string): Promise<boolean> { | ||
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(experiment)) { | ||
sendTelemetryEvent(EventName.PYTHON_EXPERIMENTS_OPT_IN_OUT, undefined, { | ||
expNameOptedOutOf: experiment | ||
}); | ||
|
||
return false; | ||
} | ||
|
||
if (this._optInto.includes('All') || this._optInto.includes(experiment)) { | ||
sendTelemetryEvent(EventName.PYTHON_EXPERIMENTS_OPT_IN_OUT, undefined, { | ||
expNameOptedInto: experiment | ||
}); | ||
|
||
return true; | ||
} | ||
|
||
return this.experimentationService.isCachedFlightEnabled(experiment); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
'use strict'; | ||
|
||
import { IExperimentationTelemetry } from 'vscode-tas-client'; | ||
import { sendTelemetryEvent, setSharedProperty } from '../../telemetry'; | ||
|
||
export class ExperimentationTelemetry implements IExperimentationTelemetry { | ||
public setSharedProperty(name: string, value: string): void { | ||
// Add the shared property to all telemetry being sent, not just events being sent by the experimentation package. | ||
setSharedProperty(name, value); | ||
} | ||
|
||
public postEvent(eventName: string, properties: Map<string, string>): void { | ||
const formattedProperties: { [key: string]: string } = {}; | ||
properties.forEach((value, key) => { | ||
formattedProperties[key] = value; | ||
}); | ||
|
||
// tslint:disable-next-line: no-any | ||
sendTelemetryEvent(eventName as any, undefined, formattedProperties); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.