summary refs log tree commit diff
path: root/synapse/util
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2021-05-04 14:32:42 +0100
committerErik Johnston <erik@matrix.org>2021-05-04 14:32:42 +0100
commit78e3502ada403144d5fbce2cd7edf8a1c36c739a (patch)
treecd72392bb4f8298a4549ea9f16dcc613cb6188cb /synapse/util
parentComment (diff)
downloadsynapse-78e3502ada403144d5fbce2cd7edf8a1c36c739a.tar.xz
Always report memory usage metrics when TRACK_MEMORY_USAGE is True
Diffstat (limited to 'synapse/util')
-rw-r--r--synapse/util/caches/__init__.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/synapse/util/caches/__init__.py b/synapse/util/caches/__init__.py
index bac10dc47a..ca36f07c20 100644
--- a/synapse/util/caches/__init__.py
+++ b/synapse/util/caches/__init__.py
@@ -105,8 +105,13 @@ class CacheMetric:
                 cache_total.labels(self._cache_name).set(self.hits + self.misses)
                 if getattr(self._cache, "max_size", None):
                     cache_max_size.labels(self._cache_name).set(self._cache.max_size)
-                if self.memory_usage is not None:
-                    cache_memory_usage.labels(self._cache_name).set(self.memory_usage)
+
+                if TRACK_MEMORY_USAGE:
+                    # self.memory_usage can be None if nothing has been inserted
+                    # into the cache yet.
+                    cache_memory_usage.labels(self._cache_name).set(
+                        self.memory_usage or 0
+                    )
             if self._collect_callback:
                 self._collect_callback()
         except Exception as e: