Refactor Counter metrics to be homeserver-scoped#18656
Merged
MadLittleMods merged 52 commits intodevelopfrom Jul 25, 2025
Merged
Refactor Counter metrics to be homeserver-scoped#18656MadLittleMods merged 52 commits intodevelopfrom
Counter metrics to be homeserver-scoped#18656MadLittleMods merged 52 commits intodevelopfrom
Conversation
server_name labelCounter metrics to be homeserver-scoped
38 tasks
…f `synapse/http/request_metrics.py`) ``` synapse/logging/opentracing.py:1084: error: Cannot determine type of "request_metrics" [has-type] synapse/logging/opentracing.py:1100: error: Cannot determine type of "request_metrics" [has-type] synapse/logging/opentracing.py:1106: error: Unused "type: ignore" comment [unused-ignore] synapse/logging/opentracing.py:1106: error: Cannot determine type of "request_metrics" [has-type] synapse/logging/opentracing.py:1106: note: Error code "has-type" not covered by "type: ignore" comment synapse/http/server.py:141: error: Cannot determine type of "request_metrics" [has-type] synapse/http/server.py:151: error: Cannot determine type of "request_metrics" [has-type] synapse/http/server.py:333: error: Cannot determine type of "request_metrics" [has-type] synapse/http/server.py:546: error: Cannot determine type of "request_metrics" [has-type] synapse/http/site.py:132: error: Cannot determine type of "server_name" [has-type] synapse/http/site.py:341: error: Cannot determine type of "request_metrics" [has-type] ```
TODO: still need to fill in `run_as_background_process` usage
…ground_process`)
5 tasks
MadLittleMods
added a commit
that referenced
this pull request
Jul 16, 2025
Conflicts: synapse/handlers/device.py synapse/metrics/__init__.py synapse/storage/_base.py synapse/storage/databases/main/end_to_end_keys.py
9 tasks
MadLittleMods
added a commit
that referenced
this pull request
Jul 23, 2025
Part of #18592 Separated out of #18656 because it's a bigger, unique piece of the refactor ### Testing strategy 1. Add the `metrics` listener in your `homeserver.yaml` ```yaml listeners: # This is just showing how to configure metrics either way # # `http` `metrics` resource - port: 9322 type: http bind_addresses: ['127.0.0.1'] resources: - names: [metrics] compress: false # `metrics` listener - port: 9323 type: metrics bind_addresses: ['127.0.0.1'] ``` 1. Start the homeserver: `poetry run synapse_homeserver --config-path homeserver.yaml` 1. Fetch `http://localhost:9322/_synapse/metrics` and/or `http://localhost:9323/metrics` 1. Observe response includes the background processs metrics (`synapse_background_process_start_count`, `synapse_background_process_db_txn_count_total`, etc) with the `server_name` label
Conflicts: synapse/appservice/scheduler.py synapse/handlers/device.py synapse/handlers/typing.py synapse/push/pusherpool.py synapse/replication/tcp/redis.py synapse/util/task_scheduler.py
MadLittleMods
commented
Jul 23, 2025
| return None | ||
|
|
||
|
|
||
| def check_prometheus_metric_instantiation(ctx: FunctionSigContext) -> CallableType: |
Contributor
Author
There was a problem hiding this comment.
New linting to prevent new Counter metrics from being introduced without the SERVER_NAME_LABEL
MadLittleMods
added a commit
that referenced
this pull request
Jul 23, 2025
MadLittleMods
added a commit
that referenced
this pull request
Jul 23, 2025
Wait for #18656 to be merged so we have `self.server_name` available.
MadLittleMods
added a commit
that referenced
this pull request
Jul 23, 2025
Wait for #18656 to merge so we have access to `self.server_name`
4 tasks
MadLittleMods
added a commit
that referenced
this pull request
Jul 23, 2025
Wait for #18656 to be merged so we have `self.server_name` available.
MadLittleMods
added a commit
that referenced
this pull request
Jul 23, 2025
Wait for #18656 to merge so we have access to `self.server_name`
MadLittleMods
added a commit
that referenced
this pull request
Jul 23, 2025
MadLittleMods
added a commit
that referenced
this pull request
Jul 24, 2025
devonh
approved these changes
Jul 24, 2025
Member
devonh
left a comment
There was a problem hiding this comment.
These changes all look good and are pretty straightforward swaps to add the new server name label.
Thanks for taking the time to cleanup things like docstrings along the way :)
|
|
||
| logger.info("Created Mailer for app_name %s", app_name) | ||
|
|
||
| emails_sent_counter.labels("password_reset") |
Member
There was a problem hiding this comment.
Huh, odd. Your cleanup looks good to me 🤷
Contributor
Author
|
Thanks for the review @devonh 🐎 |
MadLittleMods
added a commit
that referenced
this pull request
Jul 25, 2025
MadLittleMods
added a commit
that referenced
this pull request
Jul 29, 2025
Bulk refactor `Histogram` metrics to be homeserver-scoped. We also add lints to make sure that new `Histogram` metrics don't sneak in without using the `server_name` label (`SERVER_NAME_LABEL`). Part of #18592 ### Testing strategy 1. Add the `metrics` listener in your `homeserver.yaml` ```yaml listeners: # This is just showing how to configure metrics either way # # `http` `metrics` resource - port: 9322 type: http bind_addresses: ['127.0.0.1'] resources: - names: [metrics] compress: false # `metrics` listener - port: 9323 type: metrics bind_addresses: ['127.0.0.1'] ``` 1. Start the homeserver: `poetry run synapse_homeserver --config-path homeserver.yaml` 1. Fetch `http://localhost:9322/_synapse/metrics` and/or `http://localhost:9323/metrics` 1. Observe response includes the TODO metrics with the `server_name` label ### Todo - [x] Wait for #18656 to merge ### Dev notes ``` LoggingDatabaseConnection make_conn make_pool make_fake_db_pool ``` ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [x] Pull request is based on the develop branch * [x] Pull request includes a [changelog file](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#changelog). The entry should: - Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from `EventStore` to `EventWorkerStore`.". - Use markdown where necessary, mostly for `code blocks`. - End with either a period (.) or an exclamation mark (!). - Start with a capital letter. - Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry. * [x] [Code style](https://element-hq.github.io/synapse/latest/code_style.html) is correct (run the [linters](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#run-the-linters))
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.
Bulk refactor
Countermetrics to be homeserver-scoped. We also add lints to make sure that newCountermetrics don't sneak in without using theserver_namelabel (SERVER_NAME_LABEL).All of the "Fill in" commits are just bulk refactor.
Part of #18592
Testing strategy
metricslistener in yourhomeserver.yamlpoetry run synapse_homeserver --config-path homeserver.yamlhttp://localhost:9322/_synapse/metricsand/orhttp://localhost:9323/metricssynapse_user_registrations_total,synapse_http_server_response_count_total, etc metrics with theserver_namelabelDev notes
mypypluginshttps://mypy.readthedocs.io/en/latest/extending_mypy.html
ErrorCodesdefined in mypy plugins seemingly cannot be ignored by--disable-error-codepython/mypy#12987(doesn't work because of above issue)
Refactor notes
More special refactors:
synapse/http/request_metrics.pysynapse/metrics/background_process_metrics.pyUnused metrics:
notified_events_counterpush_rules_invalidation_counterpush_rules_state_size_counterremove_pusher_counterTodo
Add lint formetric.labels(...)prometheus_clientwill raise aValueErrorat runtime. Ideally, we'd be able to catch this at type-checking time but this is good enough.Measureblock metrics to be homeserver-scoped (v2) #18601 to mergePull Request Checklist
EventStoretoEventWorkerStore.".code blocks.