Refactor cache metrics to be homeserver-scoped (#18604)

(add `server_name` label to cache metrics).

Part of https://github.com/element-hq/synapse/issues/18592
This commit is contained in:
Eric Eastwood
2025-07-16 16:04:57 -05:00
committed by GitHub
parent fc10a5ee29
commit 88785dbaeb
88 changed files with 694 additions and 268 deletions

View File

@@ -33,7 +33,10 @@ class ExpiringCacheTestCase(unittest.HomeserverTestCase):
def test_get_set(self) -> None:
clock = MockClock()
cache: ExpiringCache[str, str] = ExpiringCache(
"test", cast(Clock, clock), max_len=1
cache_name="test",
server_name="testserver",
clock=cast(Clock, clock),
max_len=1,
)
cache["key"] = "value"
@@ -43,7 +46,10 @@ class ExpiringCacheTestCase(unittest.HomeserverTestCase):
def test_eviction(self) -> None:
clock = MockClock()
cache: ExpiringCache[str, str] = ExpiringCache(
"test", cast(Clock, clock), max_len=2
cache_name="test",
server_name="testserver",
clock=cast(Clock, clock),
max_len=2,
)
cache["key"] = "value"
@@ -59,7 +65,11 @@ class ExpiringCacheTestCase(unittest.HomeserverTestCase):
def test_iterable_eviction(self) -> None:
clock = MockClock()
cache: ExpiringCache[str, List[int]] = ExpiringCache(
"test", cast(Clock, clock), max_len=5, iterable=True
cache_name="test",
server_name="testserver",
clock=cast(Clock, clock),
max_len=5,
iterable=True,
)
cache["key"] = [1]
@@ -79,7 +89,10 @@ class ExpiringCacheTestCase(unittest.HomeserverTestCase):
def test_time_eviction(self) -> None:
clock = MockClock()
cache: ExpiringCache[str, int] = ExpiringCache(
"test", cast(Clock, clock), expiry_ms=1000
cache_name="test",
server_name="testserver",
clock=cast(Clock, clock),
expiry_ms=1000,
)
cache["key"] = 1