From c2680d286ac72b2d30890d4cc746d7c16528f937 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Thu, 19 Sep 2024 14:15:07 -0400 Subject: [PATCH 1/2] Track servers by host:port instead of serverConnectionId The server's connection ID is unique within the context of a single server and is only reported by MongoDB 4.2+. It should not be used to uniquely identify a server. This reverts recent changes from 50d1db71aa7ad6d8969ff48c0325ff5a7930f8f6. --- .../RetryableReads/Prose2_RetryOnMongosTest.php | 12 ++++++------ .../Prose4_RetryOnDifferentMongosTest.php | 4 ++-- .../RetryableWrites/Prose5_RetryOnSameMongosTest.php | 8 ++++---- tests/UnifiedSpecTests/EventCollector.php | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/SpecTests/RetryableReads/Prose2_RetryOnMongosTest.php b/tests/SpecTests/RetryableReads/Prose2_RetryOnMongosTest.php index 958e74b07..2040c3d49 100644 --- a/tests/SpecTests/RetryableReads/Prose2_RetryOnMongosTest.php +++ b/tests/SpecTests/RetryableReads/Prose2_RetryOnMongosTest.php @@ -64,7 +64,7 @@ public function testRetryOnDifferentMongos(): void // Step 4: Enable failed command event monitoring for client $subscriber = new class implements CommandSubscriber { - /** @var int[] */ + /** @var string[] */ public array $commandFailedServers = []; public function commandStarted(CommandStartedEvent $event): void @@ -77,7 +77,7 @@ public function commandSucceeded(CommandSucceededEvent $event): void public function commandFailed(CommandFailedEvent $event): void { - $this->commandFailedServers[] = $event->getServerConnectionId(); + $this->commandFailedServers[] = $event->getHost() . ':' . $event->getPort(); } }; @@ -130,8 +130,8 @@ public function testRetryOnSameMongos(): void // Step 4: Enable succeeded and failed command event monitoring $subscriber = new class implements CommandSubscriber { - public ?int $commandSucceededServer = null; - public ?int $commandFailedServer = null; + public ?string $commandSucceededServer = null; + public ?string $commandFailedServer = null; public function commandStarted(CommandStartedEvent $event): void { @@ -139,12 +139,12 @@ public function commandStarted(CommandStartedEvent $event): void public function commandSucceeded(CommandSucceededEvent $event): void { - $this->commandSucceededServer = $event->getServerConnectionId(); + $this->commandSucceededServer = $event->getHost() . ':' . $event->getPort(); } public function commandFailed(CommandFailedEvent $event): void { - $this->commandFailedServer = $event->getServerConnectionId(); + $this->commandFailedServer = $event->getHost() . ':' . $event->getPort(); } }; diff --git a/tests/SpecTests/RetryableWrites/Prose4_RetryOnDifferentMongosTest.php b/tests/SpecTests/RetryableWrites/Prose4_RetryOnDifferentMongosTest.php index 6d2fd7d50..f78ba3b75 100644 --- a/tests/SpecTests/RetryableWrites/Prose4_RetryOnDifferentMongosTest.php +++ b/tests/SpecTests/RetryableWrites/Prose4_RetryOnDifferentMongosTest.php @@ -67,7 +67,7 @@ public function testRetryOnDifferentMongos(): void // Step 4: Enable failed command event monitoring for client $subscriber = new class implements CommandSubscriber { - /** @var int[] */ + /** @var string[] */ public array $commandFailedServers = []; public function commandStarted(CommandStartedEvent $event): void @@ -80,7 +80,7 @@ public function commandSucceeded(CommandSucceededEvent $event): void public function commandFailed(CommandFailedEvent $event): void { - $this->commandFailedServers[] = $event->getServerConnectionId(); + $this->commandFailedServers[] = $event->getHost() . ':' . $event->getPort(); } }; diff --git a/tests/SpecTests/RetryableWrites/Prose5_RetryOnSameMongosTest.php b/tests/SpecTests/RetryableWrites/Prose5_RetryOnSameMongosTest.php index 7357b30f2..565ebf201 100644 --- a/tests/SpecTests/RetryableWrites/Prose5_RetryOnSameMongosTest.php +++ b/tests/SpecTests/RetryableWrites/Prose5_RetryOnSameMongosTest.php @@ -49,8 +49,8 @@ public function testRetryOnSameMongos(): void // Step 4: Enable succeeded and failed command event monitoring $subscriber = new class implements CommandSubscriber { - public ?int $commandSucceededServer = null; - public ?int $commandFailedServer = null; + public ?string $commandSucceededServer = null; + public ?string $commandFailedServer = null; public function commandStarted(CommandStartedEvent $event): void { @@ -58,12 +58,12 @@ public function commandStarted(CommandStartedEvent $event): void public function commandSucceeded(CommandSucceededEvent $event): void { - $this->commandSucceededServer = $event->getServerConnectionId(); + $this->commandSucceededServer = $event->getHost() . ':' . $event->getPort(); } public function commandFailed(CommandFailedEvent $event): void { - $this->commandFailedServer = $event->getServerConnectionId(); + $this->commandFailedServer = $event->getHost() . ':' . $event->getPort(); } }; diff --git a/tests/UnifiedSpecTests/EventCollector.php b/tests/UnifiedSpecTests/EventCollector.php index 7e31328dd..2251428d2 100644 --- a/tests/UnifiedSpecTests/EventCollector.php +++ b/tests/UnifiedSpecTests/EventCollector.php @@ -119,7 +119,7 @@ private function handleCommandMonitoringEvent($event): void 'name' => self::getEventName($event), 'observedAt' => microtime(true), 'commandName' => $event->getCommandName(), - 'connectionId' => $event->getServerConnectionId(), + 'connectionId' => $event->getHost() . ':' . $event->getPort(), 'requestId' => $event->getRequestId(), 'operationId' => $event->getOperationId(), ]; From bd6b38c6153872e1bbbc5ed39fcd1af045e95fb1 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Thu, 19 Sep 2024 14:20:55 -0400 Subject: [PATCH 2/2] Rename connectionId and add extra fields to EventCollector logs This renames connectionId to server, to avoid ambiguity with serverConnectionId. Additional fields have also been added to the output. Since PHPC 1.19, database name is available on all APM events. --- tests/UnifiedSpecTests/EventCollector.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/UnifiedSpecTests/EventCollector.php b/tests/UnifiedSpecTests/EventCollector.php index 2251428d2..8acf41de7 100644 --- a/tests/UnifiedSpecTests/EventCollector.php +++ b/tests/UnifiedSpecTests/EventCollector.php @@ -119,18 +119,17 @@ private function handleCommandMonitoringEvent($event): void 'name' => self::getEventName($event), 'observedAt' => microtime(true), 'commandName' => $event->getCommandName(), - 'connectionId' => $event->getHost() . ':' . $event->getPort(), - 'requestId' => $event->getRequestId(), + 'databaseName' => $event->getDatabaseName(), 'operationId' => $event->getOperationId(), + 'requestId' => $event->getRequestId(), + 'server' => $event->getHost() . ':' . $event->getPort(), + 'serverConnectionId' => $event->getServerConnectionId(), + 'serviceId' => $event->getServiceId(), ]; /* Note: CommandStartedEvent.command and CommandSucceededEvent.reply can * be omitted from logged events. */ - if ($event instanceof CommandStartedEvent) { - $log['databaseName'] = $event->getDatabaseName(); - } - if ($event instanceof CommandSucceededEvent) { $log['duration'] = $event->getDurationMicros(); }