Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 76addad

Browse files
authored
Add some metrics to staging area (#10284)
1 parent 04c8f30 commit 76addad

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

changelog.d/10284.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add metrics for new inbound federation staging area.

synapse/storage/databases/main/event_federation.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
from queue import Empty, PriorityQueue
1717
from typing import Collection, Dict, Iterable, List, Optional, Set, Tuple
1818

19+
from prometheus_client import Gauge
20+
1921
from synapse.api.constants import MAX_DEPTH
2022
from synapse.api.errors import StoreError
2123
from synapse.api.room_versions import RoomVersion
@@ -32,6 +34,16 @@
3234
from synapse.util.caches.lrucache import LruCache
3335
from synapse.util.iterutils import batch_iter
3436

37+
oldest_pdu_in_federation_staging = Gauge(
38+
"synapse_federation_server_oldest_inbound_pdu_in_staging",
39+
"The age in seconds since we received the oldest pdu in the federation staging area",
40+
)
41+
42+
number_pdus_in_federation_queue = Gauge(
43+
"synapse_federation_server_number_inbound_pdu_in_staging",
44+
"The total number of events in the inbound federation staging",
45+
)
46+
3547
logger = logging.getLogger(__name__)
3648

3749

@@ -54,6 +66,8 @@ def __init__(self, database: DatabasePool, db_conn, hs):
5466
500000, "_event_auth_cache", size_callback=len
5567
) # type: LruCache[str, List[Tuple[str, int]]]
5668

69+
self._clock.looping_call(self._get_stats_for_federation_staging, 30 * 1000)
70+
5771
async def get_auth_chain(
5872
self, room_id: str, event_ids: Collection[str], include_given: bool = False
5973
) -> List[EventBase]:
@@ -1193,6 +1207,31 @@ def _get_next_staged_event_for_room_txn(txn):
11931207

11941208
return origin, event
11951209

1210+
@wrap_as_background_process("_get_stats_for_federation_staging")
1211+
async def _get_stats_for_federation_staging(self):
1212+
"""Update the prometheus metrics for the inbound federation staging area."""
1213+
1214+
def _get_stats_for_federation_staging_txn(txn):
1215+
txn.execute(
1216+
"SELECT coalesce(count(*), 0) FROM federation_inbound_events_staging"
1217+
)
1218+
(count,) = txn.fetchone()
1219+
1220+
txn.execute(
1221+
"SELECT coalesce(min(received_ts), 0) FROM federation_inbound_events_staging"
1222+
)
1223+
1224+
(age,) = txn.fetchone()
1225+
1226+
return count, age
1227+
1228+
count, age = await self.db_pool.runInteraction(
1229+
"_get_stats_for_federation_staging", _get_stats_for_federation_staging_txn
1230+
)
1231+
1232+
number_pdus_in_federation_queue.set(count)
1233+
oldest_pdu_in_federation_staging.set(age)
1234+
11961235

11971236
class EventFederationStore(EventFederationWorkerStore):
11981237
"""Responsible for storing and serving up the various graphs associated

0 commit comments

Comments
 (0)