Add timing and use pipelines

With so many values coming in a pipeline makes more sense.
This commit is contained in:
Clint Byrum 2015-11-11 16:16:01 -08:00
parent 1e97b12e5c
commit b6e9bc8cce
2 changed files with 13 additions and 2 deletions

View File

@ -39,6 +39,7 @@ def get_statsd_client():
_statsd_client = statsd.StatsClient(cfg.CONF.counters2statsd.host,
cfg.CONF.counters2statsd.port,
cfg.CONF.counters2statsd.prefix)
_statsd_client = _statsd_client.pipeline()
return _statsd_client
@ -96,6 +97,10 @@ class AttachmentResult(testtools.StreamResult):
for groupname, values in counters.items():
if not isinstance(values, dict):
continue
if groupname == '__meta__':
if 'delta_seconds' in values:
client.timing(
'testrun', values['delta_seconds'] * 1000)
for k, v in values.items():
k = '{}.{}'.format(groupname, k)
try:
@ -103,3 +108,4 @@ class AttachmentResult(testtools.StreamResult):
except ValueError:
continue
client.incr(k, v)
client.send()

View File

@ -31,8 +31,12 @@ class TestOpenStackQaTols(base.TestCase):
@mock.patch('statsd.StatsClient')
def test_add_test_run_attachments(self, statsd_mock):
mock_client = mock.MagicMock('statsd_client')
mock_client.incr = mock.MagicMock('statds_incr')
statsd_mock.return_value = mock_client
mock_client.pipeline = mock.MagicMock('statsd_pipeline')
mock_pipeline = mock.MagicMock('Pipeline')
mock_pipeline.incr = mock.MagicMock('statds_incr')
mock_pipeline.send = mock.MagicMock('statds_send')
mock_client.pipeline.return_value = mock_pipeline
fake_counters = {'mysql': {'Queries': 10}}
fake_counters = json.dumps(fake_counters).encode('utf-8')
self.assertTrue(counters2statsd.AttachmentResult.enabled())
@ -40,4 +44,5 @@ class TestOpenStackQaTols(base.TestCase):
result.status(file_name='counters.json', file_bytes=fake_counters)
result.stopTestRun()
statsd_mock.assert_called_with('localhost', 8125, None)
mock_client.incr.assert_called_with('mysql.Queries', 10)
mock_pipeline.incr.assert_called_with('mysql.Queries', 10)
mock_pipeline.send.assert_called_with()