Expand description
What every edda service shares: logging, opening its
database, finding the auth service’s key, serving (with the CORS setting
and the limits), error responses, and the conventions of their OpenAPI
descriptions.
Re-exports§
pub use limits::Limits;
Modules§
- admin
- The admin API: what whoever runs the services asks of them over HTTP,
such as creating and deleting campaigns, so a hosting’s control plane
can do it without a shell. Served on
ADMIN_ADDR, an address only it can reach, and only withADMIN_TOKENtoo, which every request must bear; without both there’s none. - limits
- Limits on how much one client or one campaign can ask of a service, so a service open to the internet can’t be flooded or filled up: requests per minute from each client address (fewer for signing in), how big a request may be, and how much each campaign may keep.
- measure
- What a service measures, for Prometheus: its requests by route and
status and how long they take, what the limits refuse, and its
database connections; services add their own (the combat service’s
WebSockets, say). Served at
/metricsonMETRICS_ADDR, an address of its own that the proxy never serves; without it nothing is measured. - observe
- What a service logs about each request: a span with its method, path, request id, and whose it is (the campaign, once its token is checked, and the account, as the proxy says), in plain text or JSON lines, and as traces to an OpenTelemetry collector if there is one. Never a body, and never the query string, which may hold what someone typed.
- openapi
- What every service’s
OpenAPIdescription shares: the token routes need, and the error responses any route may give.
Functions§
- auth_
key - The key the auth service signs tokens with:
AUTH_PUBLIC_KEYif set, otherwise fetched from the auth service atauth_service(waiting a while for it to start). Set the key explicitly unless the network between the services is trusted. - auth_
service_ url AUTH_SERVICE_URL, or the auth service on this machine.- direct_
database_ url - Where to reach the database for what needs a session of its own:
migrations, and the combat service’s
LISTEN.DATABASE_DIRECT_URLwhenurlgoes through a pooler that hands out connections per transaction (PgBouncer’s transaction mode), otherwiseurlitself. - error_
message - What an error response says: the error itself, unless it’s internal (a 500), which is logged and not shown.
- error_
response - An error response:
{"error": "..."}withstatus(seeerror_message). - health
GET /health: answersokwhile the service runs.- init_
logging - Logs to stderr:
crate_name’s own messages, this crate’s (serving, internal errors) and each request, at info, unlessRUST_LOGsays otherwise.LOG_FORMAT=jsonwrites a JSON object a line, for a log collector, andOTEL_EXPORTER_OTLP_ENDPOINTsends traces to an OpenTelemetry collector; seeobserve. - open_
database - A connection pool to the service’s Postgres database at
url, after creating the database if there’s none yet and bringing it up to date withmigrations. Those two go throughdirect_database_url, as they need a session of their own (sqlx serialises migrations with an advisory lock, so instances may start at once). - readiness
GET /ready, for whatever runs the service (Kubernetes, compose):200while it can reach its database,503while it can’t, so it gets no requests until it can again./healthonly says it’s running.- ready
GET /ready: seereadiness.- serve
- Serves
apponbinduntil asked to stop, withinlimits, answering web pages from the origins inCORS_ORIGINS; andadminonADMIN_ADDRand metrics onMETRICS_ADDR, if set.