def test_logging_metrics(self): """Verify LoggingMetrics work""" AppWithMetrics.run(values_source_list=[configman_keys({})]) assert 'increment: increment_key=1 tags=[]' in self.caplog.text assert 'gauge: gauge_key=10 tags=[]' in self.caplog.text assert 'timing: timing_key=100 tags=[]' in self.caplog.text assert 'histogram: histogram_key=1000 tags=[]' in self.caplog.text
def test_metrics(self, metricsmock): """Verify LoggingMetrics work""" with metricsmock as mm: AppWithMetrics.run(values_source_list=[configman_keys({})]) assert mm.has_record('incr', stat='increment_key', value=1) assert mm.has_record('gauge', stat='gauge_key', value=10) assert mm.has_record('timing', stat='timing_key', value=100) assert mm.has_record('histogram', stat='histogram_key', value=1000)
def test_configmanize_dict(self): d = { "HELLO": "howdy", "JELL__O": "gelatin", "database_hostname": 'localhost', "resources__postgres__database_hostname": 'more-localhost', } r = configman_keys(d) self.assertTrue("HELLO" in r) self.assertTrue("JELL__O" in r) self.assertTrue("database_hostname" in r) self.assertTrue("resources__postgres__database_hostname" not in r) self.assertTrue("resources.postgres.database_hostname" in r)
def test_statsd_metrics(self): with mock.patch('datadog.dogstatsd.statsd') as mock_statsd: vsl = configman_keys({ 'metricscfg.statsd_host': 'localhost', 'metricscfg.statsd_port': '8125', }) AppWithMetrics.run(values_source_list=[vsl]) # Verify these didn't get logged assert 'increment: increment_key' not in self.caplog.text assert 'gauge: gauge_key' not in self.caplog.text assert 'timing: timing_key' not in self.caplog.text assert 'histogram: histogram_key' not in self.caplog.text # Verify they did get called on mock_statsd. Do this by converting the mock_calls call # objects to strings so they're easy to verify. mock_calls = [str(call) for call in mock_statsd.mock_calls] assert 'call.increment(\'increment_key\')' in mock_calls assert 'call.gauge(\'gauge_key\', value=10)' in mock_calls assert 'call.timing(\'timing_key\', value=100)' in mock_calls assert 'call.histogram(\'histogram_key\', value=1000)' in mock_calls
# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. from __future__ import absolute_import, division, print_function from os import environ from configman.dotdict import configman_keys environment = configman_keys(environ) environment.always_ignore_mismatches = True