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:
@@ -1,8 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Service\ContributionAggregator;
|
||||
use App\Service\ProviderHealthChecker;
|
||||
use App\Service\SvgRenderer;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
@@ -13,7 +16,7 @@ use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Contracts\Cache\CacheInterface;
|
||||
use Symfony\Contracts\Cache\ItemInterface;
|
||||
|
||||
class GraphController
|
||||
final class GraphController
|
||||
{
|
||||
/** @var list<string> */
|
||||
private readonly array $allowedHosts;
|
||||
@@ -23,6 +26,7 @@ class GraphController
|
||||
private readonly SvgRenderer $renderer,
|
||||
private readonly CacheInterface $cache,
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly ProviderHealthChecker $healthChecker,
|
||||
#[Autowire(env: 'ALLOWED_HOSTS')]
|
||||
string $allowedHosts = '',
|
||||
) {
|
||||
@@ -73,8 +77,13 @@ class GraphController
|
||||
#[Route('/health', name: 'health', methods: ['GET'])]
|
||||
public function health(): Response
|
||||
{
|
||||
return new Response('{"status":"ok"}', 200, ['Content-Type' => 'application/json']);
|
||||
$result = $this->healthChecker->check();
|
||||
$statusCode = $result['status'] === 'degraded' ? 503 : 200;
|
||||
|
||||
return new Response(
|
||||
json_encode($result, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR),
|
||||
$statusCode,
|
||||
['Content-Type' => 'application/json'],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user