Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

feat: add metric for all mobile bridge "unregistered" user drops #1423

Merged
merged 3 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion autopush/router/adm.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def _route(self, notification, uaid_data):
self.metrics.increment("notification.bridge.error",
tags=make_tags(
self._base_tags,
reason="connection_unavailable"))
reason="connection unavailable"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI this denormalized the reason, it's an underscore everywhere else

raise RouterException("Server error", status_code=502,
errno=902,
log_exception=False)
Expand Down
9 changes: 1 addition & 8 deletions autopush/router/apnsrouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,14 @@ def _route(self, notification, router_data):
else:
reason = "unknown"
if isinstance(e, RouterException) and e.status_code in [404, 410]:
self.metrics.increment(
"notification.bridge.connection.error",
tags=make_tags(
self._base_tags,
application=rel_channel,
reason="unregistered"
))
raise RouterException(
str(e),
status_code=e.status_code,
errno=106,
response_body="User is no longer registered",
log_exception=False
)
self.metrics.increment("notification.bridge.connection.error",
self.metrics.increment("notification.bridge.error",
tags=make_tags(self._base_tags,
application=rel_channel,
reason=reason))
Expand Down
6 changes: 5 additions & 1 deletion autopush/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2477,8 +2477,10 @@ def test_registration(self):
assert ca_data['body'] == base64url_encode(data)

@inlineCallbacks
def test_aaa_send_410(self):
def test_send_410(self):
self._add_router()
mock_metrics = Mock()
self.ep.db.metrics = mock_metrics
# get the senderid
url = "{}/v1/{}/{}/registration".format(
self.ep.conf.endpoint_url,
Expand Down Expand Up @@ -2515,6 +2517,8 @@ def test_aaa_send_410(self):
body=data
)
assert response.code == 410
assert mock_metrics.increment.call_args[1]['tags'] == \
['code:410', 'router:apns', 'vapid:True']
self.assertRaises(
ItemNotFound,
self.ep.db.router.get_uaid,
Expand Down
6 changes: 3 additions & 3 deletions autopush/tests/test_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def test_bad_send(self):
'User is no longer registered')

@inlineCallbacks
def test_aaaa_fail_send(self):
def test_fail_send(self):
def throw(*args, **kwargs):
raise HTTP20Error("oops")

Expand All @@ -279,7 +279,7 @@ def throw(*args, **kwargs):
'processing request'
assert self.metrics.increment.called
assert self.metrics.increment.call_args[0][0] == \
'notification.bridge.connection.error'
'notification.bridge.error'
self.flushLoggedErrors()

@inlineCallbacks
Expand All @@ -300,7 +300,7 @@ def throw(*args, **kwargs):
'processing request'
assert self.metrics.increment.called
assert self.metrics.increment.call_args[0][0] == \
'notification.bridge.connection.error'
'notification.bridge.error'
self.flushLoggedErrors()

def test_too_many_connections(self):
Expand Down
8 changes: 8 additions & 0 deletions autopush/web/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,14 @@ def _router_fail_err(self, fail, router_type=None, vapid=False, uaid=None):
# reporting a not found and they're mobile.
if exc.status_code in [404, 410] and router_type in [
'apns', 'fcm', 'adm']:
self._base_tags.update({
"platform": router_type,
"reason": "unregistered",
})
AzureMarker marked this conversation as resolved.
Show resolved Hide resolved
self.metrics.increment(
"notification.bridge.error",
tags=self._base_tags)

self.db.router.drop_user(uaid)
self._router_response(exc, router_type, vapid)

Expand Down