Namespaces
Classes
- ContextualAttributesFactory
This class and supporting code is the same as
repos/data-engineering/metrics-platform/js/src/DefaultEventSubmitter.js.- EventFactory
- This class is used to create events for sending to the Event Platform.
- Experiment
- ExposureLogTracker
- Manages experiment exposure deduplication across two client-side tiers.
- Instrument
- InternalEventSender
Sends analytics events to the event intake service immediately using the Beacon API.
Interfaces
Methods
getAssignments() → {Object}static
#
Gets a map of experiment to group for all experiments that the current user is enrolled into.
This method is internal and should only be used by other Test Kitchen components. Currently, this method is only used by [the Client Error Logging instrument in WikimediaEvents][0].
Returns:
- Type
- Object
getExperiment(experimentName) → {Promise.<mw.testKitchen.ExperimentInterface>}static
#
Gets the details of an experiment.
This method returns a promise that will always resolve with an instance of
mw.testKitchen.ExperimentInterface that can:
- Get information about the user's (more precisely, the subject's) enrollment in the experiment
- Send analytics events relating to the experiment
Example
const myAwesomeDialog = require( 'my.awesome.dialog' );
mw.testKitchen.async.getExperiment( 'my-awesome-non-cache-splitting-experiment' )
.then( ( e ) => {
[
'open',
'default-action',
'primary-action'
].forEach( ( event ) => {
myAwesomeDialog.on( event, () => e.send( event ) );
} );
// Was the current user assigned to the treatment group?
if ( e.isAssignedGroup( 'treatment' ) ) {
myAwesomeDialog.primaryAction.label = 'Awesome!';
}
} );
Parameters:
| Name | Type | Description |
|---|---|---|
experimentName |
string | The experiment name |
Returns:
getExperimentsByPrefix(experimentNamePrefix) → {Promise.<Array.<mw.testKitchen.ExperimentInterface>>}packagestatic
#
Gets the details of all experiments with names that start with the given prefix.
This method should only be used for experiments that repeat, e.g. a data collection activity that lasts three weeks and repeats every week, and therefore usage is expected to be rare. In these cases, this method can be used to minimize the number of code changes in the experiment.
Note well that the details are returned in any order.
Example
// The user is enrolled in the following experiments:
//
// - my-awesome-experiment-1
// - my-awesome-experiment-2
// - my-other-awesome-experiment
// Gets the details of the "my-awesome-experiment-1" and "my-awesome-experiment-2" experiments
mw.testKitchen.getExperimentByPrefix( 'my-awesome-experiment-' );
Parameters:
| Name | Type | Description |
|---|---|---|
experimentNamePrefix |
string |
Returns:
- Source:
- See:
getInstrument(instrumentName) → {mw.testKitchen.InstrumentInterface}static
#
Gets details of an instrument.
This method always returns an instance of mw.testKitchen.InstrumentInterface that can:
- Determine whether the instrument is in-sample
- Send analytics events
Parameters:
| Name | Type | Description |
|---|---|---|
instrumentName |
string |
Returns:
useFakeExperiments() → {mw.testKitchen.FakeExperimentsHelper}static
#
Stubs mw.testKitchen.getExperiment, allowing developers to test their experiments.
Example
const tk = mw.testKitchen.useFakeExperiments();
const e = tk.stubExperiment( 'my-awesome-experiment', 'treatment' );
// Run Code Under Test
assert.strictEqual( e.eventCount, 1 );
assert.strictEqual( e.events[ 0 ].action, 'my-awesome-action' );
assert.strictEqual( tk.globalEventCount, 1 );
Returns:
- Source:
mw.testKitchen.getExperiment, allowing developers to test their experiments.
useFakeInstruments() → {mw.testKitchen.FakeInstrumentsHelper}static
#
Stubs mw.testKitchen.getInstrument, allowing developers to test their instruments.
Example
const tk = mw.testKitchen.useFakeInstruments();
const i = tk.stubInstrument( 'my-awesome-instrument' );
// Run Code Under Test
assert.strictEqual( i.eventCount, 1 );
assert.strictEqual( i.events[ 0 ].action, 'my-awesome-action' );
assert.strictEqual( tk.globalEventCount, 1 );
Returns:
- Source:
mw.testKitchen.getInstrument, allowing developers to test their instruments.
Type Definitions
EnrollmentConfig
#
ExperimentConfig
#
Type:
Properties:
| Name | Type | Description |
|---|---|---|
enrolled |
string | The machine-readable name of the experiment |
assigned |
string | The group assigned to the user |
subject_id |
string | The ID assigned to the user when they were enrolled in the experiment |
sampling_unit |
string | The sampling unit used to determine whether the user should be enrolled in the experiment |
stream_name |
string | The name of the stream to send experiment-related analytics events to |
schema_id |
string | The ID of the schema used to validate experiment-related analytics events with |
phase_index |
number | The phase index of the experiment |
version |
string | The version of the experiment |
contextual_attributes |
Array.<string> | |
other_assigned |
Object.<string, string> | Enrollment information for all other experiments
that the user is enrolled in expressed as a map of experiment name (enrolled) to group
(assigned). This parameter is used as the value for the |
GenericInstrumentation
#
An instrumentation module that can be used in the context of both product health measurements, "instruments", or experiments.
InstrumentConfig
#
Type:
Properties:
| Name | Type | Description |
|---|---|---|
schema_id |
string | The ID of the schema used to validate experiment-related analytics |
InstrumentSamplingConfig
#
PartialExperimentConfig
#
Type:
Properties:
| Name | Type | Description |
|---|---|---|
user_identifier_type |
string | |
schema_id |
string | |
exposure_version |
string | |
version |
string | |
phase_index |
number | The phase index of the experiment |
PartialInstrumentConfig
#
Type:
Properties:
| Name | Type | Description |
|---|---|---|
sample |
mw.testKitchen.InstrumentSamplingConfig | |
stream_name |
string | The name of the stream to send experiment-related analytics events to |
contextual_attributes |
Array.<string> |