diff --git a/ratings/html/src/Kernel.php b/ratings/html/src/Kernel.php index ef317fa..b7b5949 100644 --- a/ratings/html/src/Kernel.php +++ b/ratings/html/src/Kernel.php @@ -8,6 +8,7 @@ use Instana\RobotShop\Ratings\Controller\HealthController; use Instana\RobotShop\Ratings\Controller\RatingsApiController; use Instana\RobotShop\Ratings\Integration\InstanaHeadersLoggingProcessor; use Instana\RobotShop\Ratings\Service\CatalogueService; +use Instana\RobotShop\Ratings\Service\HealthCheckService; use Instana\RobotShop\Ratings\Service\RatingsService; use Monolog\Formatter\LineFormatter; use Symfony\Bundle\FrameworkBundle\FrameworkBundle; @@ -96,6 +97,11 @@ class Kernel extends BaseKernel implements EventSubscriberInterface ->addMethodCall('setLogger', [new Reference('logger')]) ->setAutowired(true); + $c->register(HealthCheckService::class) + ->addArgument(new Reference('database.connection')) + ->addMethodCall('setLogger', [new Reference('logger')]) + ->setAutowired(true); + $c->register('database.connection', \PDO::class) ->setFactory([new Reference(Database::class), 'getConnection']); diff --git a/ratings/html/src/Service/HealthCheckService.php b/ratings/html/src/Service/HealthCheckService.php index edbba00..551e8d0 100644 --- a/ratings/html/src/Service/HealthCheckService.php +++ b/ratings/html/src/Service/HealthCheckService.php @@ -5,9 +5,13 @@ declare(strict_types=1); namespace Instana\RobotShop\Ratings\Service; use PDO; +use Psr\Log\LoggerAwareInterface; +use Psr\Log\LoggerAwareTrait; -class HealthCheckService +class HealthCheckService implements LoggerAwareInterface { + use LoggerAwareTrait; + /** * @var PDO */ @@ -18,7 +22,7 @@ class HealthCheckService $this->pdo = $pdo; } - public function checkConnectivity() + public function checkConnectivity(): bool { return $this->pdo->prepare('SELECT 1 + 1 FROM DUAL;')->execute(); }