Skip to content

Conversation

@deer-wmde
Copy link
Contributor

@deer-wmde deer-wmde commented Oct 31, 2025

https://phabricator.wikimedia.org/T407504

An example of how the routing to the right mediawiki version backend could happen via the API in magnustools.

You can test this via wbstack/quickstatements#187

@deer-wmde deer-wmde changed the title DNM: PoC for Mediawiki backend routing Mediawiki backend routing Nov 3, 2025
@deer-wmde deer-wmde marked this pull request as ready for review November 3, 2025 11:49
private static $callbackUrlTail;

public static function getVersionedMediawikiBackendHost() {
$host = getenv('PLATFORM_MW_BACKEND_HOST'); // default fallback
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like having a fallback. I wonder if we actually want to introduce a "we're mid updates flag" that we turn on and only in that case we do we do the API lookup.

Not for this PR though!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, as these requests probably won't get cached, as nginx does. But also shouldnt be a problem, as OAuth requests shouldn't happen too often I suppose

'Host: ' . $_SERVER['SERVER_NAME'],
];

$client = curl_init('http://' . self::platformApiBackendHost . '/backend/ingress/getWikiVersionForDomain?domain=' . $_SERVER['SERVER_NAME']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking at this whole curl thing and then trying to parse the headers of response and tried to see if there was a less complicated way. I think an alternative could be:

https://www.php.net/manual/en/function.get-headers.php

Does this look like a suitable alternative to you? I think we'd set url parameter to 'http://' . self::platformApiBackendHost . '/backend/ingress/getWikiVersionForDomain?domain=' . $_SERVER['SERVER_NAME'] and probably associative to true.

I think we'd then be able to directly access X-Version: header from the array. Does that sound right? I didn't go and try this.

Not blocking if you don't like this approach for some reason

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

incredible, how did i not know about this function? seems much more solid to me, thank you.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hahah! I didn't know about it either; I went hunting because I was scared to click approve on the string parsing of headers and all the curl setup I didn't really understand quickly without a ton of tests :P

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it wasnt very readable. Could you have a look now again pls?

deer-wmde and others added 2 commits November 4, 2025 09:56
@deer-wmde deer-wmde requested a review from tarrow November 4, 2025 10:48
Copy link
Contributor

@tarrow tarrow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me; in the absence of a test system let see if this works on staging 👀

@deer-wmde deer-wmde merged commit 855a8bb into main Nov 4, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants