Skip to content

Commit 8cc9f93

Browse files
Scope worker compatibility metrics to the requested namespace
1 parent 75a1b18 commit 8cc9f93

2 files changed

Lines changed: 35 additions & 4 deletions

File tree

src/V2/Support/OperatorMetrics.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static function snapshot(?CarbonInterface $now = null, ?string $namespace
5050
'command_contracts' => self::commandContractMetrics($namespace),
5151
'projections' => self::projectionMetrics($now, $namespace),
5252
'schedules' => self::scheduleMetrics($now, $namespace),
53-
'workers' => self::workerMetrics(),
53+
'workers' => self::workerMetrics($namespace),
5454
'backend' => BackendCapabilities::snapshot($now),
5555
'structural_limits' => StructuralLimits::snapshot(),
5656
'update_wait' => UpdateWaitPolicy::snapshot(),
@@ -302,10 +302,13 @@ private static function scheduleMetrics(CarbonInterface $now, ?string $namespace
302302
/**
303303
* @return array<string, mixed>
304304
*/
305-
private static function workerMetrics(): array
305+
private static function workerMetrics(?string $namespace): array
306306
{
307307
$required = WorkerCompatibility::current();
308-
$snapshots = WorkerCompatibilityFleet::details($required);
308+
$compatibilityNamespace = $namespace ?? WorkerCompatibilityFleet::scopeNamespace();
309+
$snapshots = $compatibilityNamespace === null
310+
? WorkerCompatibilityFleet::details($required)
311+
: WorkerCompatibilityFleet::detailsForNamespace($compatibilityNamespace, $required);
309312
$workerIds = [];
310313
$supportingWorkerIds = [];
311314
$fleet = [];
@@ -329,7 +332,7 @@ private static function workerMetrics(): array
329332
}
330333

331334
return [
332-
'compatibility_namespace' => WorkerCompatibilityFleet::scopeNamespace(),
335+
'compatibility_namespace' => $compatibilityNamespace,
333336
'required_compatibility' => $required,
334337
'active_workers' => count($workerIds),
335338
'active_worker_scopes' => count($snapshots),

tests/Feature/V2/V2OperatorMetricsTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,34 @@ public function testWorkerFleetSnapshotFallsBackToCacheWhenHeartbeatTableIsUnava
6565
$this->assertTrue($snapshot['workers']['fleet'][0]['supports_required']);
6666
}
6767

68+
public function testWorkerFleetSnapshotUsesRequestedNamespaceInsteadOfConfiguredCompatibilityNamespace(): void
69+
{
70+
Carbon::setTestNow('2026-04-09 12:00:00');
71+
$this->beforeApplicationDestroyed(static function (): void {
72+
Carbon::setTestNow();
73+
WorkerCompatibilityFleet::clear();
74+
});
75+
76+
config()
77+
->set('workflows.v2.compatibility.current', 'build-a');
78+
config()
79+
->set('workflows.v2.compatibility.namespace', 'shipping');
80+
81+
WorkerCompatibilityFleet::clear();
82+
WorkerCompatibilityFleet::recordForNamespace('billing', ['build-a'], 'redis', 'default', 'worker-billing');
83+
WorkerCompatibilityFleet::recordForNamespace('shipping', ['build-a'], 'redis', 'default', 'worker-shipping');
84+
85+
$snapshot = OperatorMetrics::snapshot(now(), 'billing');
86+
87+
$this->assertSame('billing', $snapshot['workers']['compatibility_namespace']);
88+
$this->assertSame(1, $snapshot['workers']['active_workers']);
89+
$this->assertSame(1, $snapshot['workers']['active_worker_scopes']);
90+
$this->assertSame(1, $snapshot['workers']['active_workers_supporting_required']);
91+
$this->assertCount(1, $snapshot['workers']['fleet']);
92+
$this->assertSame('worker-billing', $snapshot['workers']['fleet'][0]['worker_id']);
93+
$this->assertSame('billing', $snapshot['workers']['fleet'][0]['namespace']);
94+
}
95+
6896
public function testSnapshotSummarizesDurableBacklogRepairCompatibilityAndWorkerFleet(): void
6997
{
7098
Carbon::setTestNow('2026-04-09 12:00:00');

0 commit comments

Comments
 (0)