- Add comprehensive health check system with multiple endpoints - Add Prometheus metrics endpoint - Add production logging configurations (5 strategies) - Add complete deployment documentation suite: * QUICKSTART.md - 30-minute deployment guide * DEPLOYMENT_CHECKLIST.md - Printable verification checklist * DEPLOYMENT_WORKFLOW.md - Complete deployment lifecycle * PRODUCTION_DEPLOYMENT.md - Comprehensive technical reference * production-logging.md - Logging configuration guide * ANSIBLE_DEPLOYMENT.md - Infrastructure as Code automation * README.md - Navigation hub * DEPLOYMENT_SUMMARY.md - Executive summary - Add deployment scripts and automation - Add DEPLOYMENT_PLAN.md - Concrete plan for immediate deployment - Update README with production-ready features All production infrastructure is now complete and ready for deployment.
130 lines
5.2 KiB
PHP
130 lines
5.2 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/../../vendor/autoload.php';
|
|
require_once __DIR__ . '/TestLogger.php';
|
|
|
|
use App\Framework\Cache\Cache;
|
|
use App\Framework\Cache\CacheIdentifier;
|
|
use App\Framework\Cache\CacheKey;
|
|
use App\Framework\Cache\CacheItem;
|
|
use App\Framework\Cache\CacheResult;
|
|
use App\Framework\Core\ValueObjects\Duration;
|
|
use App\Framework\DateTime\SystemClock;
|
|
use App\Framework\ErrorAggregation\ErrorAggregator;
|
|
use App\Framework\ErrorAggregation\Storage\InMemoryErrorStorage;
|
|
use App\Framework\ErrorHandling\ErrorHandler;
|
|
use App\Framework\ErrorReporting\ErrorReporter;
|
|
use App\Framework\ErrorReporting\Storage\InMemoryErrorReportStorage;
|
|
use App\Framework\Exception\Core\SystemErrorCode;
|
|
use App\Framework\Exception\FrameworkException;
|
|
use App\Framework\Http\RequestIdGenerator;
|
|
use App\Framework\Http\ResponseEmitter;
|
|
use App\Framework\DI\DefaultContainer;
|
|
use App\Framework\Queue\InMemoryQueue;
|
|
use Tests\Debug\TestLogger;
|
|
|
|
// Setup (same as test)
|
|
$container = new DefaultContainer();
|
|
$emitter = new ResponseEmitter();
|
|
$requestIdGenerator = new RequestIdGenerator();
|
|
$errorStorage = new InMemoryErrorStorage();
|
|
$cache = new class implements Cache {
|
|
private array $data = [];
|
|
public function get(CacheIdentifier ...$identifiers): CacheResult {
|
|
$items = [];
|
|
foreach ($identifiers as $identifier) {
|
|
$keyStr = $identifier->toString();
|
|
$items[] = isset($this->data[$keyStr])
|
|
? $this->data[$keyStr]
|
|
: CacheItem::miss($identifier instanceof CacheKey ? $identifier : CacheKey::fromString($keyStr));
|
|
}
|
|
return CacheResult::fromItems(...$items);
|
|
}
|
|
public function set(CacheItem ...$items): bool {
|
|
foreach ($items as $item) {
|
|
$this->data[$item->key->toString()] = $item;
|
|
}
|
|
return true;
|
|
}
|
|
public function has(CacheIdentifier ...$identifiers): array {
|
|
return array_map(fn($id) => isset($this->data[$id->toString()]), $identifiers);
|
|
}
|
|
public function forget(CacheIdentifier ...$identifiers): bool {
|
|
foreach ($identifiers as $id) { unset($this->data[$id->toString()]); }
|
|
return true;
|
|
}
|
|
public function clear(): bool {
|
|
$this->data = [];
|
|
return true;
|
|
}
|
|
public function remember(CacheKey $key, callable $callback, ?Duration $ttl = null): CacheItem {
|
|
$keyStr = $key->toString();
|
|
if (isset($this->data[$keyStr])) {
|
|
return $this->data[$keyStr];
|
|
}
|
|
$value = $callback();
|
|
$item = $ttl ? CacheItem::forSetting($key, $value, $ttl) : CacheItem::miss($key);
|
|
$this->data[$keyStr] = $item;
|
|
return $item;
|
|
}
|
|
};
|
|
|
|
$clock = new SystemClock();
|
|
$alertQueue = new InMemoryQueue();
|
|
$logger = new TestLogger();
|
|
$errorAggregator = new ErrorAggregator($errorStorage, $cache, $clock, $alertQueue, $logger, 100, 90);
|
|
$errorReportStorage = new InMemoryErrorReportStorage();
|
|
$reportQueue = new InMemoryQueue();
|
|
$errorReporter = new ErrorReporter($errorReportStorage, $clock, null, $reportQueue, false, [], []);
|
|
$errorHandler = new ErrorHandler($emitter, $container, $requestIdGenerator, $errorAggregator, $errorReporter, null, true, null);
|
|
|
|
echo "Creating 3 identical exceptions...\n";
|
|
$exception1 = FrameworkException::create(SystemErrorCode::RESOURCE_EXHAUSTED, 'Memory limit exceeded');
|
|
$exception2 = FrameworkException::create(SystemErrorCode::RESOURCE_EXHAUSTED, 'Memory limit exceeded');
|
|
$exception3 = FrameworkException::create(SystemErrorCode::RESOURCE_EXHAUSTED, 'Memory limit exceeded');
|
|
|
|
echo "Processing exceptions...\n";
|
|
$errorHandler->createHttpResponse($exception1);
|
|
$errorHandler->createHttpResponse($exception2);
|
|
$errorHandler->createHttpResponse($exception3);
|
|
|
|
echo "\nChecking storage:\n";
|
|
$events = $errorStorage->getRecentEvents(10);
|
|
echo "Events stored: " . count($events) . "\n";
|
|
|
|
if (count($events) > 0) {
|
|
echo "First event fingerprint: " . $events[0]->getFingerprint() . "\n";
|
|
if (count($events) > 1) {
|
|
echo "Second event fingerprint: " . $events[1]->getFingerprint() . "\n";
|
|
}
|
|
if (count($events) > 2) {
|
|
echo "Third event fingerprint: " . $events[2]->getFingerprint() . "\n";
|
|
}
|
|
}
|
|
|
|
$patterns = $errorStorage->getActivePatterns(10);
|
|
echo "\nPatterns stored: " . count($patterns) . "\n";
|
|
|
|
// Also check directly via getPatternByFingerprint
|
|
if (count($events) > 0) {
|
|
$fingerprint = $events[0]->getFingerprint();
|
|
$patternByFingerprint = $errorStorage->getPatternByFingerprint($fingerprint);
|
|
echo "Pattern by fingerprint: " . ($patternByFingerprint ? "FOUND (count: {$patternByFingerprint->occurrenceCount})" : "NOT FOUND") . "\n";
|
|
}
|
|
|
|
// Check if patterns exist at all
|
|
$reflection = new \ReflectionClass($errorStorage);
|
|
$property = $reflection->getProperty('patterns');
|
|
$property->setAccessible(true);
|
|
$allPatterns = $property->getValue($errorStorage);
|
|
echo "Total patterns in storage (via reflection): " . count($allPatterns) . "\n";
|
|
|
|
if (count($patterns) > 0) {
|
|
echo "Pattern details:\n";
|
|
echo " - Fingerprint: " . $patterns[0]->fingerprint . "\n";
|
|
echo " - Occurrence count: " . $patterns[0]->occurrenceCount . "\n";
|
|
echo " - Severity: " . $patterns[0]->severity->value . "\n";
|
|
echo " - isActive: " . ($patterns[0]->isActive ? 'true' : 'false') . "\n";
|
|
}
|