Skip to content

feat(metrics): fixed-cardinality active_users gauge + restored dashboard panel - #180

Merged
VortexUK merged 1 commit into
mainfrom
feat/active-users-gauge
Jul 25, 2026
Merged

feat(metrics): fixed-cardinality active_users gauge + restored dashboard panel#180
VortexUK merged 1 commit into
mainfrom
feat/active-users-gauge

Conversation

@VortexUK

Copy link
Copy Markdown
Owner

Summary

Restores the "Active users (last 1 h)" dashboard panel removed in #179 — at a cost of 2 series instead of the 12,905 the old user_page_views_total approach consumed.

  • Middleware stamps user_id → last-seen in process memory on authenticated GETs; user identifiers never become metric labels (privacy bonus).
  • _ActiveUsersCollector emits active_users{window="1h"} / {window="24h"} gauges at scrape time — cardinality fixed regardless of user count.
  • Last-seen map self-prunes past 2048 entries.
  • frontend.json panel restored in its old grid slot, querying the new gauge (re-import after deploy).

Trade-offs vs the old metric: count resets on deploy (in-memory), no per-user breakdown (explicitly not wanted anymore).

Test plan

  • tests/server/test_metrics.py: window counting (1h vs 24h boundaries, repeat visits dedupe), stale-entry pruning.
  • Full gates: 1630 backend tests, ruff + pyright clean, dashboard JSON validated (7 panels).

🤖 Generated with Claude Code

…ard panel

Brings back "Active users (last 1 h)" without the per-user series that
blew the Grafana free tier: the middleware stamps user-id -> last-seen
in memory and _ActiveUsersCollector emits active_users{window="1h"|"24h"}
at scrape time - 2 series total regardless of user count, and no user
identifiers ever become metric labels.

Trade-offs vs the removed user_page_views_total: count resets on deploy
(in-memory) and there is no per-user breakdown.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@VortexUK
VortexUK merged commit b7e0248 into main Jul 25, 2026
6 checks passed
@VortexUK
VortexUK deleted the feat/active-users-gauge branch July 25, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant