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.
This commit is contained in:
2025-10-25 19:18:37 +02:00
parent caa85db796
commit fc3d7e6357
83016 changed files with 378904 additions and 20919 deletions

View File

@@ -0,0 +1,181 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Framework\FeatureFlags;
use App\Framework\FeatureFlags\FeatureFlag;
use App\Framework\FeatureFlags\FeatureFlagContext;
use App\Framework\FeatureFlags\FeatureFlagManager;
use App\Framework\FeatureFlags\FeatureFlagRepository;
use App\Framework\FeatureFlags\FeatureFlagStatus;
use App\Framework\Core\ValueObjects\Timestamp;
describe('FeatureFlagManager', function () {
beforeEach(function () {
// Create in-memory repository for testing
$this->repository = new class implements FeatureFlagRepository {
private array $flags = [];
public function find(string $name): ?FeatureFlag
{
return $this->flags[$name] ?? null;
}
public function findAll(): array
{
return array_values($this->flags);
}
public function save(FeatureFlag $flag): void
{
$this->flags[$flag->name] = $flag;
}
public function delete(string $name): void
{
unset($this->flags[$name]);
}
public function exists(string $name): bool
{
return isset($this->flags[$name]);
}
};
$this->manager = new FeatureFlagManager($this->repository);
});
it('enables a feature flag', function () {
$this->manager->enable('test-feature', 'Test description');
expect($this->manager->isEnabled('test-feature'))->toBeTrue();
expect($this->manager->exists('test-feature'))->toBeTrue();
});
it('disables a feature flag', function () {
$this->manager->enable('test-feature');
$this->manager->disable('test-feature');
expect($this->manager->isDisabled('test-feature'))->toBeTrue();
});
it('returns false for non-existent flag', function () {
expect($this->manager->isEnabled('non-existent'))->toBeFalse();
});
it('sets conditional feature flag', function () {
$this->manager->setConditional('user-feature', ['user_id' => [1, 2, 3]]);
$matchingContext = (new FeatureFlagContext())->withUserId('2');
$nonMatchingContext = (new FeatureFlagContext())->withUserId('99');
expect($this->manager->isEnabled('user-feature', $matchingContext))->toBeTrue();
expect($this->manager->isEnabled('user-feature', $nonMatchingContext))->toBeFalse();
});
it('sets percentage rollout', function () {
$this->manager->setPercentageRollout('rollout-feature', 50);
$flag = $this->manager->getFlag('rollout-feature');
expect($flag)->not->toBeNull();
expect($flag->conditions)->toHaveKey('percentage');
expect($flag->conditions['percentage'])->toBe(50);
});
it('validates percentage range', function () {
expect(fn () => $this->manager->setPercentageRollout('invalid', 150))
->toThrow(\InvalidArgumentException::class);
expect(fn () => $this->manager->setPercentageRollout('invalid', -10))
->toThrow(\InvalidArgumentException::class);
});
it('sets user-specific flag', function () {
$this->manager->setForUsers('user-only', [1, 2, 3]);
$flag = $this->manager->getFlag('user-only');
expect($flag->conditions)->toHaveKey('user_id');
expect($flag->conditions['user_id'])->toBe([1, 2, 3]);
});
it('sets environment-specific flag', function () {
$this->manager->setForEnvironment('env-feature', 'production');
$prodContext = (new FeatureFlagContext())->withEnvironment('production');
$devContext = (new FeatureFlagContext())->withEnvironment('development');
expect($this->manager->isEnabled('env-feature', $prodContext))->toBeTrue();
expect($this->manager->isEnabled('env-feature', $devContext))->toBeFalse();
});
it('sets expiration', function () {
$this->manager->enable('temp-feature');
$expiry = Timestamp::fromTimestamp(time() + 3600);
$this->manager->setExpiration('temp-feature', $expiry);
$flag = $this->manager->getFlag('temp-feature');
expect($flag->expiresAt)->toBe($expiry);
});
it('throws exception when setting expiration on non-existent flag', function () {
$expiry = Timestamp::fromTimestamp(time() + 3600);
expect(fn () => $this->manager->setExpiration('non-existent', $expiry))
->toThrow(\InvalidArgumentException::class);
});
it('deletes a feature flag', function () {
$this->manager->enable('delete-me');
expect($this->manager->exists('delete-me'))->toBeTrue();
$this->manager->deleteFlag('delete-me');
expect($this->manager->exists('delete-me'))->toBeFalse();
});
it('gets all feature flags', function () {
$this->manager->enable('flag1');
$this->manager->enable('flag2');
$this->manager->disable('flag3');
$allFlags = $this->manager->getAllFlags();
expect($allFlags)->toHaveCount(3);
});
it('generates status summary', function () {
$this->manager->enable('enabled1');
$this->manager->enable('enabled2');
$this->manager->disable('disabled1');
$this->manager->setConditional('conditional1', ['user_id' => [1]]);
$summary = $this->manager->getStatusSummary();
expect($summary['total'])->toBe(4);
expect($summary['enabled'])->toBe(2);
expect($summary['disabled'])->toBe(1);
expect($summary['conditional'])->toBe(1);
});
it('uses default context when none provided', function () {
$defaultContext = (new FeatureFlagContext())->withUserId('5');
$manager = new FeatureFlagManager($this->repository, $defaultContext);
$manager->setConditional('user-feature', ['user_id' => [5, 6, 7]]);
// Should use default context
expect($manager->isEnabled('user-feature'))->toBeTrue();
});
it('counts expired flags in summary', function () {
$this->manager->enable('expired-feature');
$pastExpiry = Timestamp::fromTimestamp(time() - 3600);
$this->manager->setExpiration('expired-feature', $pastExpiry);
$summary = $this->manager->getStatusSummary();
expect($summary['expired'])->toBe(1);
});
});

View File

@@ -0,0 +1,150 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Framework\FeatureFlags;
use App\Framework\FeatureFlags\FeatureFlag;
use App\Framework\FeatureFlags\FeatureFlagContext;
use App\Framework\FeatureFlags\FeatureFlagStatus;
use App\Framework\Core\ValueObjects\Timestamp;
describe('FeatureFlag', function () {
it('creates enabled feature flag', function () {
$flag = new FeatureFlag(
name: 'test-feature',
status: FeatureFlagStatus::ENABLED,
description: 'Test feature'
);
expect($flag->isEnabled())->toBeTrue();
expect($flag->name)->toBe('test-feature');
expect($flag->description)->toBe('Test feature');
});
it('creates disabled feature flag', function () {
$flag = new FeatureFlag(
name: 'test-feature',
status: FeatureFlagStatus::DISABLED
);
expect($flag->isEnabled())->toBeFalse();
});
it('checks expiration', function () {
$pastTime = Timestamp::fromTimestamp(time() - 3600);
$flag = new FeatureFlag(
name: 'expired-feature',
status: FeatureFlagStatus::ENABLED,
expiresAt: $pastTime
);
expect($flag->isEnabled())->toBeFalse();
});
it('enables flag for matching context', function () {
$flag = new FeatureFlag(
name: 'user-feature',
status: FeatureFlagStatus::CONDITIONAL,
conditions: ['user_id' => [1, 2, 3]]
);
$context = (new FeatureFlagContext())->withUserId('2');
expect($flag->isEnabledForContext($context))->toBeTrue();
});
it('disables flag for non-matching context', function () {
$flag = new FeatureFlag(
name: 'user-feature',
status: FeatureFlagStatus::CONDITIONAL,
conditions: ['user_id' => [1, 2, 3]]
);
$context = (new FeatureFlagContext())->withUserId('99');
expect($flag->isEnabledForContext($context))->toBeFalse();
});
it('handles percentage rollout', function () {
$flag = new FeatureFlag(
name: 'rollout-feature',
status: FeatureFlagStatus::CONDITIONAL,
conditions: ['percentage' => 50]
);
// Test with multiple user IDs to verify distribution
$enabledCount = 0;
for ($userId = 1; $userId <= 100; $userId++) {
$context = (new FeatureFlagContext())->withUserId((string) $userId);
if ($flag->isEnabledForContext($context)) {
$enabledCount++;
}
}
// Should be approximately 50% (allow some variance)
expect($enabledCount)->toBeGreaterThan(30);
expect($enabledCount)->toBeLessThan(70);
});
it('creates immutable copy with new status', function () {
$original = new FeatureFlag(
name: 'test-feature',
status: FeatureFlagStatus::DISABLED
);
$updated = $original->withStatus(FeatureFlagStatus::ENABLED);
expect($original->status)->toBe(FeatureFlagStatus::DISABLED);
expect($updated->status)->toBe(FeatureFlagStatus::ENABLED);
expect($original)->not->toBe($updated);
});
it('creates immutable copy with new conditions', function () {
$original = new FeatureFlag(
name: 'test-feature',
status: FeatureFlagStatus::CONDITIONAL
);
$updated = $original->withConditions(['user_id' => [1, 2]]);
expect($original->conditions)->toBeEmpty();
expect($updated->conditions)->toBe(['user_id' => [1, 2]]);
});
it('creates immutable copy with expiration', function () {
$original = new FeatureFlag(
name: 'test-feature',
status: FeatureFlagStatus::ENABLED
);
$expiry = Timestamp::fromTimestamp(time() + 3600);
$updated = $original->withExpiration($expiry);
expect($original->expiresAt)->toBeNull();
expect($updated->expiresAt)->toBe($expiry);
});
it('handles multiple conditions', function () {
$flag = new FeatureFlag(
name: 'multi-condition',
status: FeatureFlagStatus::CONDITIONAL,
conditions: [
'environment' => 'production',
'user_id' => [1, 2, 3]
]
);
$matchingContext = (new FeatureFlagContext())
->withEnvironment('production')
->withUserId('2');
$nonMatchingContext = (new FeatureFlagContext())
->withEnvironment('development')
->withUserId('2');
expect($flag->isEnabledForContext($matchingContext))->toBeTrue();
expect($flag->isEnabledForContext($nonMatchingContext))->toBeFalse();
});
});