Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use host:port for server logging and add extra fields to EventCollector logs #1428

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions tests/SpecTests/RetryableReads/Prose2_RetryOnMongosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}
};

Expand Down Expand Up @@ -130,21 +130,21 @@ 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
{
}

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();
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,21 @@ 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
{
}

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();
}
};

Expand Down
11 changes: 5 additions & 6 deletions tests/UnifiedSpecTests/EventCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,17 @@ private function handleCommandMonitoringEvent($event): void
'name' => self::getEventName($event),
'observedAt' => microtime(true),
'commandName' => $event->getCommandName(),
'connectionId' => $event->getServerConnectionId(),
'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();
}
Expand Down