def test_maybe_make_stats_request_does_not_error(self): service = stats.PrometheusService() deferToDatabase = self.patch(stats, "deferToDatabase") exception_type = factory.make_exception_type() deferToDatabase.return_value = fail(exception_type()) d = service.maybe_push_prometheus_stats() self.assertIsNone(extract_result(d))
def test_maybe_make_stats_request_doesnt_make_request(self): mock_prom_cli = self.patch(stats, "prom_cli") with transaction.atomic(): Config.objects.set_config('enable_analytics', False) service = stats.PrometheusService() maybe_push_prometheus_stats = asynchronous( service.maybe_push_prometheus_stats) maybe_push_prometheus_stats().wait(5) self.assertThat( mock_prom_cli.push_stats_to_prometheus, MockNotCalled())
def test_maybe_make_stats_request_makes_request(self): mock_call = self.patch(stats, "push_stats_to_prometheus") self.patch(stats, "PROMETHEUS_SUPPORTED", True) with transaction.atomic(): Config.objects.set_config('prometheus_enabled', True) Config.objects.set_config( 'prometheus_push_gateway', '192.168.1.1:8081') service = stats.PrometheusService() maybe_push_prometheus_stats = asynchronous( service.maybe_push_prometheus_stats) maybe_push_prometheus_stats().wait(5) self.assertThat(mock_call, MockCalledOnce())
def test__calls__maybe_make_stats_request(self): service = stats.PrometheusService() self.assertEqual( (service.maybe_push_prometheus_stats, (), {}), service.call)
def test__runs_once_an_hour_by_default(self): service = stats.PrometheusService() self.assertEqual(3600, service.step)
def test__is_a_TimerService(self): service = stats.PrometheusService() self.assertIsInstance(service, TimerService)