Expose set_metric_tag consistently.

Just a no-op on the statsd implementation.
This commit is contained in:
Dave Shawley 2016-01-27 10:46:23 -05:00
parent 64c136f635
commit 81bfee6ec3
4 changed files with 30 additions and 0 deletions

View file

@ -21,6 +21,7 @@ implements the same interface:
self.record_timing(self.request.request_time(), 'request', 'lookup')
.. method:: increase_counter(*path, amount=1)
:noindex:
:param path: counter path to increment
:keyword int amount: value to increase the counter by
@ -30,6 +31,7 @@ implements the same interface:
self.increase_counter('db', 'query', 'foo')
.. method:: execution_timer(*path)
:noindex:
:param path: timing path to record
@ -41,6 +43,16 @@ implements the same interface:
with self.execution_timer('db', 'query', 'foo'):
rows = yield self.session.query('SELECT * FROM foo')
.. method:: set_metric_tag(tag, value)
:noindex:
:param str tag: the tag to set
:param str value: the value to assign to the tag
This method stores a tag and value pair to be reported with
metrics. It is only implemented on back-ends that support
tagging metrics (e.g., :class:`sprockets.mixins.metrics.InfluxDBMixin`)
Statsd Implementation
---------------------

View file

@ -14,6 +14,16 @@ class SimpleHandler(metrics.StatsdMixin, web.RequestHandler):
"""
@gen.coroutine
def prepare(self):
maybe_future = super(SimpleHandler, self).prepare()
if gen.is_future(maybe_future):
yield maybe_future
if 'Correlation-ID' in self.request.headers:
self.set_metric_tag('correlation_id',
self.request.headers['Correlation-ID'])
@gen.coroutine
def get(self):
yield gen.sleep(0.25)

View file

@ -39,6 +39,9 @@ class StatsdMixin(object):
settings.setdefault('port', '8125')
self.__status_code = None
def set_metric_tag(self, tag, value):
"""Ignored for statsd since it does not support tagging."""
def set_status(self, status_code, reason=None):
# Extended to track status code to avoid referencing the
# _status internal variable

View file

@ -107,6 +107,11 @@ class StatsdMethodTimingTests(testing.AsyncHTTPTestCase):
for path, value, stat_type in self.statsd.find_metrics(prefix, 'ms'):
assert_between(250.0, float(value), 300.0)
def test_that_add_metric_tag_is_ignored(self):
response = self.fetch('/',
headers={'Correlation-ID': 'does not matter'})
self.assertEqual(response.code, 204)
class InfluxDbTests(testing.AsyncHTTPTestCase):