feat(metrics): fixed-cardinality active_users gauge + restored dashboard panel - #180
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_totalapproach consumed.user_id → last-seenin process memory on authenticated GETs; user identifiers never become metric labels (privacy bonus)._ActiveUsersCollectoremitsactive_users{window="1h"}/{window="24h"}gauges at scrape time — cardinality fixed regardless of user count.frontend.jsonpanel 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.🤖 Generated with Claude Code