Files
Luca Sacchi Ricciardi 23a9ffe443 feat(lab-03): complete Phase 4 - Compute & EC2 lab
Phase Plans (5 files):
- 04-RESEARCH.md: Domain research on Docker limits, healthchecks, EC2 parallels
- 04-VALIDATION.md: Success criteria and validation strategy
- 04-01-PLAN.md: Test infrastructure (RED phase)
- 04-02-PLAN.md: Diátxis documentation
- 04-03-PLAN.md: Infrastructure implementation (GREEN phase)

Test Scripts (6 files, 1300+ lines):
- 01-resource-limits-test.sh: Validate INF-03 compliance
- 02-healthcheck-test.sh: Validate healthcheck configuration
- 03-enforcement-test.sh: Verify resource limits with docker stats
- 04-verify-infrastructure.sh: Infrastructure verification
- 99-final-verification.sh: End-to-end student verification
- run-all-tests.sh: Test orchestration with fail-fast
- quick-test.sh: Fast validation (<30s)

Documentation (11 files, 2500+ lines):
Tutorials (3):
- 01-set-resource-limits.md: EC2 instance types, Docker limits syntax
- 02-implement-healthchecks.md: ELB health check parallels
- 03-dependencies-with-health.md: depends_on with service_healthy

How-to Guides (4):
- check-resource-usage.md: docker stats monitoring
- test-limits-enforcement.md: Stress testing CPU/memory
- custom-healthcheck.md: HTTP, TCP, database healthchecks
- instance-type-mapping.md: Docker limits → EC2 mapping

Reference (3):
- compose-resources-syntax.md: Complete deploy.resources reference
- healthcheck-syntax.md: All healthcheck parameters
- ec2-instance-mapping.md: Instance type mapping table

Explanation (1):
- compute-ec2-parallels.md: Container=EC2, Limits=Instance Type, Healthcheck=ELB

Infrastructure:
- docker-compose.yml: 5 services (web, app, worker, db, stress-test)
  All services: INF-03 compliant (cpus + memory limits)
  All services: healthcheck configured
  EC2 parallels: t2.nano, t2.micro, t2.small, t2.medium, m5.large
- Dockerfile: Alpine 3.19 + stress tools + non-root user

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-03 15:16:58 +02:00

121 lines
2.0 KiB
Markdown

# How-to: Scrivere Healthchecks Personalizzati
Come creare healthchecks custom per diversi tipi di servizi.
## Pattern Comuni
### HTTP Healthcheck
```yaml
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost/health || exit 1"]
interval: 15s
timeout: 3s
retries: 3
```
### TCP Port Check
```yaml
healthcheck:
test: ["CMD-SHELL", "nc -z localhost 8080 || exit 1"]
interval: 10s
timeout: 2s
retries: 3
```
### File Existence Check
```yaml
healthcheck:
test: ["CMD-SHELL", "test -f /var/run/app/ready || exit 1"]
interval: 5s
timeout: 1s
retries: 5
```
### Database Connection
```yaml
healthcheck:
test: ["CMD-SHELL", "mysqladmin ping -h localhost || exit 1"]
interval: 10s
timeout: 5s
retries: 5
```
### Redis Check
```yaml
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 3s
retries: 3
```
### Python Script Check
```yaml
healthcheck:
test: ["CMD-SHELL", "python /app/healthcheck.py || exit 1"]
interval: 30s
timeout: 10s
retries: 3
```
## Best Practices
### 1. Check Leggeri
```yaml
# ✓ GOOD - pagina leggera
test: ["CMD", "wget", "--spider", "-q", "http://localhost/health"]
# ✗ AVOID - pagina pesante
test: ["CMD", "wget", "--spider", "-q", "http://localhost/big-data"]
```
### 2. Timeout Appropriati
```yaml
# ✓ GOOD - timeout proporzionato all'interval
interval: 10s
timeout: 3s
# ✗ AVOID - timeout troppo lungo
interval: 10s
timeout: 30s # Riduce frequenza dei check
```
### 3. Retries Adeguati
```yaml
# ✓ GOOD - più retries per servizi lenti (database)
healthcheck:
retries: 5
# ✓ GOOD - meno retries per servizi veloci (web)
healthcheck:
retries: 3
```
## Debugging
### Testare manualmente
```bash
docker exec lab03-web wget --spider -q http://localhost/health
echo $? # 0 = success, !0 = failure
```
### Vedere log healthcheck
```bash
docker inspect lab03-web --format '{{range .State.Health.Log}}{{.Output}} {{end}}'
```
### Reset health status
```bash
docker restart lab03-web
```
## Vedi Anche
- Tutorial: Implementare Healthchecks
- Reference: Healthcheck Syntax