Skip to main content

Auto-Discovery API Tests

Test results for the Auto-Discovery API that allows backends to register themselves dynamically.

Test Date: 2025-12-08 API Port: 8081

API Endpoints

EndpointMethodDescription
/healthGETHealth check with version and backend count
/api/v1/registerPOSTRegister a new backend
/api/v1/heartbeat/:idPOSTUpdate backend heartbeat
/api/v1/backendsGETList all registered backends
/api/v1/backends/:idGETGet specific backend details
/api/v1/backends/:idDELETEDeregister a backend

Test Results

1. Health Check

Request:

curl -s http://34.246.117.138:8081/health

Response:

{
"status": "ok",
"version": "0.2.0",
"registered_backends": 10
}

Status: OK


2. Backend Registration

Request:

curl -s -X POST http://34.246.117.138:8081/api/v1/register \
-H "Content-Type: application/json" \
-d '{
"id": "pop-gru",
"app": "gru.pop",
"region": "sa",
"ip": "10.50.1.1",
"port": 80
}'

Response:

{
"id": "pop-gru",
"registered": true,
"message": "Backend registered successfully"
}

All Registrations:

IDAppRegionIPPortResult
pop-grugru.popsa10.50.1.180OK
pop-iadiad.popus10.50.2.180OK
pop-ordord.popus10.50.2.280OK
pop-laxlax.popus10.50.2.380OK
pop-lhrlhr.popeu10.50.3.180OK
pop-frafra.popeu10.50.3.280OK
pop-cdgcdg.popeu10.50.3.380OK
pop-nrtnrt.popap10.50.4.180OK
pop-sinsin.popap10.50.4.280OK
pop-sydsyd.popap10.50.4.380OK

Status: 10/10 registrations successful


3. List Backends

Request:

curl -s http://34.246.117.138:8081/api/v1/backends

Response:

{
"backends": [
{
"id": "pop-gru",
"app": "gru.pop",
"region": "sa",
"ip": "10.50.1.1",
"port": 80,
"healthy": true,
"last_heartbeat_secs": 5,
"registered_secs": 120
},
{
"id": "pop-iad",
"app": "iad.pop",
"region": "us",
"ip": "10.50.2.1",
"port": 80,
"healthy": true,
"last_heartbeat_secs": 5,
"registered_secs": 118
}
// ... more backends
],
"total": 10
}

Status: OK - All 10 backends listed


4. Get Single Backend

Request:

curl -s http://34.246.117.138:8081/api/v1/backends/pop-gru

Response:

{
"id": "pop-gru",
"app": "gru.pop",
"region": "sa",
"ip": "10.50.1.1",
"port": 80,
"healthy": true,
"last_heartbeat_secs": 10,
"registered_secs": 125
}

Status: OK


5. Heartbeat Update

Request:

curl -s -X POST http://34.246.117.138:8081/api/v1/heartbeat/pop-gru

Response:

{
"id": "pop-gru",
"status": "ok"
}

Status: OK - Heartbeat updated, last_heartbeat_secs reset to 0


6. Backend Deregistration

Request:

curl -s -X DELETE http://34.246.117.138:8081/api/v1/backends/test-backend

Response:

{
"deregistered": true,
"id": "test-backend"
}

Status: OK


Registration Payload Schema

Required Fields

FieldTypeDescriptionExample
idstringUnique backend identifier"pop-gru"
appstringApplication name (used for DNS)"gru.pop"
regionstringRegion code (sa, us, eu, ap)"sa"
ipstringBackend IP address"10.50.1.1"
portnumberBackend port80

Optional Fields (with defaults)

FieldTypeDefaultDescription
countrystringderivedISO country code
weightnumber2Load balancing weight (1-10)
soft_limitnumber100Comfortable connection count
hard_limitnumber150Maximum connections

Example Full Payload

{
"id": "my-backend-1",
"app": "myapp",
"region": "eu",
"country": "DE",
"ip": "10.50.3.1",
"port": 8080,
"weight": 5,
"soft_limit": 200,
"hard_limit": 300
}

Health Management

Heartbeat TTL

Backends are marked as unhealthy if they don't send a heartbeat within the TTL period.

SettingDefaultEnvironment Variable
Heartbeat TTL60 secondsEDGEPROXY_HEARTBEAT_TTL_SECS

Automatic Cleanup

  • Backends that miss heartbeat are marked healthy: false
  • Background task removes stale backends periodically
  • Unhealthy backends are excluded from load balancing

Keeping Backends Healthy

# Simple heartbeat loop (every 30 seconds)
while true; do
curl -s -X POST http://hub:8081/api/v1/heartbeat/my-backend-1
sleep 30
done

Integration with DNS

Backends registered via API can be resolved through DNS:

# Register backend with app name
curl -X POST http://hub:8081/api/v1/register \
-H "Content-Type: application/json" \
-d '{"id":"my-eu-1","app":"myservice","region":"eu","ip":"10.50.3.1","port":8080}'

# Resolve via DNS
dig @hub -p 5353 myservice.internal +short
# Returns: 10.50.3.1

Note: API-registered backends are stored in memory (DashMap). For DNS resolution, backends should also be in routing.db.


Error Responses

400 Bad Request

{
"error": "Missing required field: id"
}

404 Not Found

{
"error": "Backend not found",
"id": "unknown-backend"
}

409 Conflict

{
"error": "Backend already exists",
"id": "existing-backend"
}

Monitoring Registered Backends

Via API

# Count backends
curl -s http://hub:8081/api/v1/backends | jq '.total'

# List healthy backends
curl -s http://hub:8081/api/v1/backends | jq '.backends[] | select(.healthy==true) | .id'

# Find backends by region
curl -s http://hub:8081/api/v1/backends | jq '.backends[] | select(.region=="eu")'

Via Logs

# Watch registration events
sudo journalctl -u edgeproxy -f | grep -i "register\|heartbeat"

Test Summary

TestResult
Health CheckOK
Registration (10 backends)OK
List BackendsOK
Get Single BackendOK
Heartbeat UpdateOK
DeregistrationOK

Total: All API tests passing