Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maunium
synapse
Commits
cf65433d
Unverified
Commit
cf65433d
authored
2 years ago
by
reivilibre
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix a memory leak when running the unit tests. (#13798)
parent
eaed4e61
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
changelog.d/13798.misc
+1
-0
1 addition, 0 deletions
changelog.d/13798.misc
synapse/util/caches/__init__.py
+2
-1
2 additions, 1 deletion
synapse/util/caches/__init__.py
synapse/util/metrics.py
+5
-5
5 additions, 5 deletions
synapse/util/metrics.py
with
8 additions
and
6 deletions
changelog.d/13798.misc
0 → 100644
+
1
−
0
View file @
cf65433d
Fix a memory leak when running the unit tests.
\ No newline at end of file
This diff is collapsed.
Click to expand it.
synapse/util/caches/__init__.py
+
2
−
1
View file @
cf65433d
...
@@ -205,8 +205,9 @@ def register_cache(
...
@@ -205,8 +205,9 @@ def register_cache(
add_resizable_cache
(
cache_name
,
resize_callback
)
add_resizable_cache
(
cache_name
,
resize_callback
)
metric
=
CacheMetric
(
cache
,
cache_type
,
cache_name
,
collect_callback
)
metric
=
CacheMetric
(
cache
,
cache_type
,
cache_name
,
collect_callback
)
metric_name
=
"
cache_%s_%s
"
%
(
cache_type
,
cache_name
)
caches_by_name
[
cache_name
]
=
cache
caches_by_name
[
cache_name
]
=
cache
CACHE_METRIC_REGISTRY
.
register_hook
(
metric
.
collect
)
CACHE_METRIC_REGISTRY
.
register_hook
(
metric_name
,
metric
.
collect
)
return
metric
return
metric
...
...
This diff is collapsed.
Click to expand it.
synapse/util/metrics.py
+
5
−
5
View file @
cf65433d
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
import
logging
import
logging
from
functools
import
wraps
from
functools
import
wraps
from
types
import
TracebackType
from
types
import
TracebackType
from
typing
import
Awaitable
,
Callable
,
Generator
,
List
,
Optional
,
Type
,
TypeVar
from
typing
import
Awaitable
,
Callable
,
Dict
,
Generator
,
Optional
,
Type
,
TypeVar
from
prometheus_client
import
CollectorRegistry
,
Counter
,
Metric
from
prometheus_client
import
CollectorRegistry
,
Counter
,
Metric
from
typing_extensions
import
Concatenate
,
ParamSpec
,
Protocol
from
typing_extensions
import
Concatenate
,
ParamSpec
,
Protocol
...
@@ -220,21 +220,21 @@ class DynamicCollectorRegistry(CollectorRegistry):
...
@@ -220,21 +220,21 @@ class DynamicCollectorRegistry(CollectorRegistry):
def
__init__
(
self
)
->
None
:
def
__init__
(
self
)
->
None
:
super
().
__init__
()
super
().
__init__
()
self
.
_pre_update_hooks
:
List
[
Callable
[[],
None
]]
=
[]
self
.
_pre_update_hooks
:
Dict
[
str
,
Callable
[[],
None
]]
=
{}
def
collect
(
self
)
->
Generator
[
Metric
,
None
,
None
]:
def
collect
(
self
)
->
Generator
[
Metric
,
None
,
None
]:
"""
"""
Collects metrics, calling pre-update hooks first.
Collects metrics, calling pre-update hooks first.
"""
"""
for
pre_update_hook
in
self
.
_pre_update_hooks
:
for
pre_update_hook
in
self
.
_pre_update_hooks
.
values
()
:
pre_update_hook
()
pre_update_hook
()
yield
from
super
().
collect
()
yield
from
super
().
collect
()
def
register_hook
(
self
,
hook
:
Callable
[[],
None
])
->
None
:
def
register_hook
(
self
,
metric_name
:
str
,
hook
:
Callable
[[],
None
])
->
None
:
"""
"""
Registers a hook that is called before metric collection.
Registers a hook that is called before metric collection.
"""
"""
self
.
_pre_update_hooks
.
append
(
hook
)
self
.
_pre_update_hooks
[
metric_name
]
=
hook
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment