Skip to content

Add metric to count number of non-deactivated users.#19848

Merged
MadLittleMods merged 28 commits into
developfrom
hs/metric-for-all-users
Jun 25, 2026
Merged

Add metric to count number of non-deactivated users.#19848
MadLittleMods merged 28 commits into
developfrom
hs/metric-for-all-users

Conversation

@Half-Shot

@Half-Shot Half-Shot commented Jun 11, 2026

Copy link
Copy Markdown
Member

This reports the total count of users (split by appservice) which is meant to be the monthless counterpart to the MAU metric.

Context:

So this is largely for billing purposes and wanting to know the change in the number of users. If a user is deactivated then we no longer want to count them. Consumers might want to count appservice users, and maybe count them based on the service (perhaps you change more for users under bridge X or bridge Y).

-- #19848 (comment)

@Half-Shot Half-Shot requested a review from a team as a code owner June 11, 2026 12:05
Comment thread synapse/app/phone_stats_home.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Prometheus gauge (synapse_admin_user_count) intended to report total user counts (as a non-monthly counterpart to MAU), split by app_service.

Changes:

  • Add synapse_admin_user_count gauge and a 5-minute background task to populate it.
  • Add a datastore query to count non-deactivated users grouped by appservice.
  • Add a test exercising the gauge update path and a Towncrier newsfragment.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
synapse/app/phone_stats_home.py Defines the new gauge and schedules a periodic update task.
synapse/storage/databases/main/registration.py Adds get_user_count_by_service() SQL query used by the gauge updater.
tests/metrics/test_phone_home_stats.py Adds a test asserting the gauge reflects deactivation.
changelog.d/19848.feature Documents the new metric.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread synapse/storage/databases/main/registration.py Outdated
Comment thread synapse/app/phone_stats_home.py
Comment thread synapse/app/phone_stats_home.py
Comment thread synapse/app/phone_stats_home.py Outdated
Comment thread changelog.d/19848.feature Outdated
Comment thread tests/metrics/test_phone_home_stats.py Outdated
Half-Shot and others added 8 commits June 11, 2026 13:58
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment thread synapse/app/phone_stats_home.py
Comment thread synapse/app/phone_stats_home.py Outdated
Comment thread synapse/app/phone_stats_home.py Outdated
Comment thread synapse/app/phone_stats_home.py Outdated
Comment thread synapse/storage/databases/main/registration.py
Comment thread tests/metrics/test_phone_home_stats.py Outdated
Comment thread tests/metrics/test_phone_home_stats.py Outdated
Comment thread synapse/app/phone_stats_home.py
Comment thread tests/metrics/test_phone_home_stats.py Outdated
Comment thread tests/metrics/test_phone_home_stats.py
MadLittleMods added a commit that referenced this pull request Jun 12, 2026
…ge (#19849)

I.e. `default_config("test")` and `default_config("test", False)` are so
opaque and hard to connect the dots with.

Spawning from trying to figure out what the `server_name` is set as for
our `HomeserverTestCase` in order to reference it in
#19848 (comment)
@Half-Shot Half-Shot requested a review from MadLittleMods June 16, 2026 09:47
Comment thread synapse/storage/databases/main/registration.py
Comment thread synapse/app/phone_stats_home.py Outdated
Comment thread synapse/app/phone_stats_home.py Outdated
Comment thread tests/metrics/test_phone_home_stats.py
Comment thread tests/metrics/test_phone_home_stats.py
Comment thread synapse/storage/databases/main/registration.py Outdated
Comment thread synapse/storage/databases/main/registration.py
Comment thread synapse/app/phone_stats_home.py
Comment thread changelog.d/19848.feature Outdated
Comment thread synapse/storage/databases/main/registration.py
@Half-Shot Half-Shot changed the title Add synapse_admin_user_count metric. Add metric to count number of non-deactivated users. Jun 18, 2026
Comment thread synapse/app/phone_stats_home.py Outdated
Comment thread synapse/app/phone_stats_home.py Outdated
Comment thread synapse/storage/databases/main/registration.py
Comment thread tests/metrics/test_phone_home_stats.py
Comment thread tests/metrics/test_phone_home_stats.py Outdated
Comment thread tests/metrics/__init__.py
Comment thread synapse/storage/databases/main/registration.py
Comment thread tests/metrics/test_phone_home_stats.py Outdated
Comment thread tests/metrics/test_phone_home_stats.py Outdated
Comment thread tests/metrics/test_phone_home_stats.py
Half-Shot and others added 4 commits June 25, 2026 07:51
Co-authored-by: Eric Eastwood <erice@element.io>
Co-authored-by: Eric Eastwood <erice@element.io>
Co-authored-by: Eric Eastwood <madlittlemods@gmail.com>
@Half-Shot Half-Shot requested a review from MadLittleMods June 25, 2026 06:55
Comment thread tests/metrics/test_metrics.py Outdated
@MadLittleMods MadLittleMods merged commit 2bb3aac into develop Jun 25, 2026
80 of 82 checks passed
@MadLittleMods MadLittleMods deleted the hs/metric-for-all-users branch June 25, 2026 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants