From 0abb094f1ada9c4a78a11eb06b205c00db826860 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Thu, 21 Feb 2019 17:51:21 +0000 Subject: bail out early in on_new_receipts if no pushers (#4706) --- synapse/push/pusherpool.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'synapse/push') diff --git a/synapse/push/pusherpool.py b/synapse/push/pusherpool.py index 5a4e73ccd6..b2c92ce683 100644 --- a/synapse/push/pusherpool.py +++ b/synapse/push/pusherpool.py @@ -140,6 +140,10 @@ class PusherPool: @defer.inlineCallbacks def on_new_notifications(self, min_stream_id, max_stream_id): + if not self.pushers: + # nothing to do here. + return + try: users_affected = yield self.store.get_push_action_users_in_range( min_stream_id, max_stream_id @@ -155,6 +159,10 @@ class PusherPool: @defer.inlineCallbacks def on_new_receipts(self, min_stream_id, max_stream_id, affected_room_ids): + if not self.pushers: + # nothing to do here. + return + try: # Need to subtract 1 from the minimum because the lower bound here # is not inclusive -- cgit 1.5.1 From e07384c4e16a8a97966c58d604ef95ac1614cafa Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Fri, 22 Feb 2019 10:57:15 +0000 Subject: Add prometheus metrics for number of badge update pushes. (#4709) We're counting the number of push notifications, but not the number of badges; I'd like to see if they are significant. --- changelog.d/4709.misc | 1 + synapse/push/httppusher.py | 33 +++++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 changelog.d/4709.misc (limited to 'synapse/push') diff --git a/changelog.d/4709.misc b/changelog.d/4709.misc new file mode 100644 index 0000000000..ca47a6f327 --- /dev/null +++ b/changelog.d/4709.misc @@ -0,0 +1 @@ +Add prometheus metrics for number of badge update pushes. diff --git a/synapse/push/httppusher.py b/synapse/push/httppusher.py index 98d8d9560b..899a5253d8 100644 --- a/synapse/push/httppusher.py +++ b/synapse/push/httppusher.py @@ -32,9 +32,25 @@ if six.PY3: logger = logging.getLogger(__name__) -http_push_processed_counter = Counter("synapse_http_httppusher_http_pushes_processed", "") +http_push_processed_counter = Counter( + "synapse_http_httppusher_http_pushes_processed", + "Number of push notifications successfully sent", +) -http_push_failed_counter = Counter("synapse_http_httppusher_http_pushes_failed", "") +http_push_failed_counter = Counter( + "synapse_http_httppusher_http_pushes_failed", + "Number of push notifications which failed", +) + +http_badges_processed_counter = Counter( + "synapse_http_httppusher_badge_updates_processed", + "Number of badge updates successfully sent", +) + +http_badges_failed_counter = Counter( + "synapse_http_httppusher_badge_updates_failed", + "Number of badge updates which failed", +) class HttpPusher(object): @@ -346,6 +362,10 @@ class HttpPusher(object): @defer.inlineCallbacks def _send_badge(self, badge): + """ + Args: + badge (int): number of unread messages + """ logger.info("Sending updated badge count %d to %s", badge, self.name) d = { 'notification': { @@ -366,14 +386,11 @@ class HttpPusher(object): } } try: - resp = yield self.http_client.post_json_get_json(self.url, d) + yield self.http_client.post_json_get_json(self.url, d) + http_badges_processed_counter.inc() except Exception as e: logger.warning( "Failed to send badge count to %s: %s %s", self.name, type(e), e, ) - defer.returnValue(False) - rejected = [] - if 'rejected' in resp: - rejected = resp['rejected'] - defer.returnValue(rejected) + http_badges_failed_counter.inc() -- cgit 1.5.1 From 1d9df51ff1129f86157e54f0523cec0ddadcbd41 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 22 Feb 2019 14:47:48 +0000 Subject: Correctly handle null data in HttpPusher --- synapse/push/httppusher.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'synapse/push') diff --git a/synapse/push/httppusher.py b/synapse/push/httppusher.py index 899a5253d8..e65f8c63d3 100644 --- a/synapse/push/httppusher.py +++ b/synapse/push/httppusher.py @@ -97,6 +97,11 @@ class HttpPusher(object): pusherdict['pushkey'], ) + if self.data is None: + raise PusherConfigException( + "data can not be null for HTTP pusher" + ) + if 'url' not in self.data: raise PusherConfigException( "'url' required in data for HTTP pusher" -- cgit 1.5.1 From a164134a53417bfa3f126671b02be7e83376aacd Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 22 Feb 2019 14:48:06 +0000 Subject: Drop logging level of creating a pusher --- synapse/push/pusher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'synapse/push') diff --git a/synapse/push/pusher.py b/synapse/push/pusher.py index 368d5094be..b33f2a357b 100644 --- a/synapse/push/pusher.py +++ b/synapse/push/pusher.py @@ -56,7 +56,7 @@ class PusherFactory(object): f = self.pusher_types.get(kind, None) if not f: return None - logger.info("creating %s pusher for %r", kind, pusherdict) + logger.debug("creating %s pusher for %r", kind, pusherdict) return f(self.hs, pusherdict) def _create_email_pusher(self, _hs, pusherdict): -- cgit 1.5.1 From f2891d248756c968c346df052c796c0c69d6e764 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 22 Feb 2019 15:18:19 +0000 Subject: Correctly handle PusherConfigException --- synapse/push/pusherpool.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'synapse/push') diff --git a/synapse/push/pusherpool.py b/synapse/push/pusherpool.py index b2c92ce683..af82e02b46 100644 --- a/synapse/push/pusherpool.py +++ b/synapse/push/pusherpool.py @@ -19,6 +19,7 @@ import logging from twisted.internet import defer from synapse.metrics.background_process_metrics import run_as_background_process +from synapse.push import PusherConfigException from synapse.push.pusher import PusherFactory logger = logging.getLogger(__name__) @@ -222,6 +223,14 @@ class PusherPool: """ try: p = self.pusher_factory.create_pusher(pusherdict) + except PusherConfigException as e: + logger.warning( + "Pusher incorrectly configured user=%s, appid=%s, pushkey=%s: %s", + pusherdict.get('user_name'), + pusherdict.get('app_id'), + pusherdict.get('pushkey'), + e, + ) except Exception: logger.exception("Couldn't start a pusher: caught Exception") return -- cgit 1.5.1 From b82c9cf4629040681c7d06846422705734acd110 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 22 Feb 2019 15:27:40 +0000 Subject: Add missing return --- synapse/push/pusherpool.py | 1 + 1 file changed, 1 insertion(+) (limited to 'synapse/push') diff --git a/synapse/push/pusherpool.py b/synapse/push/pusherpool.py index af82e02b46..abf1a1a9c1 100644 --- a/synapse/push/pusherpool.py +++ b/synapse/push/pusherpool.py @@ -231,6 +231,7 @@ class PusherPool: pusherdict.get('pushkey'), e, ) + return except Exception: logger.exception("Couldn't start a pusher: caught Exception") return -- cgit 1.5.1