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

Commit

Permalink
bug: regression: wrap metric calls in thread handler
Browse files Browse the repository at this point in the history
The metric calls were blocking. It was recommended that they be wrapped
by a discrete thread handler.

Issue: #1408
  • Loading branch information
jrconlin committed Jul 7, 2020
1 parent 5299977 commit 31ae364
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
18 changes: 12 additions & 6 deletions autopush/metrics.py
Expand Up @@ -93,20 +93,26 @@ def _make_tags(self, tags):

def increment(self, name, count=1, tags=None, **kwargs):
threads.deferToThread(
self._client.incr(self._prefix_name(name), count,
tags=self._make_tags(tags))
self._client.incr,
self._prefix_name(name),
count,
tags=self._make_tags(tags)
)

def gauge(self, name, count, tags=None, **kwargs):
threads.deferToThread(
self._client.gauge(self._prefix_name(name), count,
tags=self._make_tags(tags))
self._client.gauge,
self._prefix_name(name),
count,
tags=self._make_tags(tags)
)

def timing(self, name, duration, tags=None, **kwargs):
threads.deferToThread(
self._client.timing(self._prefix_name(name), value=duration,
tags=self._make_tags(tags))
self._client.timing,
self._prefix_name(name),
value=duration,
tags=self._make_tags(tags)
)


Expand Down
13 changes: 8 additions & 5 deletions autopush/websocket.py
Expand Up @@ -91,7 +91,7 @@
from autopush.exceptions import MessageOverloadException, ItemNotFound
from autopush.noseplugin import track_object
from autopush.protocol import IgnoreBody
from autopush.metrics import IMetrics, make_tags # noqa
from autopush.metrics import IMetrics # noqa
from autopush.ssl import AutopushSSLContextFactory # noqa
from autopush.utils import (
parse_user_agent,
Expand Down Expand Up @@ -895,7 +895,7 @@ def process_notifications(self):
self.ps._check_notifications = False
self.ps._more_notifications = True

d = self.deferToThread(self.webpush_fetch())
d = self.deferToThread(self.webpush_fetch)
d.addCallback(self.finish_notifications)
d.addErrback(self.error_notification_overload)
d.addErrback(self.trap_cancel)
Expand Down Expand Up @@ -1319,7 +1319,9 @@ def process_nack(self, data):
user_agent=self.ps.user_agent, message_id=str(version),
code=code, **self.ps.raw_agent)
mcode = code if code in NACK_CODES else 0
self.metrics.increment('ua.command.nack', tags=make_tags(code=mcode))
self.metrics.increment(
'ua.command.nack',
tags=self.metrics.make_tags(code=mcode))
self.ps.stats.nacks += 1

def check_missed_notifications(self, results, resume=False):
Expand Down Expand Up @@ -1373,8 +1375,9 @@ def send_notification(self, update):
def emit_send_metrics(self, notif):
if notif.topic:
self.metrics.increment("ua.notification.topic")
self.metrics.increment('ua.message_data', notif.data_length,
tags=make_tags(source=notif.source))
self.metrics.increment(
'ua.message_data', notif.data_length,
tags=self.metrics.make_tags(source=notif.source))


class PushServerFactory(WebSocketServerFactory):
Expand Down

0 comments on commit 31ae364

Please sign in to comment.