synapse/tests
Eric Eastwood d4af2970f3
Refactor Histogram metrics to be homeserver-scoped (#18724)
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 https://github.com/element-hq/synapse/issues/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 https://github.com/element-hq/synapse/pull/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))
2025-07-29 15:35:38 -05:00
..
api Refactor cache metrics to be homeserver-scoped (#18604) 2025-07-16 16:04:57 -05:00
app Correctly mention previous copyright (#16820) 2024-01-23 11:26:48 +00:00
appservice Refactor background process metrics to be homeserver-scoped (#18670) 2025-07-23 13:28:17 -05:00
config Refactor cache metrics to be homeserver-scoped (#18604) 2025-07-16 16:04:57 -05:00
crypto Stop sending or processing the origin field in PDUs (#18418) 2025-07-01 12:04:23 +01:00
events Allow admins to see policy server-flagged events (#18585) 2025-07-29 19:57:33 +01:00
federation Move device changes off the main process (#18581) 2025-07-18 09:06:14 +02:00
handlers Refactor Counter metrics to be homeserver-scoped (#18656) 2025-07-25 14:58:47 -05:00
http Configure HTTP proxy in file config (#18686) 2025-07-22 10:33:00 -05:00
logging Refactor Counter metrics to be homeserver-scoped (#18656) 2025-07-25 14:58:47 -05:00
media Add ability to limit amount uploaded by a user (#18527) 2025-07-10 13:39:09 +01:00
metrics Refactor background process metrics to be homeserver-scoped (#18670) 2025-07-23 13:28:17 -05:00
module_api Move device changes off the main process (#18581) 2025-07-18 09:06:14 +02:00
push Refactor cache metrics to be homeserver-scoped (#18604) 2025-07-16 16:04:57 -05:00
replication Configure HTTP proxy in file config (#18686) 2025-07-22 10:33:00 -05:00
rest Allow admins to see policy server-flagged events (#18585) 2025-07-29 19:57:33 +01:00
scripts Update license headers 2023-11-21 15:29:58 -05:00
server_notices Sliding Sync: Add cache to get_tags_for_room(...) (#17730) 2024-09-19 12:43:26 +01:00
state bugfix: calculate the PL for non-creators correctly in v11 rooms (#18547) 2025-06-13 12:56:39 +01:00
storage Refactor Histogram metrics to be homeserver-scoped (#18724) 2025-07-29 15:35:38 -05:00
test_utils Allow admins to see policy server-flagged events (#18585) 2025-07-29 19:57:33 +01:00
types Use immutabledict instead of frozendict (#15113) 2023-03-22 17:15:34 +00:00
util Refactor Gauge metrics to be homeserver-scoped (#18725) 2025-07-29 10:37:59 -05:00
__init__.py Correctly mention previous copyright (#16820) 2024-01-23 11:26:48 +00:00
server.py Refactor Histogram metrics to be homeserver-scoped (#18724) 2025-07-29 15:35:38 -05:00
test_distributor.py Refactor background process metrics to be homeserver-scoped (#18670) 2025-07-23 13:28:17 -05:00
test_event_auth.py Format files with Ruff (#17643) 2024-09-02 12:39:04 +01:00
test_mau.py Refactor cache metrics to be homeserver-scoped (#18604) 2025-07-16 16:04:57 -05:00
test_phone_home.py Correctly mention previous copyright (#16820) 2024-01-23 11:26:48 +00:00
test_rust.py Add missing type hints to tests. (#15027) 2023-02-08 19:52:37 +00:00
test_server.py Fix backwards compat for DirectServeJsonResource (#18600) 2025-06-26 14:05:48 +00:00
test_state.py Bump ruff from 0.7.3 to 0.11.10 (#18451) 2025-05-20 15:23:30 +01:00
test_terms_auth.py Update license headers 2023-11-21 15:29:58 -05:00
test_test_utils.py Correctly mention previous copyright (#16820) 2024-01-23 11:26:48 +00:00
test_types.py Format files with Ruff (#17643) 2024-09-02 12:39:04 +01:00
test_visibility.py Allow admins to see policy server-flagged events (#18585) 2025-07-29 19:57:33 +01:00
unittest.py Cleanup Python 3.8 leftovers (#17967) 2025-02-10 16:53:24 +00:00
utils.py Refactor Histogram metrics to be homeserver-scoped (#18724) 2025-07-29 15:35:38 -05:00