mirror of
https://github.com/sprockets/sprockets.mixins.metrics.git
synced 2024-11-25 11:19:53 +00:00
Use get_status for status code
This commit is contained in:
parent
e470d5ca53
commit
a83d5ef771
3 changed files with 17 additions and 17 deletions
|
@ -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