mirror of
https://github.com/sprockets/sprockets.mixins.metrics.git
synced 2024-11-22 03:00:25 +00:00
Merge pull request #23 from nvllsvm/master
Use get_status to retrieve status code
This commit is contained in:
commit
fe0ba5360c
5 changed files with 24 additions and 19 deletions
|
@ -3,6 +3,10 @@
|
|||
Release History
|
||||
===============
|
||||
|
||||
`3.0.3`_ (24-Mar-2017)
|
||||
----------------------
|
||||
- Fix retrival of status code.
|
||||
|
||||
`3.0.2`_ (12-Dec-2016)
|
||||
----------------------
|
||||
- Fix influxdb test that fails intermittently.
|
||||
|
@ -63,7 +67,8 @@ Release History
|
|||
- Add :class:`sprockets.mixins.metrics.InfluxDBMixin`
|
||||
- Add :class:`sprockets.mixins.metrics.influxdb.InfluxDBConnection`
|
||||
|
||||
.. _Next Release: https://github.com/sprockets/sprockets.mixins.metrics/compare/3.0.2...master
|
||||
.. _Next Release: https://github.com/sprockets/sprockets.mixins.metrics/compare/3.0.3...master
|
||||
.. _3.0.3: https://github.com/sprockets/sprockets.mixins.metrics/compare/3.0.2...3.0.3
|
||||
.. _3.0.2: https://github.com/sprockets/sprockets.mixins.metrics/compare/3.0.1...3.0.2
|
||||
.. _3.0.1: https://github.com/sprockets/sprockets.mixins.metrics/compare/3.0.0...3.0.1
|
||||
.. _3.0.0: https://github.com/sprockets/sprockets.mixins.metrics/compare/2.1.1...3.0.0
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
version_info = (3, 0, 2)
|
||||
version_info = (3, 0, 3)
|
||||
__version__ = '.'.join(str(v) for v in version_info)
|
||||
__all__ = ['__version__', 'version_info']
|
||||
|
|
|
@ -93,7 +93,7 @@ class InfluxDBMixin(object):
|
|||
|
||||
def on_finish(self):
|
||||
super(InfluxDBMixin, self).on_finish()
|
||||
self.set_metric_tag('status_code', self._status_code)
|
||||
self.set_metric_tag('status_code', self.get_status())
|
||||
self.record_timing(self.request.request_time(), 'duration')
|
||||
self.application.influxdb.submit(
|
||||
self.settings[SETTINGS_KEY]['measurement'],
|
||||
|
|
|
@ -15,7 +15,6 @@ class StatsdMixin(object):
|
|||
|
||||
def initialize(self):
|
||||
super(StatsdMixin, self).initialize()
|
||||
self.__status_code = None
|
||||
|
||||
def set_metric_tag(self, tag, value):
|
||||
"""Ignored for statsd since it does not support tagging.
|
||||
|
@ -90,21 +89,7 @@ class StatsdMixin(object):
|
|||
super(StatsdMixin, self).on_finish()
|
||||
self.record_timing(self.request.request_time(),
|
||||
self.__class__.__name__, self.request.method,
|
||||
self.__status_code)
|
||||
|
||||
def set_status(self, status_code, reason=None):
|
||||
"""Extend tornado `set_status` method to track status code
|
||||
to avoid referencing the _status internal variable
|
||||
|
||||
:param int status_code: Response status code. If ``reason``
|
||||
is ``None``, it must be present in `httplib.responses
|
||||
<http.client.responses>`.
|
||||
:param string reason: Human-readable reason phrase describing
|
||||
the status code. If ``None``, it will be filled in from
|
||||
`httplib.responses <http.client.responses>`.
|
||||
"""
|
||||
self.__status_code = status_code
|
||||
super(StatsdMixin, self).set_status(status_code, reason=reason)
|
||||
self.get_status())
|
||||
|
||||
|
||||
class StatsDCollector(object):
|
||||
|
|
15
tests.py
15
tests.py
|
@ -30,6 +30,12 @@ class CounterBumper(statsd.StatsdMixin, web.RequestHandler):
|
|||
self.set_status(204)
|
||||
|
||||
|
||||
class DefaultStatusCode(statsd.StatsdMixin, web.RequestHandler):
|
||||
|
||||
def get(self):
|
||||
pass
|
||||
|
||||
|
||||
def assert_between(low, value, high):
|
||||
if not (low <= value < high):
|
||||
raise AssertionError('Expected {} to be between {} and {}'.format(
|
||||
|
@ -42,6 +48,7 @@ class StatsdMetricCollectionTests(testing.AsyncHTTPTestCase):
|
|||
self.application = web.Application([
|
||||
web.url('/', examples.statsd.SimpleHandler),
|
||||
web.url('/counters/(.*)/([.0-9]*)', CounterBumper),
|
||||
web.url('/status_code', DefaultStatusCode),
|
||||
])
|
||||
return self.application
|
||||
|
||||
|
@ -95,6 +102,14 @@ class StatsdMetricCollectionTests(testing.AsyncHTTPTestCase):
|
|||
headers={'Correlation-ID': 'does not matter'})
|
||||
self.assertEqual(response.code, 204)
|
||||
|
||||
def test_that_status_code_is_used_when_not_explicitly_set(self):
|
||||
response = self.fetch('/status_code')
|
||||
self.assertEqual(response.code, 200)
|
||||
|
||||
expected = 'testing.timers.DefaultStatusCode.GET.200'
|
||||
self.assertEqual(expected,
|
||||
list(self.statsd.find_metrics(expected, 'ms'))[0][0])
|
||||
|
||||
|
||||
class StatsdConfigurationTests(testing.AsyncHTTPTestCase):
|
||||
|
||||
|
|
Loading…
Reference in a new issue