예제 #1
0
 def test_update_increment(self):
     mock = MagicMock()
     mock.incr.side_effect = Exception
     stats_client = StatsLogClient(client=mock,
                                   secrets_manager=mock,
                                   http_client=mock)
     name = 'collection_failure'
     value = 1
     self.assertFalse(stats_client.update_increment(name, value))
예제 #2
0
 def test_add_gauge_no_tags(self):
     mock = MagicMock()
     stats_client = StatsLogClient(client=mock,
                                   secrets_manager=mock,
                                   http_client=mock)
     name = 'test_stat'
     value = 0
     result = stats_client.add_gauge(name, value)
     mock.gauge.assert_called_once_with(name, value, delta=False, rate=1)
     self.assertTrue(result)
예제 #3
0
 def test_add_gauge_exception(self):
     mock = MagicMock()
     mock.gauge.side_effect = Exception('test')
     stats_client = StatsLogClient(client=mock,
                                   secrets_manager=mock,
                                   http_client=mock)
     name = 'test_stat'
     value = 0
     tags = {'tag1': 'tag1_value', 'tag2': 'tag2_value'}
     result = stats_client.add_gauge(name, value, tags)
     self.assertFalse(result)
예제 #4
0
 def test_update_increment_no_tags(self):
     mock = MagicMock()
     mock.incr.return_value = True
     stats_client = StatsLogClient(client=mock,
                                   secrets_manager=mock,
                                   http_client=mock)
     name = 'collection_failure'
     value = 1
     result = stats_client.update_increment(name, value)
     mock.incr.assert_called_once_with(name, value)
     self.assertTrue(result)
예제 #5
0
 def test_add_timing(self):
     mock = MagicMock()
     stats_client = StatsLogClient(client=mock,
                                   secrets_manager=mock,
                                   http_client=mock)
     stats_client.add_timing(Constants.DUMMY, Constants.DUMMY_NUM)
     mock.timing.assert_called_once_with(Constants.DUMMY,
                                         Constants.DUMMY_NUM)
     mock.timing.side_effect = Exception
     self.assertFalse(
         stats_client.add_timing(Constants.DUMMY, Constants.DUMMY_NUM))
예제 #6
0
 def test_add_gauge_defaults(self):
     mock = MagicMock()
     stats_client = StatsLogClient(client=mock,
                                   secrets_manager=mock,
                                   http_client=mock)
     name = 'test_stat'
     value = 0
     tags = {'tag1': 'tag1_value', 'tag2': 'tag2_value'}
     result = stats_client.add_gauge(name, value, tags)
     mock.gauge.assert_called_once_with(name,
                                        value,
                                        delta=False,
                                        rate=1,
                                        tags=tags)
     self.assertTrue(result)
예제 #7
0
 def worker_result(self, worker_ctx, _=None, exc_info=None):
     large_page = self.check_large_page(worker_ctx)
     stats_client = StatsLogClient()
     service_name = worker_ctx.service_name
     method_name = worker_ctx.entrypoint.method_name
     time_end = time()
     time_start = self.timestamps.pop(worker_ctx)
     elapsed = get_elapsed_milliseconds(time_end, time_start)
     monitor_calls_id = MonitoringProvider.get_monitor_id(service_name, method_name, False, large_page, exc_info)
     monitor_elapsed_id = MonitoringProvider.get_monitor_id(service_name, method_name, True, large_page, exc_info)
     # Increment the stats for function call counter
     stats_client.update_increment(monitor_calls_id, Constants.MONITOR_INCR_DEFAULT)
     # Add the timing for the function call time
     stats_client.add_timing(monitor_elapsed_id, elapsed)
예제 #8
0
 def wrapper(*args, **kwargs):
     stats = StatsLogClient()
     time_start = time()
     result = func(*args, **kwargs)
     time_end = time()
     elapsed = get_elapsed_milliseconds(time_end, time_start)
     call_count_name = MonitoringProvider.get_monitor_id(Settings.SERVICE_NAME, func.__name__)
     elapsed_name = MonitoringProvider.get_monitor_id(Settings.SERVICE_NAME, func.__name__, True)
     if monitor_name:
         call_count_name = monitor_name + Constants.MONITOR_CALLS_SUFFIX
         elapsed_name = monitor_name + Constants.MONITOR_ELAPSED_SUFFIX
     # Increment the stats for function call counter
     stats.update_increment(call_count_name, Constants.MONITOR_INCR_DEFAULT)
     # Add the timing for the function call time
     stats.add_timing(elapsed_name, elapsed)
     return result