[dreamwidth/dreamwidth] 5737b5: Add per-request metrics (volume + latency) via DW:...
Branch: refs/heads/main Home: https://github.com/dreamwidth/dreamwidth Commit: 5737b5ccc77c40b8de34b14157c289968dc3de3b https://github.com/dreamwidth/dreamwidth/commit/5737b5ccc77c40b8de34b14157c289968dc3de3b Author: Mark Smith mark@dreamwidth.org Date: 2026-05-24 (Sun, 24 May 2026)
Changed paths: M cgi-bin/DW/Stats.pm M cgi-bin/Plack/Middleware/DW/AccessLog.pm M cgi-bin/Plack/Middleware/DW/RateLimit.pm A t/access-log.t M t/rate-limit.t A t/stats.t
Log Message:
Add per-request metrics (volume + latency) via DW::Stats (#3550)
Emit two DogStatsD metrics per HTTP request so Grafana can show request volume, flow breakdown, and latency percentiles:
- dw.request counter, +1 per request
- dw.request.duration_ms timing (|ms), wall-clock latency
Both carry the same low-cardinality tag set: auth (anon|user), ratelimit (excluded|allowed|blocked|skipped), status (full code), method. No path, user, or host tags, so cardinality stays bounded.
DW::Stats gains a timing() method mirroring increment(). The Plack rate-limit middleware stashes the auth state and its decision in the PSGI env (excluded on the internal-IP skip, allowed/blocked after the bucket check); DW::AccessLog -- which already runs once per request and measures duration -- reads those via a pure requesttags helper (defaulting to anon/skipped for requests that never reach the limiter, e.g. static files and redirects) and emits both metrics. The shared $duration_ms is reused for the JSON access log too, so Loki and Grafana report the same value.
DW::Stats is a no-op when %LJ::STATS is unset (dev container, tests), so there is no behavior change locally. The prod receiver is Grafana Alloy's statsd receiver, which maps |ms timings into histograms.
Co-authored-by: Claude Opus 4.7 (1M context) noreply@anthropic.com
To unsubscribe from these emails, change your notification settings at https://github.com/dreamwidth/dreamwidth/settings/notifications
