Add health monitoring endpoints for Phase 6

- Add /health (liveness) and /ready (readiness) endpoints to worker-api
- /ready checks database connectivity and returns 503 if unavailable
- Update DEPLOYMENT.md with health endpoint documentation
- Update PROGRESS.md to reflect monitoring setup complete

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jedarden 2026-03-24 10:08:11 -04:00
parent 24859669fc
commit 257eb32641
3 changed files with 94 additions and 8 deletions

View file

@ -133,6 +133,44 @@ wrangler pages deploy dist --project-name=aicodebattle
## Monitoring
### Health Endpoints
The Worker API provides two health endpoints for monitoring:
- **Liveness**: `GET /health` or `GET /api/health`
- Returns 200 if the worker process is running
- Use for Kubernetes liveness probes
- **Readiness**: `GET /ready` or `GET /api/ready`
- Returns 200 if database is connected and ready
- Returns 503 if database is unavailable
- Use for Kubernetes readiness probes
Example responses:
```json
// GET /health
{
"success": true,
"data": {
"status": "healthy",
"timestamp": "2024-01-15T10:30:00.000Z"
}
}
// GET /ready (when healthy)
{
"success": true,
"data": {
"status": "ready",
"database": "connected",
"timestamp": "2024-01-15T10:30:00.000Z"
}
}
```
### Cloudflare Monitoring
- Cloudflare Analytics: Available in Cloudflare dashboard
- Worker Logs: `wrangler tail`
- Container Logs: `docker-compose logs -f`

View file

@ -25,20 +25,23 @@
- Cloudflare setup instructions
- Container deployment commands
- Troubleshooting guide
### Remaining Phase 6 Work
- [ ] Cloudflare Pages project creation and deployment
- [x] D1 database schema and migrations
- Complete schema.sql with all tables from plan
- Added: predictions, predictor_stats, map_votes, replay_feedback, series, series_games, seasons
- Added evolution fields to bots table (evolved, island, generation, parent_ids)
- Created migrations/0001_initial.sql for D1 migrations
- Updated wrangler.toml with migrations_dir config
- [x] Monitoring endpoints
- `/health` - Liveness probe (always returns 200)
- `/ready` - Readiness probe (checks database connectivity, returns 503 if unavailable)
- Documented in DEPLOYMENT.md
### Remaining Phase 6 Work (requires Cloudflare account access)
- [ ] Cloudflare Pages project creation and deployment
- [ ] R2 bucket creation and custom domain
- [ ] Worker API deployment via Wrangler
- [ ] Worker API deployment via Wrangler (`wrangler deploy`)
- [ ] DNS configuration
- [ ] Monitoring setup
### Phase 5 Completed ✅

View file

@ -66,9 +66,54 @@ export default {
};
try {
// Health check
// Health check (liveness probe - always returns 200 if process is running)
if (path === '/health' || path === '/api/health') {
return json({ success: true, data: { status: 'healthy' } });
return json({
success: true,
data: {
status: 'healthy',
timestamp: new Date().toISOString(),
},
});
}
// Readiness check (checks if service can handle requests)
if (path === '/ready' || path === '/api/ready') {
try {
// Test database connectivity
const dbResult = await env.DB.prepare('SELECT 1 as ok').first();
const dbHealthy = dbResult?.ok === 1;
if (!dbHealthy) {
return json({
success: false,
data: {
status: 'not_ready',
database: 'error',
timestamp: new Date().toISOString(),
},
}, 503);
}
return json({
success: true,
data: {
status: 'ready',
database: 'connected',
timestamp: new Date().toISOString(),
},
});
} catch (error) {
return json({
success: false,
data: {
status: 'not_ready',
database: 'error',
error: String(error),
timestamp: new Date().toISOString(),
},
}, 503);
}
}
// ============ Job Endpoints (require API key) ============