From 6d98e9b806b8daca0e16aa36631f481b202d4326 Mon Sep 17 00:00:00 2001 From: Ryan Mclean Date: Thu, 8 Dec 2016 15:48:32 -0500 Subject: [PATCH] Remove prepending host name --- README.rst | 1 - sprockets/mixins/metrics/statsd.py | 14 ++++---------- tests.py | 18 +++++++----------- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/README.rst b/README.rst index d5ee068..357d3fb 100644 --- a/README.rst +++ b/README.rst @@ -54,7 +54,6 @@ Settings :port: The Statsd port :prepend_metric_type: Optional flag to prepend bucket path with the StatsD metric type -:prepend_hostname: Optional flag to prepend bucket path with the hostname InfluxDB Mixin -------------- diff --git a/sprockets/mixins/metrics/statsd.py b/sprockets/mixins/metrics/statsd.py index 0e3d48e..0284102 100644 --- a/sprockets/mixins/metrics/statsd.py +++ b/sprockets/mixins/metrics/statsd.py @@ -120,20 +120,17 @@ class StatsDCollector(object): :param str namespace: The StatsD bucket to write metrics into. :param bool prepend_metric_type: Optional flag to prepend bucket path with the StatsD metric type - :param bool prepend_hostname: Optional flag to prepend bucket path with - the hostname """ METRIC_TYPES = {'c': 'counters', 'ms': 'timers'} def __init__(self, host, port, namespace='sprockets', - prepend_metric_type=True, prepend_hostname=True): + prepend_metric_type=True): self._host = host self._port = int(port) self._namespace = namespace self._prepend_metric_type = prepend_metric_type - self._prepend_hostname = prepend_hostname self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0) def send(self, path, value, metric_type): @@ -169,8 +166,7 @@ class StatsDCollector(object): """Get prefixes where applicable Add metric prefix counters, timers respectively if - :attr:`prepend_metric_type` flag is True. Adds hostname prefix - if :attr:`prepend_hostname` is true. + :attr:`prepend_metric_type` flag is True. :param str metric_type: The metric type :rtype: list @@ -179,8 +175,6 @@ class StatsDCollector(object): prefixes = [] if self._prepend_metric_type: prefixes.append(self.METRIC_TYPES[metric_type]) - if self._prepend_hostname: - prefixes.append(socket.gethostname()) return prefixes @@ -191,8 +185,8 @@ def install(application, **kwargs): install the collector into. :param kwargs: keyword parameters to pass to the :class:`StatsDCollector` initializer. - :returns: :data:`True` if the client was installed by this call - and :data:`False` otherwise. + :returns: :data:`True` if the client was installed successfully, + or :data:`False` otherwise. - **host** The StatsD host. If host is not specified, the ``STATSD_HOST`` environment variable, or default `127.0.0.1`, diff --git a/tests.py b/tests.py index 7ba58e3..e4bb284 100644 --- a/tests.py +++ b/tests.py @@ -49,7 +49,8 @@ class StatsdMetricCollectionTests(testing.AsyncHTTPTestCase): self.statsd = FakeStatsdServer(self.io_loop) statsd.install(self.application, **{'namespace': 'testing', 'host': self.statsd.sockaddr[0], - 'port': self.statsd.sockaddr[1]}) + 'port': self.statsd.sockaddr[1], + 'prepend_metric_type': True}) def tearDown(self): self.statsd.close() @@ -59,8 +60,7 @@ class StatsdMetricCollectionTests(testing.AsyncHTTPTestCase): response = self.fetch('/') self.assertEqual(response.code, 204) - expected = 'testing.timers.{}.SimpleHandler.GET.204'.format( - socket.gethostname().replace('.', '-')) + expected = 'testing.timers.SimpleHandler.GET.204' for path, value, stat_type in self.statsd.find_metrics(expected, 'ms'): assert_between(250.0, float(value), 500.0) @@ -68,8 +68,7 @@ class StatsdMetricCollectionTests(testing.AsyncHTTPTestCase): response = self.fetch('/', method='POST', body='') self.assertEqual(response.code, 204) - prefix = 'testing.counters.{}.request.path'.format( - socket.gethostname().replace('.', '-')) + prefix = 'testing.counters.request.path' for path, value, stat_type in self.statsd.find_metrics(prefix, 'c'): self.assertEqual(int(value), 1) @@ -77,8 +76,7 @@ class StatsdMetricCollectionTests(testing.AsyncHTTPTestCase): response = self.fetch('/counters/path/5', method='POST', body='') self.assertEqual(response.code, 204) - prefix = 'testing.counters.{}.path'.format( - socket.gethostname().replace('.', '-')) + prefix = 'testing.counters.path' for path, value, stat_type in self.statsd.find_metrics(prefix, 'c'): self.assertEqual(int(value), 5) @@ -86,8 +84,7 @@ class StatsdMetricCollectionTests(testing.AsyncHTTPTestCase): response = self.fetch('/counters/one.two.three/0.25') self.assertEqual(response.code, 204) - prefix = 'testing.timers.{}.one.two.three'.format( - socket.gethostname().replace('.', '-')) + prefix = 'testing.timers.one.two.three' for path, value, stat_type in self.statsd.find_metrics(prefix, 'ms'): assert_between(250.0, float(value), 300.0) @@ -114,8 +111,7 @@ class StatsdConfigurationTests(testing.AsyncHTTPTestCase): statsd.install(self.application, **{'namespace': 'testing', 'host': self.statsd.sockaddr[0], 'port': self.statsd.sockaddr[1], - 'prepend_metric_type': False, - 'prepend_hostname': False}) + 'prepend_metric_type': False}) def tearDown(self): self.statsd.close()