diff --git a/autopush/router/apnsrouter.py b/autopush/router/apnsrouter.py index 7f21325b..52875904 100644 --- a/autopush/router/apnsrouter.py +++ b/autopush/router/apnsrouter.py @@ -37,6 +37,7 @@ def _connect(self): def __init__(self, ap_settings, router_conf): """Create a new APNS router and connect to APNS""" self.ap_settings = ap_settings + self._base_tags = [] self.config = router_conf self.default_title = router_conf.get("default_title", "SimplePush") self.default_body = router_conf.get("default_body", "New Alert") @@ -87,6 +88,10 @@ def _route(self, notification, router_data): self.messages[now] = {"token": token, "payload": payload} # TODO: Add listener for error handling. self.apns.gateway_server.register_response_listener(self._error) + self.ap_settings.metrics.increment( + "updates.client.bridge.apns.attempted", + self._base_tags) + self.apns.gateway_server.send_notification(token, payload, now) # cleanup sent messages @@ -94,6 +99,9 @@ def _route(self, notification, router_data): for time_sent in self.messages.keys(): if time_sent < now - self.config.get("expry", 10): del self.messages[time_sent] + self.ap_settings.metrics.increment( + "updates.client.bridge.apns.succeed", + self._base_tags) return RouterResponse(status_code=200, response_body="Message sent") def _error(self, err): diff --git a/autopush/router/gcm.py b/autopush/router/gcm.py index bdb8ef74..1adeb63f 100644 --- a/autopush/router/gcm.py +++ b/autopush/router/gcm.py @@ -23,6 +23,8 @@ def __init__(self, ap_settings, router_conf): self.dryRun = router_conf.get("dryrun", False) self.collapseKey = router_conf.get("collapseKey", "simplepush") self.senderIDs = router_conf.get("senderIDs") + self.metrics = ap_settings.metrics + self._base_tags = [] if not self.senderIDs: self.senderIDs = SenderIDs(router_conf) try: @@ -103,6 +105,8 @@ def _route(self, notification, router_data): except Exception, e: raise self._error("Unhandled exception in GCM Routing: %s" % e, 500) + self.metrics.increment("updates.client.bridge.gcm.attempted", + self._base_tags) return self._process_reply(result) def _error(self, err, status, **kwargs): @@ -144,4 +148,6 @@ def _process_reply(self, reply): raise RouterException("GCM failure to deliver", status_code=503, response_body="Please try request later.") + self.metrics.increment("updates.client.bridge.gcm.succeeded", + self._base_tags) return RouterResponse(status_code=200, response_body="Message Sent") diff --git a/autopush/tests/test_router.py b/autopush/tests/test_router.py index 987c58b1..b7e05c53 100644 --- a/autopush/tests/test_router.py +++ b/autopush/tests/test_router.py @@ -252,7 +252,12 @@ def throw_ex(): raise AttributeError fsenderids = Mock() fsenderids.choose_ID.side_effect = throw_ex - self.assertRaises(IOError, GCMRouter, {}, {"senderIDs": fsenderids}) + settings = AutopushSettings( + hostname="localhost", + statsd_host=None, + ) + self.assertRaises(IOError, GCMRouter, settings, + {"senderIDs": fsenderids}) def test_register(self): result = self.router.register("uaid", {"token": "connect_data"})