Enable Discovery debug logging for production troubleshooting
- Add DISCOVERY_LOG_LEVEL=debug - Add DISCOVERY_SHOW_PROGRESS=true - Temporary changes for debugging InitializerProcessor fixes on production
This commit is contained in:
73
src/Framework/Database/ConnectionMetadata.php
Normal file
73
src/Framework/Database/ConnectionMetadata.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\Database;
|
||||
|
||||
/**
|
||||
* Connection metadata for advanced pool management
|
||||
*/
|
||||
final class ConnectionMetadata
|
||||
{
|
||||
public function __construct(
|
||||
public readonly string $id,
|
||||
public readonly \DateTimeImmutable $createdAt,
|
||||
public \DateTimeImmutable $lastUsedAt,
|
||||
public \DateTimeImmutable $lastHealthCheckAt,
|
||||
public bool $isHealthy = true,
|
||||
public int $totalQueries = 0,
|
||||
public int $failedQueries = 0,
|
||||
public float $averageQueryTime = 0.0,
|
||||
) {
|
||||
}
|
||||
|
||||
public function recordQuery(float $executionTimeMs, bool $successful = true): void
|
||||
{
|
||||
$this->lastUsedAt = new \DateTimeImmutable();
|
||||
$this->totalQueries++;
|
||||
|
||||
if (! $successful) {
|
||||
$this->failedQueries++;
|
||||
}
|
||||
|
||||
// Update average query time (simple moving average)
|
||||
$this->averageQueryTime = ($this->averageQueryTime * ($this->totalQueries - 1) + $executionTimeMs) / $this->totalQueries;
|
||||
}
|
||||
|
||||
public function updateHealthStatus(bool $isHealthy): void
|
||||
{
|
||||
$this->isHealthy = $isHealthy;
|
||||
$this->lastHealthCheckAt = new \DateTimeImmutable();
|
||||
}
|
||||
|
||||
public function isIdle(int $maxIdleTimeSeconds): bool
|
||||
{
|
||||
$idleTime = time() - $this->lastUsedAt->getTimestamp();
|
||||
|
||||
return $idleTime > $maxIdleTimeSeconds;
|
||||
}
|
||||
|
||||
public function needsHealthCheck(int $healthCheckIntervalSeconds): bool
|
||||
{
|
||||
$timeSinceLastCheck = time() - $this->lastHealthCheckAt->getTimestamp();
|
||||
|
||||
return $timeSinceLastCheck > $healthCheckIntervalSeconds;
|
||||
}
|
||||
|
||||
public function getStats(): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'created_at' => $this->createdAt->format('c'),
|
||||
'last_used_at' => $this->lastUsedAt->format('c'),
|
||||
'last_health_check_at' => $this->lastHealthCheckAt->format('c'),
|
||||
'is_healthy' => $this->isHealthy,
|
||||
'total_queries' => $this->totalQueries,
|
||||
'failed_queries' => $this->failedQueries,
|
||||
'failure_rate' => $this->totalQueries > 0 ? $this->failedQueries / $this->totalQueries : 0,
|
||||
'average_query_time_ms' => $this->averageQueryTime,
|
||||
'age_seconds' => time() - $this->createdAt->getTimestamp(),
|
||||
'idle_time_seconds' => time() - $this->lastUsedAt->getTimestamp(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user