feat(health): make /health report per-provider probe status
Introduce ProviderHealthChecker which probes each configured provider via AutowireIterator. Wire it into GraphController so /health returns detailed per-provider status and responds 503 when any provider is in a degraded state. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Attribute\AutowireIterator;
|
||||
|
||||
final class ProviderHealthChecker
|
||||
{
|
||||
public function __construct(
|
||||
#[AutowireIterator('app.provider')]
|
||||
private readonly iterable $providers,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return array{status: string, providers: array<string, array<string, string>>}
|
||||
*/
|
||||
public function check(): array
|
||||
{
|
||||
$statuses = [];
|
||||
$hasError = false;
|
||||
|
||||
/** @var ProviderInterface $provider */
|
||||
foreach ($this->providers as $provider) {
|
||||
$status = $provider->probe();
|
||||
$statuses[$status->name] = $status->toArray();
|
||||
|
||||
if ($status->status === ProviderStatusType::Error) {
|
||||
$hasError = true;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => $hasError ? 'degraded' : 'ok',
|
||||
'providers' => $statuses,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user