feat: mention selected port by api client in log messages

This commit is contained in:
Björn Fromme
2026-05-18 12:48:07 +02:00
parent b18b09d4a5
commit de4dadb9e5
2 changed files with 28 additions and 1 deletions
+8
View File
@@ -844,6 +844,7 @@ class ApiClient
$this->logger->error('Connection retry timeout exceeded', [ $this->logger->error('Connection retry timeout exceeded', [
'elapsed_time' => microtime(true) - $this->operationStartTime, 'elapsed_time' => microtime(true) - $this->operationStartTime,
'total_timeout' => $this->config['total_timeout'], 'total_timeout' => $this->config['total_timeout'],
'port' => $this->selectedPort,
]); ]);
throw new TimeoutException('Connection timeout exceeded during retries'); throw new TimeoutException('Connection timeout exceeded during retries');
} }
@@ -852,6 +853,7 @@ class ApiClient
'error_message' => $errStr, 'error_message' => $errStr,
'error_number' => $errNo, 'error_number' => $errNo,
'attempt' => $tries, 'attempt' => $tries,
'port' => $this->selectedPort,
]); ]);
++$tries; ++$tries;
sleep(1); sleep(1);
@@ -865,6 +867,7 @@ class ApiClient
'error_message' => $errStr, 'error_message' => $errStr,
'error_number' => $errNo, 'error_number' => $errNo,
'elapsed_time' => microtime(true) - $this->operationStartTime, 'elapsed_time' => microtime(true) - $this->operationStartTime,
'port' => $this->selectedPort,
]); ]);
throw new ApiClientException('Unable to open socket'); throw new ApiClientException('Unable to open socket');
} }
@@ -883,6 +886,7 @@ class ApiClient
if (microtime(true) - $this->operationStartTime > $this->config['total_timeout']) { if (microtime(true) - $this->operationStartTime > $this->config['total_timeout']) {
$this->logger->error('Total timeout exceeded before send', [ $this->logger->error('Total timeout exceeded before send', [
'elapsed_time' => microtime(true) - $this->operationStartTime, 'elapsed_time' => microtime(true) - $this->operationStartTime,
'port' => $this->selectedPort,
]); ]);
throw new TimeoutException('Total operation timeout exceeded before send'); throw new TimeoutException('Total operation timeout exceeded before send');
} }
@@ -913,6 +917,7 @@ class ApiClient
'total_timeout' => $totalTimeout, 'total_timeout' => $totalTimeout,
'bytes_received' => strlen($response), 'bytes_received' => strlen($response),
'read_attempts' => $readAttempts, 'read_attempts' => $readAttempts,
'port' => $this->selectedPort,
]); ]);
throw new TimeoutException('Total operation timeout exceeded while receiving data'); throw new TimeoutException('Total operation timeout exceeded while receiving data');
} }
@@ -930,6 +935,7 @@ class ApiClient
'elapsed_time' => $elapsedTime, 'elapsed_time' => $elapsedTime,
'bytes_received' => 0, 'bytes_received' => 0,
'read_attempts' => $readAttempts, 'read_attempts' => $readAttempts,
'port' => $this->selectedPort,
]); ]);
throw new ImmediateConnectionCloseException('Server closed connection immediately - server may be busy'); throw new ImmediateConnectionCloseException('Server closed connection immediately - server may be busy');
} }
@@ -938,6 +944,7 @@ class ApiClient
'elapsed_time' => $elapsedTime, 'elapsed_time' => $elapsedTime,
'bytes_received' => strlen($response), 'bytes_received' => strlen($response),
'read_attempts' => $readAttempts, 'read_attempts' => $readAttempts,
'port' => $this->selectedPort,
]); ]);
throw new TimeoutException('Stream timeout while reading from socket'); throw new TimeoutException('Stream timeout while reading from socket');
} }
@@ -950,6 +957,7 @@ class ApiClient
$this->logger->warning('Server closed connection without sending data', [ $this->logger->warning('Server closed connection without sending data', [
'elapsed_time' => $elapsedTime, 'elapsed_time' => $elapsedTime,
'read_attempts' => $readAttempts, 'read_attempts' => $readAttempts,
'port' => $this->selectedPort,
]); ]);
throw new ImmediateConnectionCloseException('Server closed connection without sending data'); throw new ImmediateConnectionCloseException('Server closed connection without sending data');
} }
+20 -1
View File
@@ -18,14 +18,17 @@ use Symfony\Component\Serializer\SerializerInterface;
class ApiClientReceiveTest extends TestCase class ApiClientReceiveTest extends TestCase
{ {
private ApiClient $apiClient; private ApiClient $apiClient;
private LoggerInterface $logger;
protected function setUp(): void protected function setUp(): void
{ {
$this->logger = $this->createMock(LoggerInterface::class);
$this->apiClient = new ApiClient( $this->apiClient = new ApiClient(
$this->createMock(SerializerInterface::class), $this->createMock(SerializerInterface::class),
$this->createMock(ApiResponseParser::class), $this->createMock(ApiResponseParser::class),
$this->createMock(FilesystemOperator::class), $this->createMock(FilesystemOperator::class),
$this->createMock(LoggerInterface::class), $this->logger,
$this->createMock(BookingDataProcessor::class), $this->createMock(BookingDataProcessor::class),
new RequestStack(), new RequestStack(),
new RequestIdGenerator(), new RequestIdGenerator(),
@@ -45,6 +48,16 @@ class ApiClientReceiveTest extends TestCase
rewind($stream); rewind($stream);
$this->setOperationStartTime(); $this->setOperationStartTime();
$this->setSelectedPort(9000);
$this->logger->expects($this->once())
->method('warning')
->with(
'Server closed connection without sending data',
$this->callback(static function (array $context): bool {
return 9000 === $context['port'];
}),
);
$this->expectException(ImmediateConnectionCloseException::class); $this->expectException(ImmediateConnectionCloseException::class);
$this->expectExceptionMessage('Server closed connection without sending data'); $this->expectExceptionMessage('Server closed connection without sending data');
@@ -77,4 +90,10 @@ class ApiClientReceiveTest extends TestCase
$property = new \ReflectionProperty(ApiClient::class, 'operationStartTime'); $property = new \ReflectionProperty(ApiClient::class, 'operationStartTime');
$property->setValue($this->apiClient, microtime(true)); $property->setValue($this->apiClient, microtime(true));
} }
private function setSelectedPort(int $port): void
{
$property = new \ReflectionProperty(ApiClient::class, 'selectedPort');
$property->setValue($this->apiClient, $port);
}
} }