Files
michaelschiemer/tests/debug/test-error-aggregator-debug.php
Michael Schiemer fc3d7e6357 feat(Production): Complete production deployment infrastructure
- 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.
2025-10-25 19:18:37 +02:00

164 lines
5.2 KiB
PHP

<?php
declare(strict_types=1);
require __DIR__ . '/../../vendor/autoload.php';
use App\Framework\ErrorAggregation\ErrorAggregator;
use App\Framework\ErrorAggregation\Storage\InMemoryErrorStorage;
use App\Framework\Queue\InMemoryQueue;
use App\Framework\Cache\Cache;
use App\Framework\Cache\CacheIdentifier;
use App\Framework\Cache\CacheItem;
use App\Framework\Cache\CacheKey;
use App\Framework\Cache\CacheResult;
use App\Framework\Core\ValueObjects\Duration;
use App\Framework\DateTime\Clock;
use App\Framework\Core\ValueObjects\Timestamp;
use App\Framework\Exception\Core\DatabaseErrorCode;
use App\Framework\Exception\FrameworkException;
use App\Framework\Exception\ExceptionContext;
use App\Framework\Exception\RequestContext;
use App\Framework\Exception\SystemContext;
use App\Framework\Exception\ErrorHandlerContext;
// Create test cache
$cache = new class implements Cache {
private array $data = [];
public function get(CacheIdentifier ...$identifiers): CacheResult
{
$hits = [];
$misses = [];
foreach ($identifiers as $identifier) {
$key = $identifier->toString();
if (isset($this->data[$key])) {
$value = $this->data[$key];
$hits[$key] = $value instanceof CacheItem ? $value->value : $value;
} else {
$misses[] = $key;
}
}
return new CacheResult($hits, $misses);
}
public function set(CacheItem ...$items): bool
{
foreach ($items as $item) {
$this->data[$item->key->toString()] = $item;
}
return true;
}
public function has(CacheIdentifier ...$identifiers): array
{
$result = [];
foreach ($identifiers as $identifier) {
$key = (string) $identifier;
$result[$key] = isset($this->data[$key]);
}
return $result;
}
public function forget(CacheIdentifier ...$identifiers): bool
{
foreach ($identifiers as $identifier) {
$key = (string) $identifier;
unset($this->data[$key]);
}
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 = CacheItem::forSetting($key, $value, $ttl);
$this->data[$keyStr] = $item;
return $item;
}
};
// Create test clock
$clock = new class implements Clock {
public function now(): \DateTimeImmutable { return new \DateTimeImmutable(); }
public function fromTimestamp(Timestamp $timestamp): \DateTimeImmutable { return $timestamp->toDateTime(); }
public function fromString(string $dateTime, ?string $format = null): \DateTimeImmutable { return new \DateTimeImmutable($dateTime); }
public function today(): \DateTimeImmutable { return new \DateTimeImmutable('today'); }
public function yesterday(): \DateTimeImmutable { return new \DateTimeImmutable('yesterday'); }
public function tomorrow(): \DateTimeImmutable { return new \DateTimeImmutable('tomorrow'); }
public function time(): Timestamp { return Timestamp::now(); }
};
echo "Creating ErrorAggregator...\n";
$storage = new InMemoryErrorStorage();
$alertQueue = new InMemoryQueue();
$errorAggregator = new ErrorAggregator(
storage: $storage,
cache: $cache,
clock: $clock,
alertQueue: $alertQueue
);
echo "Creating exception and context...\n";
$exception = FrameworkException::create(
DatabaseErrorCode::QUERY_FAILED,
'Test database query failed'
);
$exceptionContext = ExceptionContext::empty()
->withOperation('test_operation', 'TestComponent')
->withData(['test_key' => 'test_value']);
$requestContext = RequestContext::fromGlobals();
$systemContext = SystemContext::current();
$errorHandlerContext = ErrorHandlerContext::create(
$exceptionContext,
$requestContext,
$systemContext,
['http_status' => 500]
);
echo "Processing error...\n";
try {
$errorAggregator->processError($errorHandlerContext);
echo "SUCCESS: Error processed without exception\n";
} catch (\Throwable $e) {
echo "ERROR processing error: " . $e->getMessage() . "\n";
echo "Stack trace:\n" . $e->getTraceAsString() . "\n";
}
echo "\nGetting recent events...\n";
$recentEvents = $errorAggregator->getRecentEvents(10);
echo "Recent events count: " . count($recentEvents) . "\n";
echo "\nGetting active patterns...\n";
$activePatterns = $errorAggregator->getActivePatterns(10);
echo "Active patterns count: " . count($activePatterns) . "\n";
if (count($recentEvents) > 0) {
echo "\nFirst event details:\n";
$event = $recentEvents[0];
echo " Error message: " . $event->errorMessage . "\n";
echo " Component: " . $event->component . "\n";
echo " Operation: " . $event->operation . "\n";
}
if (count($activePatterns) > 0) {
echo "\nFirst pattern details:\n";
$pattern = $activePatterns[0];
echo " Component: " . $pattern->component . "\n";
echo " Occurrence count: " . $pattern->occurrenceCount . "\n";
}