-
Notifications
You must be signed in to change notification settings - Fork 348
Refactor Measure
block metrics to be homeserver-scoped
#18591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
676a2cc
Refactor block metrics to use HS specific registry
MadLittleMods 420c83d
Use global `REGISTRY` for now
MadLittleMods 612cbd9
Refactor `InFlight` block metrics to be HS specific
MadLittleMods c07e1f5
Add docstrings
MadLittleMods 96c9485
Merge branch 'develop' into madlittlemods/per-hs-metrics-measure
MadLittleMods 019f0b7
Refactor bulk `Measure` usage
MadLittleMods c5296f5
Refactor `Measure` in `synapse/http/federation/well_known_resolver.py`
MadLittleMods 41dfb20
Update `measure_func` to support `HasClockAndMetricsManager`
MadLittleMods f469042
Make sure `@measure_func` usages have the necessary properties
MadLittleMods 6c39fc8
Fix mypy complaining about unknown types by changing property order a…
MadLittleMods e46690c
Add changelog
MadLittleMods 3277afd
Refactor from `hs.metrics_manager` -> `hs.get_metrics_manager()`
MadLittleMods ee51a45
Update doc comment further
MadLittleMods 554673d
Use homeserver specific registry and combine in the metrics endpoint …
MadLittleMods f6f079b
Better docstring
MadLittleMods 71f415d
Fix `tests.test_state` missing `get_metrics_manager()` on homeserver …
MadLittleMods 1a5e9f6
Fill in `get_metrics_manager()` on port db `MockHomeserver`
MadLittleMods File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Refactor `Measure` block metrics to be homeserver-scoped. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,7 @@ | |
from synapse.logging.opentracing import init_tracer | ||
from synapse.metrics import install_gc_manager, register_threadpool | ||
from synapse.metrics.background_process_metrics import wrap_as_background_process | ||
from synapse.metrics.homeserver_metrics_manager import HomeserverMetricsManager | ||
from synapse.metrics.jemalloc import setup_jemalloc_stats | ||
from synapse.module_api.callbacks.spamchecker_callbacks import load_legacy_spam_checkers | ||
from synapse.module_api.callbacks.third_party_event_rules_callbacks import ( | ||
|
@@ -283,18 +284,38 @@ async def wrapper() -> None: | |
reactor.callWhenRunning(lambda: defer.ensureDeferred(wrapper())) | ||
|
||
|
||
def listen_metrics(bind_addresses: StrCollection, port: int) -> None: | ||
def listen_metrics( | ||
bind_addresses: StrCollection, port: int, metrics_manager: HomeserverMetricsManager | ||
) -> None: | ||
""" | ||
Start Prometheus metrics server. | ||
""" | ||
from prometheus_client import start_http_server as start_http_server_prometheus | ||
from prometheus_client import ( | ||
REGISTRY, | ||
CollectorRegistry, | ||
start_http_server as start_http_server_prometheus, | ||
) | ||
|
||
from synapse.metrics import RegistryProxy | ||
from synapse.metrics import CombinedRegistryProxy | ||
|
||
combined_registry_proxy = CombinedRegistryProxy( | ||
[ | ||
# TODO: Remove `REGISTRY` once all metrics have been migrated to the | ||
# homeserver specific metrics collector registry, see | ||
# https://github.com/element-hq/synapse/issues/18592 | ||
REGISTRY, | ||
metrics_manager.metrics_collector_registry, | ||
] | ||
) | ||
# Cheeky cast but matches the signature of a `CollectorRegistry` instance enough | ||
# for it to be usable in the contexts in which we use it. | ||
# TODO Do something nicer about this. | ||
registry = cast(CollectorRegistry, combined_registry_proxy) | ||
Comment on lines
+310
to
+313
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This cast is the same thing we were doing before with the |
||
|
||
for host in bind_addresses: | ||
logger.info("Starting metrics listener on %s:%d", host, port) | ||
_set_prometheus_client_use_created_metrics(False) | ||
start_http_server_prometheus(port, addr=host, registry=RegistryProxy) | ||
start_http_server_prometheus(port, addr=host, registry=registry) | ||
|
||
|
||
def _set_prometheus_client_use_created_metrics(new_value: bool) -> None: | ||
|
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of this work can be removed if we decide that it's okay to drop the
type: metrics
listener (part of #18584)