This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix cache metrics not being updated when not using the legacy exposition module. #13717
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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 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 |
---|---|---|
|
@@ -20,37 +20,74 @@ | |
from typing import Any, Callable, Dict, List, Optional, Sized, TypeVar | ||
|
||
import attr | ||
from prometheus_client import REGISTRY | ||
from prometheus_client.core import Gauge | ||
|
||
from synapse.config.cache import add_resizable_cache | ||
from synapse.util.metrics import DynamicCollectorRegistry | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
# Whether to track estimated memory usage of the LruCaches. | ||
TRACK_MEMORY_USAGE = False | ||
|
||
# We track cache metrics in a special registry that lets us update the metrics | ||
# just before they are returned from the scrape endpoint. | ||
CACHE_METRIC_REGISTRY = DynamicCollectorRegistry() | ||
|
||
caches_by_name: Dict[str, Sized] = {} | ||
collectors_by_name: Dict[str, "CacheMetric"] = {} | ||
|
||
cache_size = Gauge("synapse_util_caches_cache_size", "", ["name"]) | ||
cache_hits = Gauge("synapse_util_caches_cache_hits", "", ["name"]) | ||
cache_evicted = Gauge("synapse_util_caches_cache_evicted_size", "", ["name", "reason"]) | ||
cache_total = Gauge("synapse_util_caches_cache", "", ["name"]) | ||
cache_max_size = Gauge("synapse_util_caches_cache_max_size", "", ["name"]) | ||
cache_size = Gauge( | ||
"synapse_util_caches_cache_size", "", ["name"], registry=CACHE_METRIC_REGISTRY | ||
) | ||
cache_hits = Gauge( | ||
"synapse_util_caches_cache_hits", "", ["name"], registry=CACHE_METRIC_REGISTRY | ||
) | ||
cache_evicted = Gauge( | ||
"synapse_util_caches_cache_evicted_size", | ||
"", | ||
["name", "reason"], | ||
registry=CACHE_METRIC_REGISTRY, | ||
) | ||
cache_total = Gauge( | ||
"synapse_util_caches_cache", "", ["name"], registry=CACHE_METRIC_REGISTRY | ||
) | ||
cache_max_size = Gauge( | ||
"synapse_util_caches_cache_max_size", "", ["name"], registry=CACHE_METRIC_REGISTRY | ||
) | ||
cache_memory_usage = Gauge( | ||
"synapse_util_caches_cache_size_bytes", | ||
"Estimated memory usage of the caches", | ||
["name"], | ||
registry=CACHE_METRIC_REGISTRY, | ||
) | ||
|
||
response_cache_size = Gauge("synapse_util_caches_response_cache_size", "", ["name"]) | ||
response_cache_hits = Gauge("synapse_util_caches_response_cache_hits", "", ["name"]) | ||
response_cache_size = Gauge( | ||
"synapse_util_caches_response_cache_size", | ||
"", | ||
["name"], | ||
registry=CACHE_METRIC_REGISTRY, | ||
) | ||
response_cache_hits = Gauge( | ||
"synapse_util_caches_response_cache_hits", | ||
"", | ||
["name"], | ||
registry=CACHE_METRIC_REGISTRY, | ||
) | ||
response_cache_evicted = Gauge( | ||
"synapse_util_caches_response_cache_evicted_size", "", ["name", "reason"] | ||
"synapse_util_caches_response_cache_evicted_size", | ||
"", | ||
["name", "reason"], | ||
registry=CACHE_METRIC_REGISTRY, | ||
) | ||
response_cache_total = Gauge("synapse_util_caches_response_cache", "", ["name"]) | ||
response_cache_total = Gauge( | ||
"synapse_util_caches_response_cache", "", ["name"], registry=CACHE_METRIC_REGISTRY | ||
) | ||
|
||
|
||
# Register our custom cache metrics registry with the global registry | ||
REGISTRY.register(CACHE_METRIC_REGISTRY) | ||
|
||
|
||
class EvictionReason(Enum): | ||
|
@@ -168,9 +205,9 @@ def register_cache( | |
add_resizable_cache(cache_name, resize_callback) | ||
|
||
metric = CacheMetric(cache, cache_type, cache_name, collect_callback) | ||
metric_name = "cache_%s_%s" % (cache_type, cache_name) | ||
# TODO evil ??metric_name = "cache_%s_%s" % (cache_type, cache_name) | ||
caches_by_name[cache_name] = cache | ||
collectors_by_name[metric_name] = metric | ||
CACHE_METRIC_REGISTRY.register_hook(metric.collect) | ||
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. I think this replaces 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. yep! |
||
return metric | ||
|
||
|
||
|
This file contains 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
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.
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.
What's going on here?
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.
bahah, just cruft. I should have checked the diff! I'll remove it :)