Skip to content

Health Check

API Gateway provides health check functionality for both the gateway itself and backend services.

External Health Check

The external health check provides an endpoint that can be used to verify the gateway is running.

Configuration

yaml
healthcheck:
  outer:
    enable: true
    path: /healthz
    ok: true

Options

FieldTypeDefaultDescription
enableboolfalseEnable the health check endpoint
pathstring/healthzPath for the health check endpoint
okbooltrueAlways return OK (skip actual checks)

Usage

When enabled, the gateway responds to health check requests:

bash
curl http://localhost:8080/healthz
# Returns: ok

This is useful for:

  • Load balancer health checks
  • Kubernetes liveness/readiness probes
  • Monitoring systems

Example

yaml
healthcheck:
  outer:
    enable: true
    path: /healthz
    ok: true

Kubernetes probe configuration:

yaml
livenessProbe:
  httpGet:
    path: /healthz
    port: 8080
  initialDelaySeconds: 10
  periodSeconds: 5

Internal Health Check

The internal health check monitors backend services to ensure they are available.

Configuration

yaml
healthcheck:
  inner:
    enable: true
    interval: 30
    timeout: 5

Options

FieldTypeDefaultDescription
enableboolfalseEnable internal health checks
intervalint30Check interval in seconds
timeoutint5Request timeout in seconds

Service Health Check

You can configure health checks for individual services:

yaml
routes:
  - name: api
    path: /api
    backend:
      service:
        name: api.example.com
        port: 8080
        health_check:
          enable: true
          method: GET
          path: /health
          status: [200]
          ok: false

Service Health Check Options

FieldTypeDefaultDescription
enableboolfalseEnable health check for this service
methodstringGETHTTP method for health check
pathstring/healthHealth check endpoint path
statusarray[200]Valid HTTP status codes
intervalint30Check interval in seconds
timeoutint5Request timeout in seconds
okboolfalseAlways consider service healthy (skip checks)

Health Check Behavior

When a service health check fails:

  • The gateway may stop routing requests to that service
  • Errors are logged for monitoring
  • The gateway continues to operate for other services

Health Check Examples

Basic Configuration

yaml
healthcheck:
  outer:
    enable: true
    path: /healthz
  inner:
    enable: true
    interval: 30
    timeout: 5

Service-Specific Health Check

yaml
routes:
  - name: user-service
    path: /users
    backend:
      service:
        name: user-service.example.com
        port: 8080
        health_check:
          enable: true
          path: /api/health
          status: [200, 201]

Kubernetes Integration

yaml
# Gateway configuration
healthcheck:
  outer:
    enable: true
    path: /healthz

---
# Kubernetes deployment
apiVersion: apps/v1
kind: Deployment
metadata:
  name: api-gateway
spec:
  template:
    spec:
      containers:
      - name: api-gateway
        image: gozoox/api-gateway:latest
        livenessProbe:
          httpGet:
            path: /healthz
            port: 8080
          initialDelaySeconds: 10
          periodSeconds: 5
        readinessProbe:
          httpGet:
            path: /healthz
            port: 8080
          initialDelaySeconds: 5
          periodSeconds: 3

Monitoring

Health check status can be monitored through:

  • Gateway logs
  • External monitoring systems (Prometheus, etc.)
  • Kubernetes events

Best Practices

  1. Use Simple Endpoints: Keep health check endpoints lightweight
  2. Appropriate Intervals: Balance between responsiveness and overhead
  3. Timeout Configuration: Set reasonable timeouts to avoid hanging requests
  4. Status Codes: Use appropriate HTTP status codes for health status
  5. Separate Endpoints: Use different endpoints for liveness and readiness if needed

Next Steps

Released under the MIT License.