This commit is contained in:
Mateusz Gruszczyński committed 2026-11-15 20:54:59 +01:00
1 parent 758cfd6274
commit 8bdec5c757
32 files changed
+418 -44

No files matched your search

+46
View File
@@ -141,6 +141,52 @@ done
The initial request can show `RustProxy; fwd=miss`; an eligible repeat should show `RustProxy; hit; ttl=...`. If the origin sends no `Cache-Status`, there is no upstream member to display. If RustProxy diagnostic output is off, any visible `Cache-Status` is from upstream; absence of a RustProxy member is expected. The actual cache outcome should also be checked in server request logs.
## Detailed cache status: STALE and REVALIDATED
Two kinds of responses come from the cache but are not plain hits:
- **STALE** — served past its freshness: Varnish grace, `stale-while-revalidate`, `max-stale`, `stale-if-error` while the origin fails, or a request-collapse timeout.
- **REVALIDATED** — the stored object was confirmed by the origin with `304 Not Modified`.
Where they show:
| Place | Value |
|---|---|
| `Server-Timing` cache metric | always `STALE` / `REVALIDATED` |
| access log `cache` field, log filter and `rust-proxy logs` | always `STALE` / `REVALIDATED` (before 0.38.2: `HIT`); `cache_reason` gives the exact cause |
| `X-Cache` | `HIT` by default; `STALE` / `REVALIDATED` with **X-Cache shows STALE and REVALIDATED instead of HIT** (`cache.expose_detailed_status`, also per vhost) |
| Cache dashboard | counted as HIT for the hit ratio; the request line adds `· N STALE · N REVALIDATED` (also `stale` and `revalidated` per domain in `/api/cache`) |
A growing STALE count while the origin is down means RustProxy is answering from cache instead of returning errors. `Only on HIT` treats STALE and REVALIDATED as hits. `X-Cache` stays `HIT` by default because monitoring scripts often match on it.
## Server-Timing
With **Expose Server-Timing diagnostics** (`timing_headers: true` on the vhost) RustProxy adds one `Server-Timing` field. Browsers show it in the developer tools (Network → Timing) and RUM tools read it through `PerformanceServerTiming`.
```http
Server-Timing: app;dur=7
Server-Timing: proxy;dur=2.31, upstream;dur=1.94, proxy-cache;desc="MISS"
```
| Metric | Meaning |
|---|---|
| `proxy;dur` | Total time in RustProxy until the response headers, in milliseconds. |
| `upstream;dur` | Time from sending the request to the backend until its response headers. Absent when the backend was not contacted. |
| `proxy-cache;desc` | `HIT`, `MISS`, `BYPASS`, `STALE` or `REVALIDATED` (see above). Absent when no cache decision was made. |
**Metric names** (`timing_header_names`, panel: **Server-Timing metric names**):
| Value | Names | When |
|---|---|---|
| `standard` (default) | `proxy`, `upstream`, `proxy-cache` | RustProxy as a reverse proxy or load balancer in front of the application. The names do not collide with a CDN in front of RustProxy (Cloudflare, Akamai, Fastly add their own `edge`, `origin`, `cdn-cache`, where *origin* means RustProxy) nor with an application's own `cache` metric. |
| `cdn` | `edge`, `origin`, `cdn-cache` | RustProxy is the outermost, CDN-like layer and a RUM tool expects the Akamai mPulse names. Do not use with a CDN in front of RustProxy. |
| `legacy` | `proxy`, `origin`, `cache` | Names used before 0.38.2, for existing dashboards. |
- On a MISS or BYPASS the origin's own `Server-Timing` metrics are kept and RustProxy's field is appended after them. With several RustProxy hops (edge → front → application) every hop appends its own field, so the inner hop's cache result stays visible.
- On a response served from the cache (`HIT`, `STALE`, `REVALIDATED`) the stored `Server-Timing` of the origin is removed, because it describes the request that filled the cache, not this one. This also applies when `timing_headers` is off.
- Scripts on the same origin can always read `Server-Timing`. For scripts on another origin (a RUM collector, an assets domain) list those origins in **Timing-Allow-Origin** (`timing_allow_origin: ["https://app.example.com"]`, or `["*"]`); the header is only sent together with Server-Timing.
- Turn Server-Timing off on public production sites if response timings should not be exposed.
## Advanced behavior
- **Budget limits:** HOT RAM capacity, object count/size, transient fill memory and optional COLD byte/object limits. Configure based on real workload and monitor disk/RSS.