Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
115 changed files
with
750 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
framework: | ||
default_locale: en | ||
translator: | ||
default_path: '%kernel.project_dir%/translations' | ||
fallbacks: | ||
- en | ||
# providers: | ||
# crowdin: | ||
# dsn: '%env(CROWDIN_DSN)%' | ||
# loco: | ||
# dsn: '%env(LOCO_DSN)%' | ||
# lokalise: | ||
# dsn: '%env(LOKALISE_DSN)%' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
-- MariaDB dump 10.19 Distrib 10.7.3-MariaDB, for debian-linux-gnu (x86_64) | ||
-- | ||
-- Host: localhost Database: uuid_example | ||
-- ------------------------------------------------------ | ||
-- Server version 10.7.3-MariaDB-1:10.7.3+maria~focal | ||
|
||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; | ||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; | ||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; | ||
/*!40101 SET NAMES utf8mb4 */; | ||
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; | ||
/*!40103 SET TIME_ZONE='+00:00' */; | ||
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; | ||
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; | ||
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; | ||
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; | ||
|
||
CREATE SCHEMA IF NOT EXISTS cushon_health_test; | ||
|
||
CREATE USER 'cushon_read'@'%'; | ||
CREATE USER 'cushon_write'@'%'; | ||
|
||
GRANT ALL PRIVILEGES ON `cushon_health_test`.* TO 'cushon_write'@'%' IDENTIFIED BY 'cushon_health_writer'; | ||
GRANT SELECT ON `cushon_health_test`.* TO 'cushon_read'@'%' IDENTIFIED BY 'cushon_health_reader'; | ||
|
||
FLUSH PRIVILEGES; | ||
|
||
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; | ||
|
||
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; | ||
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; | ||
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; | ||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; | ||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; | ||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; | ||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; | ||
|
||
-- Dump completed on 2022-03-23 15:47:25 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\DBAL\Types\Types; | ||
use Doctrine\Migrations\AbstractMigration; | ||
use Ramsey\Uuid\Doctrine\UuidBinaryType; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20220530155854 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Create a simple table for health checks'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
$health = $schema->createTable('health'); | ||
$health->addColumn( | ||
'last_checked', | ||
Types::DATETIME_IMMUTABLE | ||
); | ||
|
||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$schema->dropTable('health'); | ||
} | ||
} |
31 changes: 25 additions & 6 deletions
31
app/src/ApplicationHealth/DependencyCheck/DatabaseCheck.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\ApplicationHealth\DependencyCheck; | ||
|
||
use App\ApplicationHealth\DependencyCheck\DatabaseCheck\HealthDependencyRepository; | ||
use App\ApplicationHealth\DependencyCheck\DatabaseCheck\DatabaseUserCheck; | ||
use App\ApplicationHealth\DependencyCheck\DatabaseCheck\Exception\NoDatabaseChecksProvided; | ||
use Cushon\HealthBundle\ApplicationHealth\DependencyCheck; | ||
use Cushon\HealthBundle\ApplicationHealth\HealthReport\DependencyStatus; | ||
use Ds\Set; | ||
use Generator; | ||
|
||
final class DatabaseCheck implements DependencyCheck | ||
{ | ||
/** | ||
* @var Set<DatabaseUserCheck> | ||
*/ | ||
private Set $dependencyRepositories; | ||
|
||
/** | ||
* @param HealthDependencyRepository ...$dependencyRepositories | ||
* @param iterable<DatabaseUserCheck> $dependencyRepositories | ||
*/ | ||
public function __construct(HealthDependencyRepository ...$dependencyRepositories) | ||
public function __construct(iterable $dependencyRepositories) | ||
{ | ||
$this->dependencyRepositories = new Set($dependencyRepositories); | ||
$this->dependencyRepositories = new Set(); | ||
foreach ($dependencyRepositories as $dependencyRepository) { | ||
$this->addDatabaseUserCheck($dependencyRepository); | ||
} | ||
|
||
if (!$this->dependencyRepositories->count()) { | ||
throw NoDatabaseChecksProvided::create(); | ||
} | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function check(): Generator | ||
{ | ||
/** @var HealthDependencyRepository $dependencyRepository */ | ||
foreach ($this->dependencyRepositories as $dependencyRepository) { | ||
yield $dependencyRepository->checkUser(); | ||
} | ||
} | ||
|
||
/** | ||
* @param DatabaseUserCheck $databaseUserChecks | ||
* @return void | ||
*/ | ||
private function addDatabaseUserCheck(DatabaseUserCheck $databaseUserChecks): void | ||
{ | ||
$this->dependencyRepositories->add($databaseUserChecks); | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
...abaseCheck/HealthDependencyRepository.php → ...Check/DatabaseCheck/DatabaseUserCheck.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...rc/ApplicationHealth/DependencyCheck/DatabaseCheck/Exception/NoDatabaseChecksProvided.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace App\ApplicationHealth\DependencyCheck\DatabaseCheck\Exception; | ||
|
||
use InvalidArgumentException; | ||
|
||
final class NoDatabaseChecksProvided extends InvalidArgumentException | ||
{ | ||
/** | ||
* @return static | ||
*/ | ||
public static function create(): self | ||
{ | ||
return new self('No database checks were provided'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Repository\DatabaseCheck; | ||
|
||
use App\ApplicationHealth\DependencyCheck\DatabaseCheck\DatabaseUserCheck; | ||
use Cushon\HealthBundle\ApplicationHealth\HealthReport\DependencyStatus; | ||
use Cushon\HealthBundle\ApplicationHealth\HealthReport\DependencyStatus\SimpleStatus; | ||
use Doctrine\DBAL\Connection; | ||
use Doctrine\DBAL\Exception; | ||
|
||
final class ReadUserCheck implements DatabaseUserCheck | ||
{ | ||
/** | ||
* @var Connection | ||
*/ | ||
private Connection $connection; | ||
|
||
/** | ||
* @param Connection $readConnection | ||
*/ | ||
public function __construct(Connection $readConnection) | ||
{ | ||
$this->connection = $readConnection; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function checkUser(): DependencyStatus | ||
{ | ||
$healthy = false; | ||
try { | ||
$this->connection->createQueryBuilder() | ||
->select('last_checked') | ||
->from('health') | ||
->executeQuery(); | ||
$healthy = true; | ||
$info = null; | ||
} catch (Exception $e) { | ||
$info = $e->getMessage(); | ||
} | ||
|
||
return new SimpleStatus('DB read user', $healthy, $info); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Repository\DatabaseCheck; | ||
|
||
use App\ApplicationHealth\DependencyCheck\DatabaseCheck\DatabaseUserCheck; | ||
use Cushon\HealthBundle\ApplicationHealth\HealthReport\DependencyStatus; | ||
use Cushon\HealthBundle\ApplicationHealth\HealthReport\DependencyStatus\SimpleStatus; | ||
use DateTimeImmutable; | ||
use Doctrine\DBAL\Connection; | ||
use Doctrine\DBAL\Exception; | ||
use Doctrine\DBAL\Types\Types; | ||
|
||
final class WriteUserCheck implements DatabaseUserCheck | ||
{ | ||
/** | ||
* @var Connection | ||
*/ | ||
private Connection $connection; | ||
|
||
/** | ||
* @param Connection $writeConnection | ||
*/ | ||
public function __construct(Connection $writeConnection) | ||
{ | ||
$this->connection = $writeConnection; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function checkUser(): DependencyStatus | ||
{ | ||
$health = false; | ||
try { | ||
$this->connection->createQueryBuilder() | ||
->insert('health') | ||
->setValue('last_checked', ':now') | ||
->setParameter('now', new DateTimeImmutable(), Types::DATETIME_IMMUTABLE) | ||
->executeStatement(); | ||
$health = true; | ||
$info = null; | ||
} catch (Exception $e) { | ||
$info = $e->getMessage(); | ||
} | ||
|
||
return new SimpleStatus('DB write user', $health, $info); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.