GitHub시작하기

이 페이지는 아직 한국어로 번역되지 않아 영문 원문을 표시하고 있습니다.

더 보기

Deploying backend services

Use Postgres for production accounts, cloud saves and self-hosted leaderboards. SQLite is suitable for development, tests and a single node with a durable volume. Memory stores are test-only.

Run accountsd, cloudsaved and leaderboardd behind one TLS-terminating proxy with rate limits and health checks. Give each daemon an explicit address and share the account service key set from accountsd genkey through a protected secret store.

Back up Postgres with managed snapshots or pg_dump and rehearse restores. Each daemon creates or migrates its schema when it opens the database, and on Postgres the migration takes an advisory lock, so several instances may start at once. A daemon refuses a database whose schema is newer than it knows, so roll forward instead of starting an older binary against a newer database.

The file-backed leaderboard keeps boards in memory and is intended for a single process until a shared SQL store is configured. SQLite files require a durable volume and WAL files must be backed up together.

Give operators an admin listener by adding an admin: block to each daemon's configuration. Bind it to a private address, never the public one the proxy forwards players to, and expose it only through a VPN or an access-controlled proxy that terminates TLS and sets X-Forwarded-Proto: https, so the session cookie is Secure. Keep each operators file in version control and its .totp.yaml secrets file and the audit directory on protected storage, and let every daemon that shares an operators file write the .totp-used directory beside it, where accepted TOTP codes are recorded; the audit directory is append-only text, so ship it to your log store like other logs.

Health and metrics

Each daemon serves its deployment endpoints when its configuration sets metrics to a listen address. They are absent otherwise, and they never share the listener players reach:

metrics: 127.0.0.1:9101
Endpoint Answers
GET /healthz 200 while the process runs
GET /readyz 200 while the database answers a ping within 2 seconds, else 503; leaderboardd -data checks that its score directory is there
GET /metrics The series below, in the Prometheus text format

Point a load balancer's readiness probe at /readyz, so an instance that loses its database leaves rotation until the database is back, and a liveness probe at /healthz, which does not depend on the database, so the orchestrator does not restart every instance during a database outage. On SQLite, /readyz and the store counts read through a second, read-only handle on the database file, so a long write on the store's single connection, such as a large cloud save on a slow disk, neither fails the probe nor waits behind a scrape. The endpoints have no authentication: bind metrics to 127.0.0.1, a private interface or a port the proxy does not forward. A daemon whose metrics address is not loopback, such as :9101 for an in-cluster Prometheus, logs a warning at startup to remind you.

Series Daemon Meaning
nsgo_http_requests_total{route,code} all Requests served, by route pattern (such as POST /v1/guest) and status code; requests no route matched count under route="unmatched"
nsgo_http_request_duration_seconds{route} all Histogram of the time to serve a request, from 5 ms to 10 s
nsgo_accounts_signins_total{method} accountsd Sign-ins that returned credentials, method one of guest, register, email and identity
nsgo_accounts_signin_failures_total{method} accountsd Sign-ins answered with an error status
nsgo_accounts_accounts, nsgo_accounts_sessions accountsd Accounts, and device sessions signed in and not yet signed out
nsgo_cloudsave_accounts cloudsaved Accounts with at least one slot, live or deleted
nsgo_cloudsave_slots cloudsaved Slots whose newest version is a save, not a deletion
nsgo_cloudsave_stored_bytes cloudsaved Payload bytes of every kept version of every slot
nsgo_leaderboard_entries{board} leaderboardd Accounts with a score in the board's current period

The account, session, slot and byte counts scan their tables in full, so a daemon runs them at most once every 15 seconds and answers the scrapes in between with the last count; a scrape interval shorter than that sees the same values repeated. Each count gives up after 5 seconds and leaves its series out until the next count, with a warning in the log. A program that builds its own server around accounts.New, cloudsave.New or selfhost.New gets the same endpoints from package servicehealth: wrap the player handler in a servicehealth.Requests, add collectors to a servicehealth.Health, and serve it with servicehealth.Listen or mount it on another listener with Register. servicehealth.AuditCollector exports an audit.Writer's dropped records as nsgo_audit_dropped_total.

이 페이지 편집