Add readiness endpoint for graceful shutdown coordination
Implement readiness endpoint (/api/ready) that returns:
- {"ready":true} (HTTP 200) during normal operation
- {"ready":false} (HTTP 503) during graceful shutdown
Key changes:
- Added readiness context to control readiness state
- Modified server.NewServer() to accept readiness context
- Implemented handleReadiness() with context-aware logic
- Updated cmd/server/main.go to manage readiness state
- Readiness set to false when shutdown signal received
- Updated test script to validate readiness behavior
- Added comprehensive documentation for readiness endpoint
This allows Kubernetes/service meshes to stop routing traffic
to the pod during graceful shutdown while allowing existing
requests to complete. Health endpoint continues to return
happy status during shutdown for proper orchestration.
This commit is contained in:
32
AGENTS.md
32
AGENTS.md
@@ -225,9 +225,28 @@ curl http://127.0.0.1:9090/api/health
|
||||
```bash
|
||||
# Check health endpoint
|
||||
curl -s http://localhost:8080/api/health
|
||||
|
||||
# Check readiness endpoint
|
||||
curl -s http://localhost:8080/api/ready
|
||||
```
|
||||
|
||||
**Expected response:** `{"status":"healthy"}`
|
||||
**Expected responses:**
|
||||
- Health: `{"status":"healthy"}`
|
||||
- Readiness (normal): `{"ready":true}`
|
||||
- Readiness (during shutdown): `{"ready":false}` with HTTP 503
|
||||
|
||||
**Endpoint Differences:**
|
||||
- **Health endpoint** (`/api/health`): Indicates if the application is running and functional
|
||||
- **Readiness endpoint** (`/api/ready`): Indicates if the application is ready to accept traffic
|
||||
|
||||
**Use Cases:**
|
||||
- **Health**: Used by load balancers to check if the app is alive
|
||||
- **Readiness**: Used by Kubernetes/service meshes to determine if the app can accept new requests
|
||||
|
||||
**During Graceful Shutdown:**
|
||||
- Health endpoint continues to return `{"status":"healthy"}`
|
||||
- Readiness endpoint returns `{"ready":false}` with HTTP 503 Service Unavailable
|
||||
- This allows existing requests to complete while preventing new requests
|
||||
|
||||
### Stopping the Server
|
||||
|
||||
@@ -276,6 +295,17 @@ GET /api/health
|
||||
{"status":"healthy"}
|
||||
```
|
||||
|
||||
### Readiness Check
|
||||
```http
|
||||
GET /api/ready
|
||||
```
|
||||
|
||||
**Responses:**
|
||||
- Normal operation: `{"ready":true}` (HTTP 200)
|
||||
- During shutdown: `{"ready":false}` (HTTP 503 Service Unavailable)
|
||||
|
||||
**Purpose:** Indicates whether the server is ready to accept new requests. Returns false during graceful shutdown to allow existing requests to complete while preventing new ones.
|
||||
|
||||
### Greet Service
|
||||
```http
|
||||
GET /api/v1/greet/
|
||||
|
||||
Reference in New Issue
Block a user