mirror of
https://github.com/sprockets/sprockets.mixins.metrics.git
synced 2024-11-25 03:00:25 +00:00
InfluxDBMixin: Add test for set_metric_tag.
This commit is contained in:
parent
78a59d167d
commit
64c136f635
2 changed files with 26 additions and 0 deletions
|
@ -32,6 +32,16 @@ class SimpleHandler(metrics.InfluxDBMixin, 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):
|
||||
with self.execution_timer('sleepytime'):
|
||||
|
|
16
tests.py
16
tests.py
|
@ -1,6 +1,7 @@
|
|||
import logging
|
||||
import socket
|
||||
import time
|
||||
import uuid
|
||||
|
||||
from tornado import gen, testing, web
|
||||
import mock
|
||||
|
@ -190,3 +191,18 @@ class InfluxDbTests(testing.AsyncHTTPTestCase):
|
|||
response = self.fetch('/')
|
||||
self.assertEqual(response.code, 204)
|
||||
self.assertIs(cfg['db_connection'], conn)
|
||||
|
||||
def test_that_metric_tag_is_tracked(self):
|
||||
cid = str(uuid.uuid4())
|
||||
response = self.fetch('/', headers={'Correlation-ID': cid})
|
||||
self.assertEqual(response.code, 204)
|
||||
|
||||
for key, fields, timestamp in self.influx_messages:
|
||||
if key.startswith('my-service,'):
|
||||
tag_dict = dict(a.split('=') for a in key.split(',')[1:])
|
||||
self.assertEqual(tag_dict['correlation_id'],
|
||||
'"{}"'.format(cid))
|
||||
break
|
||||
else:
|
||||
self.fail('Expected to find "request" metric in {!r}'.format(
|
||||
list(self.application.influx_db['requests'])))
|
||||
|
|
Loading…
Reference in a new issue