Page MenuHomePhabricator

Evaluate completeness of testwiki traffic diversion to Pretrain
Open, MediumPublic

Description

Motivation

Once we've completed implementation of traffic diversion to Pretrain for all supported request paths and (incrementally) enabled it for testwiki, we need to evaluate the completeness of diversion. Indeed, completeness is central to the parent hypothesis (T427659) and is a fundamental requirement before making Pretrain meaningfully different from the rest of production MediaWiki-on-k8s by adopting the wmf/next images.

Our expectation is that the vast majority of traffic will be covered by the work already tracked under the parent and sibling tasks, but there will likely be a game of whackamole to identify services that, e.g., do not use the service mesh.

Proposal

What we need is a way to detect the presence of HTTP traffic for Pretrain wikis (initially just testwiki) outside of mw-pretrain and surface it, along with properties of the HTTP request (e.g., direct client IP, User-Agent) to aid in identifying the source. Note that these are effectively always going to be internal sources.

While we have httpd access logs for MediaWiki-on-k8s in logstash (i.e., emitted by apache2 and forwarded by rsyslog), these are sampled (1/100) in rsyslog and it would be challenging / brittle to conditionally disable sampling for specific combinations of HTTP Host and k8s namespace.

Instead, I'd propose we do something in mediawiki-config. At a high level, we could:

  • Extend ClusterConfig with an isPretrain method, by analogy with other SERVERGROUP-trait-based patterns there (see ClusterConfig.php).
  • If isPretrain returns false [0] and wgDBname is in the array of Pretrain-targeted wikis (i.e., just testwiki initially), then log a warning. This would most likely happen somewhere in CommonSettings.php.

Now, where this gets tricky is "log a warning" - we won't have the normal MediaWiki log facilities available at this point in the request lifecycle. We could just trigger_error at E_USER_WARNING, but that's pretty crude, as it just lands us in the PHP-FPM error logs - i.e., no structured logging. This is similar to the problem discussed in T422455#11801546.

Instead, I believe we could use https://www.mediawiki.org/wiki/Manual:$wgExtensionFunctions to defer logging until after MediaWiki is fully initialized, similar to what's done for the XFF log channel. That would allow us to use MediaWiki's structured log facilities, emitting these logs to a distinct channel.

[0] Note: At least for the MVP, we do not intend to support maintenance script execution in Pretrain - i.e., on-demand scripts will continue to run in mw-script and periodic jobs will run in mw-cron. Thus, we want to exclude the PHP_SAPI === 'cli' case from this condition, as these cases are permitted to run outside mw-pretrain.