def test_maybe_make_stats_request_does_not_error(self): service = prometheus.PrometheusService() deferToDatabase = self.patch(prometheus, "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_call = self.patch(prometheus, "push_stats_to_prometheus") with transaction.atomic(): Config.objects.set_config('enable_analytics', False) service = prometheus.PrometheusService() maybe_push_prometheus_stats = asynchronous( service.maybe_push_prometheus_stats) maybe_push_prometheus_stats().wait(5) self.assertThat(mock_call, MockNotCalled())
def test_maybe_make_stats_request_makes_request(self): mock_call = self.patch(prometheus, "push_stats_to_prometheus") setting = self.patch(prometheus, "PROMETHEUS") setting.return_value = True with transaction.atomic(): Config.objects.set_config('prometheus_enabled', True) Config.objects.set_config('prometheus_push_gateway', '192.168.1.1:8081') service = prometheus.PrometheusService() maybe_push_prometheus_stats = asynchronous( service.maybe_push_prometheus_stats) maybe_push_prometheus_stats().wait(5) self.assertThat(mock_call, MockCalledOnce())
def make_PrometheusService(): from maasserver import prometheus return prometheus.PrometheusService()
def test__calls__maybe_make_stats_request(self): service = prometheus.PrometheusService() self.assertEqual((service.maybe_push_prometheus_stats, (), {}), service.call)
def test__runs_once_an_hour_by_default(self): service = prometheus.PrometheusService() self.assertEqual(3600, service.step)
def test__is_a_TimerService(self): service = prometheus.PrometheusService() self.assertIsInstance(service, TimerService)