feat(api): BIT-2601 rate-limit typing, login preset, and rejection metrics
Align hub rate-limit error context with @fastify/rate-limit types, parse RATE_* and body-size env vars via parsePositiveIntEnv, wire POST /admin/auth/login to the login preset, increment er_api_rate_limit_rejections_total per bucket, and document ingest_token_id plus Prometheus scraping notes. Made-with: Cursor
This commit is contained in:
1 parent
6c22dc8bb9
commit
b29f72bef4
9 files changed
+155
-58
No files matched your search
@@ -15,6 +15,18 @@
|
||||
|
||||
---
|
||||
|
||||
## Hub API — rate limiting (`api/`)
|
||||
|
||||
The hub registers `@fastify/rate-limit` globally and attaches stricter presets to selected routes (`api/src/plugins/rate-limit.ts`, `api/src/index.ts`). Defaults and env tunables are documented in the plugin header (`RATE_*`, body size caps).
|
||||
|
||||
### Request augmentation: `ingest_token_id`
|
||||
|
||||
Hub ingest handlers (e.g. future `POST /api/ingest/*`) **may** set `request.ingest_token_id` to the authenticated ingest key’s stable id **before** the rate-limit hook runs. The ingest preset’s `keyGenerator` then uses `ingest:token:<id>` instead of `ingest:ip:<ip>`, so many clients behind one NAT do not share one counter. The separate **ingest-api** process already applies DB-backed per-key limits; this field keeps the hub aligned if ingest is ever co-hosted in the same Fastify app.
|
||||
|
||||
Rate-limit denials are counted in Prometheus as **`er_api_rate_limit_rejections_total`** (`bucket` label: `global`, `ingest`, `login`, `mutation`). See [OBSERVABILITY_PROMETHEUS.md](OBSERVABILITY_PROMETHEUS.md).
|
||||
|
||||
---
|
||||
|
||||
## Hub API — health & metrics
|
||||
|
||||
### `GET /health`
|
||||
|
||||
Reference in new issue
Block a user