Page MenuHomePhabricator

Prepare sticky cookie for gradual PHP 8.1 rollout
Closed, ResolvedPublic

Description

Requirements:

  • Consistency within a browsing session from a given client. This is important to help find, reproduce, and report issues.
  • Progressively increase traffic to PHP 8.1 via a sample rate.
  • Lowering the sample rate back down, in case of issues, should move existing clients back as well.

Previously:

Event Timeline

The previous MW configuration and JS code for this has been kept and maintained since 2022 and so is already in production:

From Codesearch (current code):

The mechanism is controlled via the $wgWMENewPHPVersion and $wgWMENewPHPSamplingRate MediaWiki configuration variables, which default to "" and 0 respectively.

When set, the above JavaScript code (already enabled in production today) will create a 7-day PHP_ENGINE cookies, set to the value of $wgWMENewPHPVersion.

When the traffic is at 0%, or if you want to force your own opt-in for any reason when your own random cookie happens to be outside the bucket, you can use the PHP_ENGINE_STICKY=1 cookie to force the client logic to preserve any manaully set PHP_ENGINE=8.1 cookie, as follows:

Browser console
$.cookie( 'PHP_ENGINE', version, { expires: 30, path: '/' } );
$.cookie( 'PHP_ENGINE_STICKY', '1', { expires: 30, path: '/' } );

Cookies like PHP_ENGINE=8.1 are expected to be handled at either the edge or appserver layer. Previously this was handled in Varnish and Apache. Now, on mw-on-k8s, I imagine this will be in hanled in an ATS plugin. That'll be tracked in a separate task.

Local testing:

LocalSettings
wfLoadExtension('EventLogging');
wfLoadExtension('EventBus');

wfLoadExtension('WikimediaEvents');

$wgWMENewPHPVersion = '8.1';
$wgWMENewPHPSamplingRate = 0.0;

Then, from the Main Page, logged-out, in the browser console

Console (initial state)
$.cookie();
//> Object { "my_wikimwuser-sessionId": "0cf86c91af0ff8ba946e" }
mw.loader.moduleRegistry['ext.wikimediaEvents'].packageExports['config.json']
//> Object { newPHPSamplingRate: 0, newPHPVersion: "8.1", … }
LocalSettings (50%)
$wgWMENewPHPVersion = '8.1';
$wgWMENewPHPSamplingRate = 0.5;
Console (50%)
$.cookie()
//> Object { "my_wikimwuser-sessionId": "0cf86c91af0ff8ba946e", PHP_ENGINE: "8.1" }
mw.loader.moduleRegistry['ext.wikimediaEvents'].packageExports['config.json']
//> Object { newPHPSamplingRate: 0.5, newPHPVersion: "8.1", … }
LocalSettings (100%)
$wgWMENewPHPVersion = '8.1';
$wgWMENewPHPSamplingRate = 1.0;
Console (100%)
$.cookie()
//> Object { "my_wikimwuser-sessionId": "0cf86c91af0ff8ba946e", PHP_ENGINE: "8.1" }
mw.loader.moduleRegistry['ext.wikimediaEvents'].packageExports['config.json']
//> Object { newPHPSamplingRate: 1, newPHPVersion: "8.1", … }
LocalSettings (rollback)
$wgWMENewPHPVersion = '8.1';
$wgWMENewPHPSamplingRate = 0.2;
Console (rollback)
$.cookie()
//> Object { "my_wikimwuser-sessionId": "0cf86c91af0ff8ba946e" }
mw.loader.moduleRegistry['ext.wikimediaEvents'].packageExports['config.json']
//> Object { newPHPSamplingRate: 0.2, newPHPVersion: "8.1", … }

Next, manual override for developer testing (e.g. when sample rate is at 0%).

$.cookie()
//> Object { "my_wikimwuser-sessionId": "0cf86c91af0ff8ba946e" }
mw.loader.moduleRegistry['ext.wikimediaEvents'].packageExports['config.json']
//> Object { newPHPSamplingRate: 0, newPHPVersion: "8.1", … }

$.cookie( 'PHP_ENGINE', '8.1', { expires: 30, path: '/' } );
$.cookie( 'PHP_ENGINE_STICKY', '1', { expires: 30, path: '/' } );

After hard-refreshing the page, the JS code is expected to preserve the PHP_ENGINE cookie, despite being outside sampling (unlike rollback behaviour above):

$.cookie()
//> Object { "my_wikimwuser-sessionId": "0cf86c91af0ff8ba946e", PHP_ENGINE: "8.1", PHP_ENGINE_STICKY: "1" }
mw.loader.moduleRegistry['ext.wikimediaEvents'].packageExports['config.json']
//> Object { newPHPSamplingRate: 0, newPHPVersion: "8.1", … }