instrumentation: Avoid user.sessionId() if possible, since it sets a cookie

Bug: T289780
Change-Id: I8d80f4e02c6b59087c88d42be671fa81b4d37ba8
This commit is contained in:
Bartosz Dziewoński 2024-07-13 01:22:14 +02:00
parent 0a3665e5f0
commit 4ff08bd2fb
4 changed files with 14 additions and 6 deletions

Binary file not shown.

Binary file not shown.

View file

@ -17,6 +17,10 @@
*/
export function isEnabled( user, config, experiments ) {
const bucketingRate = config.get( 'wgPopupsStatsvSamplingRate', 0 );
if ( bucketingRate === 0 || bucketingRate === 1 ) {
// Avoid calling user.sessionId() if possible, since it sets a cookie
return !!bucketingRate;
}
return experiments.weightedBoolean(
'ext.Popups.statsv',

View file

@ -34,11 +34,15 @@ QUnit.test( '#isEnabled', function ( assert ) {
config.delete( 'wgPopupsStatsvSamplingRate' );
isEnabled( user, config, experiments );
assert.deepEqual(
weightedBooleanStub.getCall( 1 ).args[ 1 ],
0,
'The bucketing rate should be 0 by default.'
const defaultResult = isEnabled( user, config, experiments );
assert.strictEqual(
defaultResult,
false,
'The bucketing is disabled by default.'
);
assert.strictEqual(
weightedBooleanStub.callCount,
1,
'The experiments object is not called when bucketing rate is the default 0.'
);
} );