Exemplo n.º 1
0
 def test_doesnt_call_metrics_gauge_if_gauge_metrics_is_empty(self):
     """Test that report_metrics doesn't call metrics_gauge if counter metrics are empty"""
     self.some_metrics_cache.fetch_all_and_clear.return_value = {
         'time': mock.MagicMock(),
         'count': mock.MagicMock(),
         'gauge': []
     }
     report_metrics(self.some_metrics_cache, self.some_api_sdk)
     self.some_api_sdk.metrics_gauge.assert_not_called()
Exemplo n.º 2
0
def run(arguments):
    try:
        config = parse_config_file(arguments['<config_file>'])
        redis = get_redis(config)
        metrics_cache = RedisMetricsCache(redis)
        sdk_api = api_factory(config)
        report_metrics(metrics_cache, sdk_api)
    except:
        logger.exception('Exception caught posting metrics')
Exemplo n.º 3
0
 def test_calls_metrics_gauge(self):
     """Test that report_metrics calls metrics_gauge if gauge metrics are not empty"""
     self.some_metrics_cache.fetch_all_and_clear.return_value = {
         'time': mock.MagicMock(),
         'count': mock.MagicMock(),
         'gauge': [mock.MagicMock()]
     }
     report_metrics(self.some_metrics_cache, self.some_api_sdk)
     self.some_api_sdk.metrics_gauge.assert_called_once_with(
         self.some_metrics_cache.fetch_all_and_clear.return_value['gauge'])
Exemplo n.º 4
0
def _report_metrics(seconds, config):
    try:
        while True:
            redis = get_redis(config)
            metrics_cache = RedisMetricsCache(redis)
            sdk_api = api_factory(config)
            report_metrics(metrics_cache, sdk_api)

            time.sleep(seconds)
    except:
        logger.exception('Exception caught posting metrics')
Exemplo n.º 5
0
def uwsgi_report_metrics(user_config):
    try:
        config = _get_config(user_config)
        seconds = config['metricsRefreshRate']
        while True:
            metrics_cache = UWSGIMetricsCache(get_uwsgi())
            sdk_api = api_factory(config)
            report_metrics(metrics_cache, sdk_api)

            time.sleep(seconds)
    except:
        _logger.exception('Exception caught posting metrics')
Exemplo n.º 6
0
    def test_calls_metrics_times(self):
        """Test that report_metrics calls metrics_times if time metrics are not empty"""
        self.some_metrics_cache.fetch_all_and_clear.return_value = {
            'count': mock.MagicMock(),
            'gauge': mock.MagicMock()
        }

        self.some_metrics_cache.fetch_all_times_and_clear.return_value = [
            mock.MagicMock()
        ]

        report_metrics(self.some_metrics_cache, self.some_api_sdk)
        self.some_api_sdk.metrics_times.assert_called_once_with(
            self.some_metrics_cache.fetch_all_times_and_clear.return_value)
Exemplo n.º 7
0
 def test_doesnt_call_metrics_counters_if_disabled(self):
     """Test that report_metrics doesn't call metrics_counters if the cache is disabled"""
     self.some_metrics_cache.is_enabled.return_value = False
     report_metrics(self.some_metrics_cache, self.some_api_sdk)
     self.some_api_sdk.metrics_counters.assert_not_called()
Exemplo n.º 8
0
 def test_doenst_call_fetch_all_and_clear_if_disabled(self):
     """Test that report_metrics doesn't call fetch_all_and_clear if the cache is disabled"""
     self.some_metrics_cache.is_enabled.return_value = False
     report_metrics(self.some_metrics_cache, self.some_api_sdk)
     self.some_metrics_cache.fetch_all_and_clear.assert_not_called()
Exemplo n.º 9
0
 def test_disables_cache_if_exception_is_raised(self):
     """Test that report_metrics disables cache if exception is raised"""
     self.some_metrics_cache.fetch_all_and_clear.side_effect = Exception()
     report_metrics(self.some_metrics_cache, self.some_api_sdk)
     self.some_metrics_cache.disable.assert_called_once_with()