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

Commit 5526f9f

Browse files
authored
Fix overcounting of pushers when they are replaced (#13296)
Signed-off-by: Sean Quah <[email protected]>
1 parent 8c60c57 commit 5526f9f

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

changelog.d/13296.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a bug introduced in v1.18.0 where the `synapse_pushers` metric would overcount pushers when they are replaced.

synapse/push/pusherpool.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ async def _start_pusher(self, pusher_config: PusherConfig) -> Optional[Pusher]:
328328
return None
329329

330330
try:
331-
p = self.pusher_factory.create_pusher(pusher_config)
331+
pusher = self.pusher_factory.create_pusher(pusher_config)
332332
except PusherConfigException as e:
333333
logger.warning(
334334
"Pusher incorrectly configured id=%i, user=%s, appid=%s, pushkey=%s: %s",
@@ -346,23 +346,28 @@ async def _start_pusher(self, pusher_config: PusherConfig) -> Optional[Pusher]:
346346
)
347347
return None
348348

349-
if not p:
349+
if not pusher:
350350
return None
351351

352-
appid_pushkey = "%s:%s" % (pusher_config.app_id, pusher_config.pushkey)
352+
appid_pushkey = "%s:%s" % (pusher.app_id, pusher.pushkey)
353353

354-
byuser = self.pushers.setdefault(pusher_config.user_name, {})
354+
byuser = self.pushers.setdefault(pusher.user_id, {})
355355
if appid_pushkey in byuser:
356-
byuser[appid_pushkey].on_stop()
357-
byuser[appid_pushkey] = p
356+
previous_pusher = byuser[appid_pushkey]
357+
previous_pusher.on_stop()
358358

359-
synapse_pushers.labels(type(p).__name__, p.app_id).inc()
359+
synapse_pushers.labels(
360+
type(previous_pusher).__name__, previous_pusher.app_id
361+
).dec()
362+
byuser[appid_pushkey] = pusher
363+
364+
synapse_pushers.labels(type(pusher).__name__, pusher.app_id).inc()
360365

361366
# Check if there *may* be push to process. We do this as this check is a
362367
# lot cheaper to do than actually fetching the exact rows we need to
363368
# push.
364-
user_id = pusher_config.user_name
365-
last_stream_ordering = pusher_config.last_stream_ordering
369+
user_id = pusher.user_id
370+
last_stream_ordering = pusher.last_stream_ordering
366371
if last_stream_ordering:
367372
have_notifs = await self.store.get_if_maybe_push_in_range_for_user(
368373
user_id, last_stream_ordering
@@ -372,9 +377,9 @@ async def _start_pusher(self, pusher_config: PusherConfig) -> Optional[Pusher]:
372377
# risk missing push.
373378
have_notifs = True
374379

375-
p.on_started(have_notifs)
380+
pusher.on_started(have_notifs)
376381

377-
return p
382+
return pusher
378383

379384
async def remove_pusher(self, app_id: str, pushkey: str, user_id: str) -> None:
380385
appid_pushkey = "%s:%s" % (app_id, pushkey)

0 commit comments

Comments
 (0)