eqs / health-check-provider
Provides healthcheck endpoints in accordance with IETF's healthcheck draft RFC
Installs: 2 918
Dependents: 0
Suggesters: 0
Security: 0
Stars: 16
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: ^8.1
- psr/clock: ^1.0
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
- psr/http-server-handler: ^1.0
Requires (Dev)
- doctrine/dbal: ^3.7
- ramsey/devtools: ^2.0
- spatie/phpunit-snapshot-assertions: ^5.1
- symfony/browser-kit: ^7.0
- symfony/clock: ^7.0
- symfony/framework-bundle: ^7.0
- symfony/psr-http-message-bridge: ^7.0
This package is auto-updated.
Last update: 2024-11-01 10:09:10 UTC
README
Provides structure for healthcheck endpoints in accordance with IETF's healthcheck draft RFC
About
Package provides endpoints which conform to draft 06 version of IETF's healthcheck RFC.
Integrations
We are shipping following integrations, but it's very easy to implement your own by reusing CallableHealthChecker:
- HTTP request
- Doctrine Connection
Installation
Install this package as a dependency using Composer.
composer require eqs/health-check-provider
Usage
This library provides PSR-15 HTTP Server Request Handler, which guarantees compatibility with wide range of PHP frameworks. In case your framework does not natively support it, you can find a PSR bridge which supports it.
Example controller for Symfony framework
For this example, on top of standard symfony packages, you also need php-http/discovery
and symfony/psr-http-message-bridge
packages.
use Doctrine\DBAL\Connection; use GuzzleHttp\Psr7\HttpFactory; use EQS\HealthCheckProvider\DTO\CheckDetails; use EQS\HealthCheckProvider\DTO\HealthResponse; use EQS\HealthCheckProvider\HealthChecker\CallableHealthChecker; use EQS\HealthCheckProvider\HealthChecker\DoctrineConnectionHealthChecker; use EQS\HealthCheckProvider\HealthChecker\HttpHealthChecker; use EQS\HealthCheckProvider\RequestHandler; use Psr\Http\Client\ClientInterface; use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory; use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Messenger\Transport\Receiver\MessageCountAwareInterface; use Symfony\Component\Messenger\Transport\TransportInterface; use Symfony\Component\Routing\Annotation\Route; class GetHealthCheckController extends AbstractController { public function __construct( #[Autowire(service: 'messenger.transport.amqp_dc_user_update')] private MessageCountAwareInterface&TransportInterface $transport, private Connection $connection, private ClientInterface $httpClient, ) {} #[Route(path: '/api/health_check')] public function __invoke(Request $request): Response { $psr17Factory = new HttpFactory(); $psrBridge = new HttpFoundationFactory(); return $psrBridge->createResponse( (new RequestHandler( new HealthResponse(), [ new CallableHealthChecker(new CheckDetails('AMQP', true), fn () => $this->transport->getMessageCount()), new DoctrineConnectionHealthChecker(new CheckDetails('Database', true), $this->connection), new HttpHealthChecker( new CheckDetails('External API', false), $this->httpClient, new \GuzzleHttp\Psr7\Request('GET', 'https://www.google.com'), ), ], $psr17Factory, $psr17Factory, )) ->handle((new PsrHttpFactory($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory)) ->createRequest($request)), ); } }
Contributing
Contributions are welcome! To contribute, please familiarize yourself with CONTRIBUTING.md.
Copyright and License
eqs/health-check-provider is copyright © EQS Group and licensed for use under the terms of the MIT License (MIT). Please see LICENSE for more information.