Operating SAGE in Production

The repository’s docs/operations.md is the full runbook. This page covers what you need to run SAGE safely.

Ports

SAGE binds separate listeners on purpose. The split is a security boundary.

ListenerConfig keyDefaultWho should reach it
Relays and healthrouter_config.port3069Clients, through your edge
Admin APIadmin_config.addrlocalhost:9091Operators only
Prometheusmetrics_config.prometheus_addr:9090Your scraper
pprofmetrics_config.pprof_addroffNobody, normally
Danger

SAGE does not authenticate clients or rate-limit them, and every relay spends your stake. Put 3069 behind a proxy that does both.

  • The admin API is a control plane. It can toggle flags, reset reputation, clear circuit breakers, drain operators and reload the config. It listens on loopback by default; binding it anywhere else requires admin_config.auth_token (or SAGE_ADMIN_TOKEN), and SAGE refuses to start without one. Send Authorization: Bearer <token>.
  • pprof is off unless set. A heap dump contains the gateway and application keys. If you enable it to chase a leak, bind it to loopback and turn it off again.

Health Endpoints

RouteMeaningUse it for
/health, /livez200 while the process servesLiveness
/healthz503 until the protocol layer has a session, and while the full node is unreachableTaking a pod out of rotation (PATH’s readiness spelling)
/ready503 until sessions are ready and reputation has warmed from health checksReadiness and startup probes
/ready/{service}503 until that service holds a session with at least one endpointPer-service checks

Kubernetes

yaml
containers:
  - name: sagegw
    image: ghcr.io/pokt-network/sage:v0.1.0
    args: ["-config", "/etc/sage/config.yaml"]
    ports:
      - {name: relay,   containerPort: 3069}
      - {name: metrics, containerPort: 9090}
    volumeMounts:
      - {name: config, mountPath: /etc/sage, readOnly: true}
    livenessProbe:
      httpGet: {path: /livez, port: relay}
    readinessProbe:
      httpGet: {path: /ready, port: relay}
    startupProbe:
      httpGet: {path: /ready, port: relay}
      periodSeconds: 10
      failureThreshold: 30   # covers a cold start's first probe cycle
    lifecycle:
      preStop: {exec: {command: ["sleep", "5"]}}
volumes:
  - name: config
    secret: {secretName: sage-config}   # it holds signing keys
  • Do not point liveness at /ready or /healthz. A full-node outage would turn into a restart loop.
  • Expose only the relay port through the Service. Reach the admin API with kubectl port-forward, or through an internal Service with the token.
  • Shutdown is graceful on SIGTERM: in-flight relays finish and WebSocket clients get close code 1012, which tells them to reconnect.

Several Replicas and Redis

Redis is optional. Without it, each replica runs on its own view and the gateway still works. With it:

  • Feature flags, drains, bans, health-probe results and circuit breakers are shared across replicas.
  • One replica is elected to send health-check probes; the others apply its results.
  • The leader saves its reputation to Redis, and a replica that starts adopts it instead of re-learning. Reputation is not shared live: after that, each replica scores from its own traffic.

If Redis becomes unreachable, every replica falls back to local state and keeps serving (a replica that starts meanwhile starts with cold reputation), and rejoins without a restart when Redis answers again. Redis Sentinel is supported through redis_config.sentinel_master.

Degraded Modes

  • Pool collapse. When every endpoint of a service scores below the minimum, SAGE serves the least bad one rather than nothing. Treat it as an alert: the whole pool is unhealthy.
  • Circuit breaks. A broken domain leaves the pool for a while, longer on repeat. sage_circuit_breaker_state shows what is broken now.
  • A response served from a degraded path carries the X-Degraded header and counts in sage_degraded_total.

Monitoring

Every metric SAGE exports is listed in the generated docs/metrics.md. Start with:

MetricWatch for
sage_client_requests_totalClient-facing status codes per service
sage_relay_latency_secondsLatency per service
sage_relay_totalUpstream attempts and their outcomes
sage_endpoint_reputation_scoreWhether the pool is healthy
sage_circuit_breaker_stateDomains broken out for a sustained period
sage_recovered_panics_totalNon-zero means a bug was contained; report it

service_id="__unknown__" on any metric means requests for services this gateway does not serve. The label collapses deliberately, so a hostile header cannot create unbounded series.

The repository ships Grafana dashboards in grafana/.

Admin API

The full route list is generated: docs/admin-api.md. The routes used most when something is wrong:

RouteAnswers
GET /admin/reputation/{serviceID}Scores per endpoint key
GET /admin/timeline/{serviceID}Why a score moved: signal, reason, before and after
GET /admin/chain-state/{serviceID}The head SAGE believes, and each endpoint’s height
POST /admin/circuit-breaker/clear/{serviceID}Lets a broken domain back in
POST /admin/reputation/reset/{serviceID}/{endpoint}Returns an endpoint to the initial score
PUT /admin/flags/{flag}/{serviceID}Turns a behaviour on or off for one service
GET /admin/configThe config the process is actually running

The timeline and reputation views are per replica: ask the replica that saw the problem, soon after.