Ejemplo n.º 1
0
 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))
Ejemplo n.º 2
0
    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())
Ejemplo n.º 3
0
    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())
Ejemplo n.º 4
0
 def test__calls__maybe_make_stats_request(self):
     service = stats.PrometheusService()
     self.assertEqual(
         (service.maybe_push_prometheus_stats, (), {}),
         service.call)
Ejemplo n.º 5
0
 def test__runs_once_an_hour_by_default(self):
     service = stats.PrometheusService()
     self.assertEqual(3600, service.step)
Ejemplo n.º 6
0
 def test__is_a_TimerService(self):
     service = stats.PrometheusService()
     self.assertIsInstance(service, TimerService)