Page MenuHomePhabricator

Using mw.eventLog.inSample for subsampling gets in the way of randomness
Closed, ResolvedPublic

Description

Now this is quite the hilarious bug. When looking at the survey data, I noticed that on September 20th, Russian Wikipedia NavTiming hits started getting the survey 100% of the time, when the survey sampling rate didn't change, it was still 2 (i.e. only 50% of NavTiming hits are supposed to get the survey).

The root cause turns out to be https://gerrit.wikimedia.org/r/#/c/mediawiki/extensions/NavigationTiming/+/458081/

What's happening is that once we've passed the initial mw.eventLog.inSample that determines whether NavTiming should trigger (1 in 1000 chance), we call it again to see if the survey should trigger (1 in 2 chances). But mw.eventLog.inSample works on a sticky value, looking at its modulo. If a number can be divided by 1000, it can be divided by 2...

Essentially the stickiness of mw.eventLog.inSample is making it unsuitable for nested inSample logic.

Russian Wikipedia is the only wiki where this bug manifested itself, because it's the only one configured with an even survey sampling rate!

Not having a local copy of inSample in NavigationTiming is a good idea, but the local copy still had the old property of not being sticky.

The simplest fix is for sub-sampling logic in NavigationTiming to call mw.eventLog.randomTokenMatch (non sticky) instead of mw.eventLog.inSample;

Event Timeline

Gilles renamed this task from Reusing mw.eventLog.inSample gets in the way of randomness to Using mw.eventLog.inSample for subsampling gets in the way of randomness.Oct 18 2018, 7:52 PM
Gilles triaged this task as Medium priority.Oct 18 2018, 7:56 PM

Change 468416 had a related patch set uploaded (by Gilles; owner: Gilles):
[mediawiki/extensions/NavigationTiming@master] Restore randomization independence to samplings

https://gerrit.wikimedia.org/r/468416

Change 468416 merged by jenkins-bot:
[mediawiki/extensions/NavigationTiming@master] Restore randomization independence to samplings

https://gerrit.wikimedia.org/r/468416