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.
| Listener | Config key | Default | Who should reach it |
|---|---|---|---|
| Relays and health | router_config.port | 3069 | Clients, through your edge |
| Admin API | admin_config.addr | localhost:9091 | Operators only |
| Prometheus | metrics_config.prometheus_addr | :9090 | Your scraper |
| pprof | metrics_config.pprof_addr | off | Nobody, normally |
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(orSAGE_ADMIN_TOKEN), and SAGE refuses to start without one. SendAuthorization: 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
| Route | Meaning | Use it for |
|---|---|---|
/health, /livez | 200 while the process serves | Liveness |
/healthz | 503 until the protocol layer has a session, and while the full node is unreachable | Taking a pod out of rotation (PATH’s readiness spelling) |
/ready | 503 until sessions are ready and reputation has warmed from health checks | Readiness and startup probes |
/ready/{service} | 503 until that service holds a session with at least one endpoint | Per-service checks |
Kubernetes
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
/readyor/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_stateshows what is broken now. - A response served from a degraded path carries the
X-Degradedheader and counts insage_degraded_total.
Monitoring
Every metric SAGE exports is listed in the generated docs/metrics.md. Start with:
| Metric | Watch for |
|---|---|
sage_client_requests_total | Client-facing status codes per service |
sage_relay_latency_seconds | Latency per service |
sage_relay_total | Upstream attempts and their outcomes |
sage_endpoint_reputation_score | Whether the pool is healthy |
sage_circuit_breaker_state | Domains broken out for a sustained period |
sage_recovered_panics_total | Non-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:
| Route | Answers |
|---|---|
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/config | The config the process is actually running |
The timeline and reputation views are per replica: ask the replica that saw the problem, soon after.