From b7e8752030d2bf60cb304531830ce89c05363d5b Mon Sep 17 00:00:00 2001 From: Dat Date: Wed, 25 Nov 2026 16:01:05 +0100 Subject: [PATCH 1/6] Add tests to check host resolution --- tests/Routes/QsBatch/QsControllerTest.php | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/Routes/QsBatch/QsControllerTest.php b/tests/Routes/QsBatch/QsControllerTest.php index 9b41e1598..bb70a564f 100644 --- a/tests/Routes/QsBatch/QsControllerTest.php +++ b/tests/Routes/QsBatch/QsControllerTest.php @@ -5,6 +5,7 @@ use App\EventPageUpdate; use App\QsBatch; use App\Wiki; +use App\WikiDb; use Carbon\Carbon; use Illuminate\Foundation\Testing\DatabaseTransactions; use Tests\TestCase; @@ -58,6 +59,30 @@ public function testGetOldestBatch(): void { $this->assertNotNull($response->json()[0]['pending_since']); } + public function testGetOldestBatchIncludesMediaWikiBackendHost(): void { + $wiki = Wiki::factory()->create(['id' => 99, 'domain' => 'test.wikibase.cloud']); + WikiDb::factory()->create(['wiki_id' => $wiki->id, 'version' => 'mw1.43-wbs2']); + QsBatch::factory()->create(['id' => 1, 'done' => 0, 'wiki_id' => 99, 'entityIds' => 'a,b']); + + $this->json('GET', $this->route . '/getBatches') + ->assertStatus(200) + ->assertJsonPath('0.mediawiki_backend_host', 'mediawiki-143-app-backend.default.svc.cluster.local') + ->assertJsonMissingPath('0.wiki.wiki_db'); + } + + public function testGetOldestBatchWithUnknownMediaWikiVersionStillReturnsBatch(): void { + $wiki = Wiki::factory()->create(['id' => 99, 'domain' => 'test.wikibase.cloud']); + WikiDb::factory()->create(['wiki_id' => $wiki->id, 'version' => 'mw1.43-unmapped']); + QsBatch::factory()->create(['id' => 1, 'done' => 0, 'wiki_id' => 99, 'entityIds' => 'a,b']); + + $this->json('GET', $this->route . '/getBatches') + ->assertStatus(200) + ->assertJsonPath('0.id', 1) + ->assertJsonPath('0.mediawiki_backend_host', null); + + $this->assertNotNull(QsBatch::where('id', 1)->first()->pending_since); + } + public function testMarkDone(): void { QsBatch::factory()->create(['pending_since' => Carbon::now()->subSeconds(1), 'id' => 1, 'done' => 1, 'wiki_id' => 1, 'entityIds' => 'a,b']); QsBatch::factory()->create(['pending_since' => Carbon::now()->subSeconds(2), 'id' => 2, 'done' => 0, 'wiki_id' => 1, 'entityIds' => 'c,d']); From b2455a185538ce56efa747d73fea6550ea03ee32 Mon Sep 17 00:00:00 2001 From: Dat Date: Wed, 25 Nov 2026 16:23:31 +0100 Subject: [PATCH 2/6] Add the version-specific MediaWiki backend host to queryservice batches --- app/Http/Controllers/Backend/QsController.php | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Backend/QsController.php b/app/Http/Controllers/Backend/QsController.php index 01c38ebbd..12ec97341 100644 --- a/app/Http/Controllers/Backend/QsController.php +++ b/app/Http/Controllers/Backend/QsController.php @@ -4,14 +4,18 @@ use App\Http\Controllers\Controller; use App\QsBatch; +use App\Services\MediaWikiHostResolver; +use App\Services\UnknownDBVersionException; +use App\Services\UnknownWikiDomainException; use Carbon\Carbon; use Illuminate\Http\Request; use Illuminate\Http\Response; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Log; class QsController extends Controller { - public function getBatches(Request $request): Response { - return DB::transaction(function () { + public function getBatches(Request $request, MediaWikiHostResolver $mwHostResolver): Response { + return DB::transaction(function () use ($mwHostResolver) { $oldestBatch = QsBatch::has('wiki') ->where([ ['done', '=', 0], @@ -29,11 +33,31 @@ public function getBatches(Request $request): Response { $oldestBatch->update(['pending_since' => Carbon::now()]); $oldestBatch->load(['wiki', 'wiki.wikiQueryserviceNamespace']); + // queryservice-updater reads from MediaWiki directly + // platform-nginx is bypassed, which does not serve suspended wikis + $oldestBatch->setAttribute( + 'mediawiki_backend_host', + $this->getMediaWikiBackendHost($mwHostResolver, $oldestBatch) + ); + return response([$oldestBatch]); }, 3); } + private function getMediaWikiBackendHost(MediaWikiHostResolver $mwHostResolver, QsBatch $batch): ?string { + try { + // Resolving by domain avoids exposing wikiDb credentials in the response + return $mwHostResolver->getBackendHostForDomain($batch->wiki->domain); + } catch (UnknownDBVersionException|UnknownWikiDomainException $e) { + Log::warning('Unable to resolve the MediaWiki backend host for queryservice batch ' . $batch->id . ': ' . $e->getMessage()); + + // Keep an unknown host from blocking the queue by returning null + // allowing the batch to proceed without a resolved backend host + return null; + } + } + public function markBatchesDone(Request $request): Response { $batches = (array) $request->json()->all('batches'); QsBatch::whereIn('id', $batches)->increment( From 5cc0cdcad018949983839589a0b02f858c4745ec Mon Sep 17 00:00:00 2001 From: Dat Date: Wed, 25 Nov 2026 16:01:05 +0100 Subject: [PATCH 3/6] Add tests to check host resolution --- tests/Routes/QsBatch/QsControllerTest.php | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/Routes/QsBatch/QsControllerTest.php b/tests/Routes/QsBatch/QsControllerTest.php index 9b41e1598..bb70a564f 100644 --- a/tests/Routes/QsBatch/QsControllerTest.php +++ b/tests/Routes/QsBatch/QsControllerTest.php @@ -5,6 +5,7 @@ use App\EventPageUpdate; use App\QsBatch; use App\Wiki; +use App\WikiDb; use Carbon\Carbon; use Illuminate\Foundation\Testing\DatabaseTransactions; use Tests\TestCase; @@ -58,6 +59,30 @@ public function testGetOldestBatch(): void { $this->assertNotNull($response->json()[0]['pending_since']); } + public function testGetOldestBatchIncludesMediaWikiBackendHost(): void { + $wiki = Wiki::factory()->create(['id' => 99, 'domain' => 'test.wikibase.cloud']); + WikiDb::factory()->create(['wiki_id' => $wiki->id, 'version' => 'mw1.43-wbs2']); + QsBatch::factory()->create(['id' => 1, 'done' => 0, 'wiki_id' => 99, 'entityIds' => 'a,b']); + + $this->json('GET', $this->route . '/getBatches') + ->assertStatus(200) + ->assertJsonPath('0.mediawiki_backend_host', 'mediawiki-143-app-backend.default.svc.cluster.local') + ->assertJsonMissingPath('0.wiki.wiki_db'); + } + + public function testGetOldestBatchWithUnknownMediaWikiVersionStillReturnsBatch(): void { + $wiki = Wiki::factory()->create(['id' => 99, 'domain' => 'test.wikibase.cloud']); + WikiDb::factory()->create(['wiki_id' => $wiki->id, 'version' => 'mw1.43-unmapped']); + QsBatch::factory()->create(['id' => 1, 'done' => 0, 'wiki_id' => 99, 'entityIds' => 'a,b']); + + $this->json('GET', $this->route . '/getBatches') + ->assertStatus(200) + ->assertJsonPath('0.id', 1) + ->assertJsonPath('0.mediawiki_backend_host', null); + + $this->assertNotNull(QsBatch::where('id', 1)->first()->pending_since); + } + public function testMarkDone(): void { QsBatch::factory()->create(['pending_since' => Carbon::now()->subSeconds(1), 'id' => 1, 'done' => 1, 'wiki_id' => 1, 'entityIds' => 'a,b']); QsBatch::factory()->create(['pending_since' => Carbon::now()->subSeconds(2), 'id' => 2, 'done' => 0, 'wiki_id' => 1, 'entityIds' => 'c,d']); From 1db00060ab1d8de979b261a61e824bb2e02b7e74 Mon Sep 17 00:00:00 2001 From: Dat Date: Wed, 25 Nov 2026 16:23:31 +0100 Subject: [PATCH 4/6] Add the version-specific MediaWiki backend host to queryservice batches --- app/Http/Controllers/Backend/QsController.php | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Backend/QsController.php b/app/Http/Controllers/Backend/QsController.php index 01c38ebbd..12ec97341 100644 --- a/app/Http/Controllers/Backend/QsController.php +++ b/app/Http/Controllers/Backend/QsController.php @@ -4,14 +4,18 @@ use App\Http\Controllers\Controller; use App\QsBatch; +use App\Services\MediaWikiHostResolver; +use App\Services\UnknownDBVersionException; +use App\Services\UnknownWikiDomainException; use Carbon\Carbon; use Illuminate\Http\Request; use Illuminate\Http\Response; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Log; class QsController extends Controller { - public function getBatches(Request $request): Response { - return DB::transaction(function () { + public function getBatches(Request $request, MediaWikiHostResolver $mwHostResolver): Response { + return DB::transaction(function () use ($mwHostResolver) { $oldestBatch = QsBatch::has('wiki') ->where([ ['done', '=', 0], @@ -29,11 +33,31 @@ public function getBatches(Request $request): Response { $oldestBatch->update(['pending_since' => Carbon::now()]); $oldestBatch->load(['wiki', 'wiki.wikiQueryserviceNamespace']); + // queryservice-updater reads from MediaWiki directly + // platform-nginx is bypassed, which does not serve suspended wikis + $oldestBatch->setAttribute( + 'mediawiki_backend_host', + $this->getMediaWikiBackendHost($mwHostResolver, $oldestBatch) + ); + return response([$oldestBatch]); }, 3); } + private function getMediaWikiBackendHost(MediaWikiHostResolver $mwHostResolver, QsBatch $batch): ?string { + try { + // Resolving by domain avoids exposing wikiDb credentials in the response + return $mwHostResolver->getBackendHostForDomain($batch->wiki->domain); + } catch (UnknownDBVersionException|UnknownWikiDomainException $e) { + Log::warning('Unable to resolve the MediaWiki backend host for queryservice batch ' . $batch->id . ': ' . $e->getMessage()); + + // Keep an unknown host from blocking the queue by returning null + // allowing the batch to proceed without a resolved backend host + return null; + } + } + public function markBatchesDone(Request $request): Response { $batches = (array) $request->json()->all('batches'); QsBatch::whereIn('id', $batches)->increment( From 835948169aecf258c8ac418ff9d78b2fac085047 Mon Sep 17 00:00:00 2001 From: Dat Date: Tue, 1 Dec 2026 18:40:29 +0100 Subject: [PATCH 5/6] Return API host instead of backend host in queryservice batches --- app/Http/Controllers/Backend/QsController.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/Backend/QsController.php b/app/Http/Controllers/Backend/QsController.php index 12ec97341..cd44538bd 100644 --- a/app/Http/Controllers/Backend/QsController.php +++ b/app/Http/Controllers/Backend/QsController.php @@ -33,11 +33,9 @@ public function getBatches(Request $request, MediaWikiHostResolver $mwHostResolv $oldestBatch->update(['pending_since' => Carbon::now()]); $oldestBatch->load(['wiki', 'wiki.wikiQueryserviceNamespace']); - // queryservice-updater reads from MediaWiki directly - // platform-nginx is bypassed, which does not serve suspended wikis $oldestBatch->setAttribute( - 'mediawiki_backend_host', - $this->getMediaWikiBackendHost($mwHostResolver, $oldestBatch) + 'mediawiki_api_host', + $this->getMediaWikiApiHost($mwHostResolver, $oldestBatch) ); return response([$oldestBatch]); @@ -45,15 +43,15 @@ public function getBatches(Request $request, MediaWikiHostResolver $mwHostResolv } - private function getMediaWikiBackendHost(MediaWikiHostResolver $mwHostResolver, QsBatch $batch): ?string { + private function getMediaWikiApiHost(MediaWikiHostResolver $mwHostResolver, QsBatch $batch): ?string { try { // Resolving by domain avoids exposing wikiDb credentials in the response - return $mwHostResolver->getBackendHostForDomain($batch->wiki->domain); + return $mwHostResolver->getHostsForDomain($batch->wiki->domain)['api']; } catch (UnknownDBVersionException|UnknownWikiDomainException $e) { - Log::warning('Unable to resolve the MediaWiki backend host for queryservice batch ' . $batch->id . ': ' . $e->getMessage()); + Log::warning('Unable to resolve the MediaWiki API host for queryservice batch ' . $batch->id . ': ' . $e->getMessage()); // Keep an unknown host from blocking the queue by returning null - // allowing the batch to proceed without a resolved backend host + // allowing the batch to proceed without a resolved API host return null; } } From 856d6ba05686411e4b109144994636f16cf458bb Mon Sep 17 00:00:00 2001 From: Dat Date: Tue, 1 Dec 2026 18:59:43 +0100 Subject: [PATCH 6/6] update test --- tests/Routes/QsBatch/QsControllerTest.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/Routes/QsBatch/QsControllerTest.php b/tests/Routes/QsBatch/QsControllerTest.php index bb70a564f..d2c9f32f7 100644 --- a/tests/Routes/QsBatch/QsControllerTest.php +++ b/tests/Routes/QsBatch/QsControllerTest.php @@ -59,14 +59,15 @@ public function testGetOldestBatch(): void { $this->assertNotNull($response->json()[0]['pending_since']); } - public function testGetOldestBatchIncludesMediaWikiBackendHost(): void { + public function testGetOldestBatchIncludesMediaWikiApiHost(): void { $wiki = Wiki::factory()->create(['id' => 99, 'domain' => 'test.wikibase.cloud']); WikiDb::factory()->create(['wiki_id' => $wiki->id, 'version' => 'mw1.43-wbs2']); QsBatch::factory()->create(['id' => 1, 'done' => 0, 'wiki_id' => 99, 'entityIds' => 'a,b']); $this->json('GET', $this->route . '/getBatches') ->assertStatus(200) - ->assertJsonPath('0.mediawiki_backend_host', 'mediawiki-143-app-backend.default.svc.cluster.local') + ->assertJsonPath('0.mediawiki_api_host', 'mediawiki-143-app-api.default.svc.cluster.local') + ->assertJsonMissingPath('0.mediawiki_backend_host') ->assertJsonMissingPath('0.wiki.wiki_db'); } @@ -78,7 +79,7 @@ public function testGetOldestBatchWithUnknownMediaWikiVersionStillReturnsBatch() $this->json('GET', $this->route . '/getBatches') ->assertStatus(200) ->assertJsonPath('0.id', 1) - ->assertJsonPath('0.mediawiki_backend_host', null); + ->assertJsonPath('0.mediawiki_api_host', null); $this->assertNotNull(QsBatch::where('id', 1)->first()->pending_since); }