mirror of
https://github.com/sprockets/sprockets.mixins.metrics.git
synced 2024-11-22 03:00:25 +00:00
MOBILE-9220 added newline to tcp messages, added tests
This commit is contained in:
parent
b5d1cae249
commit
6fd2cf4035
2 changed files with 20 additions and 0 deletions
|
@ -162,6 +162,7 @@ class StatsDCollector(object):
|
|||
"""
|
||||
msg = '{0}:{1}|{2}'.format(
|
||||
self._build_path(path, metric_type), value, metric_type)
|
||||
msg = self._build_udp_or_tcp_message(msg)
|
||||
|
||||
LOGGER.debug('Sending %s to %s:%s', msg.encode('ascii'),
|
||||
self._host, self._port)
|
||||
|
@ -174,6 +175,12 @@ class StatsDCollector(object):
|
|||
except (OSError, socket.error) as error: # pragma: nocover
|
||||
LOGGER.exception('Error sending statsd metric: %s', error)
|
||||
|
||||
def _build_udp_or_tcp_message(self, msg):
|
||||
if self._tcp is False:
|
||||
return msg
|
||||
|
||||
return msg + "\n"
|
||||
|
||||
def _build_path(self, path, metric_type):
|
||||
"""Return a normalized path.
|
||||
|
||||
|
|
13
tests.py
13
tests.py
|
@ -63,6 +63,13 @@ class TCPStatsdMetricCollectionTests(testing.AsyncHTTPTestCase):
|
|||
'protocol': 'tcp',
|
||||
'prepend_metric_type': True})
|
||||
|
||||
def test_that_tcp_message_appends_a_newline(self):
|
||||
orig = 'testing.timers.SimpleHandler.GET.204'
|
||||
expected = 'testing.timers.SimpleHandler.GET.204\n'
|
||||
|
||||
msg = self.application.statsd._build_udp_or_tcp_message(orig)
|
||||
self.assertEqual(msg, expected)
|
||||
|
||||
def test_that_http_method_call_is_recorded(self):
|
||||
response = self.fetch('/')
|
||||
self.assertEqual(response.code, 204)
|
||||
|
@ -171,6 +178,12 @@ class UDPStatsdMetricCollectionTests(testing.AsyncHTTPTestCase):
|
|||
self.statsd.close()
|
||||
super(UDPStatsdMetricCollectionTests, self).tearDown()
|
||||
|
||||
def test_that_udp_message_is_unchanged(self):
|
||||
expected = 'testing.timers.SimpleHandler.GET.204'
|
||||
|
||||
msg = self.application.statsd._build_udp_or_tcp_message(expected)
|
||||
self.assertEqual(msg, expected)
|
||||
|
||||
def test_that_http_method_call_is_recorded(self):
|
||||
response = self.fetch('/')
|
||||
self.assertEqual(response.code, 204)
|
||||
|
|
Loading…
Reference in a new issue