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

Commit

Permalink
feat: capture and metric item not found instead of log
Browse files Browse the repository at this point in the history
There's no need to log exceptions failing to save a message for a
user that has been deleted. Now a metric will be emitted instead.

This also tweaks the tox runner to no longer include object memory
tracking by default.

Closes #811
  • Loading branch information
bbangert committed Mar 1, 2017
1 parent feccb86 commit 199e665
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
39 changes: 37 additions & 2 deletions autopush/tests/test_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

import twisted.internet.base
from autopush.tests.test_db import make_webpush_notification
from boto.dynamodb2.exceptions import ProvisionedThroughputExceededException
from boto.dynamodb2.exceptions import ProvisionedThroughputExceededException, \
ItemNotFound
from boto.exception import JSONResponseError
from cyclone.web import Application
from mock import Mock, patch
Expand Down Expand Up @@ -459,7 +460,41 @@ def wait_for_agent_call(): # pragma: nocover
reactor.callLater(0.1, wait_for_agent_call)

mock_metrics.increment.assert_called_with(
"error.notify_uaid_failure", tags=None)
"client.notify_uaid_failure", tags=None)
d.callback(True)
reactor.callLater(0.1, wait_for_agent_call)
return d

def test_close_with_delivery_cleanup_and_no_get_uaid_error(self):
self._connect()
self.proto.ps.uaid = uuid.uuid4().hex
self.proto.ap_settings.clients["asdf"] = self.proto
chid = str(uuid.uuid4())

# Stick an un-acked direct notification in
self.proto.ps.direct_updates[chid] = 12

# Apply some mocks
self.proto.ap_settings.storage.save_notification = Mock()
self.proto.ap_settings.router.get_uaid = mock_get = Mock()
self.proto.ps.metrics = mock_metrics = Mock()

def raise_item(*args, **kwargs):
raise ItemNotFound()

mock_get.side_effect = raise_item

# Close the connection
self.proto.onClose(True, None, None)

d = Deferred()

def wait_for_agent_call(): # pragma: nocover
if not mock_metrics.mock_calls:
reactor.callLater(0.1, wait_for_agent_call)

mock_metrics.increment.assert_called_with(
"client.lookup_uaid_failure", tags=None)
d.callback(True)
reactor.callLater(0.1, wait_for_agent_call)
return d
Expand Down
10 changes: 9 additions & 1 deletion autopush/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,14 +579,22 @@ def _lookup_node(self, results):
self.ps.uaid
)
d.addCallback(self._notify_node)
d.addErrback(self._trap_uaid_not_found)
d.addErrback(self.log_failure,
extra="Failed to get UAID for redeliver")

def _trap_uaid_not_found(self, fail):
# type: (Failure) -> None
"""Traps UAID not found error"""
fail.trap(ItemNotFound)
self.ps.metrics.increment("client.lookup_uaid_failure",
tags=self.base_tags)

def _notify_node(self, result):
"""Checks the result of lookup node to send the notify if the client is
connected elsewhere now"""
if not result:
self.ps.metrics.increment("error.notify_uaid_failure",
self.ps.metrics.increment("client.notify_uaid_failure",
tags=self.base_tags)
return

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ deps = -rtest-requirements.txt
usedevelop = True
passenv = SKIP_INTEGRATION
commands =
nosetests {posargs} --with-object-tracker autopush
nosetests {posargs} autopush
install_command = pip install --pre {opts} {packages}

[testenv:pypy]
Expand Down

0 comments on commit 199e665

Please sign in to comment.