Esempio n. 1
0
    def _setup(self):
        from kaneda import Metrics
        from kaneda.utils import import_class, get_object_from_settings
        from kaneda.exceptions import UnexistingKanedaClass, SettingsError
        from . import settings

        if settings.DEBUG:
            backend_class = import_class('kaneda.backends.LoggerBackend')
            if settings.LOGGER:
                backend = backend_class(logger=logging.getLogger(settings.LOGGER))
            elif settings.LOGGER_FILENAME:
                backend = backend_class(filename=settings.LOGGER_FILENAME)
            else:
                backend = backend_class()
            _metrics = Metrics(backend=backend)
        else:
            if not settings.BACKEND and not settings.QUEUE:
                raise SettingsError('You need to set KANEDA_BACKEND or KANEDA_QUEUE on settings.py to django_kaneda')
            if settings.BACKEND:
                try:
                    backend = get_object_from_settings(settings.BACKEND, settings)
                    _metrics = Metrics(backend=backend)
                except UnexistingKanedaClass:
                    raise UnexistingKanedaClass('The selected KANEDA_BACKEND class does not exists.')
            if settings.QUEUE:
                try:
                    queue = get_object_from_settings(settings.QUEUE, settings)
                    _metrics = Metrics(queue=queue)
                except UnexistingKanedaClass:
                    raise UnexistingKanedaClass('The selected KANEDA_QUEUE class does not exists.')
        self._wrapped = _metrics
Esempio n. 2
0
 def test_logger_metric(self, logger_backend, logger_filename):
     metrics = Metrics(backend=logger_backend)
     metrics.gauge('test_gauge', 42)
     with open(logger_filename) as f:
         lines = f.readlines()
         assert lines
         result = lines[-1].split(' - ')[2]
         assert result
         assert 'test_gauge' in result
Esempio n. 3
0
 def test_logger_metric(self, logger_backend, logger_filename):
     metrics = Metrics(backend=logger_backend)
     metrics.gauge('test_gauge', 42)
     with open(logger_filename) as f:
         lines = f.readlines()
         assert lines
         result = lines[-1].split(' - ')[2]
         assert result
         assert 'test_gauge' in result
Esempio n. 4
0
 def test_influx_metric(self, influx_backend):
     metrics = Metrics(backend=influx_backend)
     result = metrics.gauge('test_gauge', 42)
     assert result
Esempio n. 5
0
 def test_rethink_metric(self, rethink_backend):
     metrics = Metrics(backend=rethink_backend)
     result = metrics.gauge('test_gauge', 42)
     assert result
     assert result['inserted'] == 1
Esempio n. 6
0
 def test_mongo_metric(self, mongo_backend):
     metrics = Metrics(backend=mongo_backend)
     result = metrics.gauge('test_gauge', 42)
     assert result
     assert result.inserted_id
Esempio n. 7
0
 def test_mongo_metric(self, mongo_backend):
     metrics = Metrics(backend=mongo_backend)
     result = metrics.gauge('test_gauge', 42)
     assert result
     assert result.inserted_id
Esempio n. 8
0
 def test_celery(self, celery_queue):
     metrics = Metrics(queue=celery_queue)
     result = metrics.gauge('test_gauge_celery', 1)
     assert result
Esempio n. 9
0
 def test_celery(self, celery_queue):
     metrics = Metrics(queue=celery_queue)
     result = metrics.gauge('test_gauge_celery', 1)
     assert result
Esempio n. 10
0
 def test_rq(self, rq_queue):
     metrics = Metrics(queue=rq_queue)
     result = metrics.gauge('test_gauge_rq', 1)
     assert result
Esempio n. 11
0
 def test_benchmark_elasticsearch(self, elasticsearch_backend, benchmark):
     metrics = Metrics(backend=elasticsearch_backend)
     benchmark(metrics.gauge, 'benchmark_elasticsearch', 1)
Esempio n. 12
0
 def test_benchmark_rethink(self, rethink_backend, benchmark):
     metrics = Metrics(backend=rethink_backend)
     benchmark(metrics.gauge, 'benchmark_mongo', 1)
Esempio n. 13
0
 def test_benchmark_mongo(self, mongo_backend, benchmark):
     metrics = Metrics(backend=mongo_backend)
     benchmark(metrics.gauge, 'benchmark_mongo', 1)
Esempio n. 14
0
 def test_elasticsearch_metric(self, elasticsearch_backend):
     metrics = Metrics(backend=elasticsearch_backend)
     result = metrics.gauge('test_gauge', 42)
     assert result
     assert result['_id']
Esempio n. 15
0
 def test_influx_metric(self, influx_backend):
     metrics = Metrics(backend=influx_backend)
     result = metrics.gauge('test_gauge', 42)
     assert result
Esempio n. 16
0
 def test_rethink_metric(self, rethink_backend):
     metrics = Metrics(backend=rethink_backend)
     result = metrics.gauge('test_gauge', 42)
     assert result
     assert result['inserted'] == 1
Esempio n. 17
0
 def test_elasticsearch_metric(self, elasticsearch_backend):
     metrics = Metrics(backend=elasticsearch_backend)
     result = metrics.gauge('test_gauge', 42)
     assert result
     assert result['_id']
Esempio n. 18
0
 def test_benchmark_rq(self, rq_queue, benchmark):
     metrics = Metrics(queue=rq_queue)
     benchmark(metrics.gauge, 'benchmark_rq', 1)
Esempio n. 19
0
 def test_zmq(self, zmq_queue):
     metrics = Metrics(queue=zmq_queue)
     metrics.gauge('test_gauge_rq', 1)
     zmq_queue.socket.close()
Esempio n. 20
0
 def test_benchmark_zmq(self, zmq_queue, benchmark):
     metrics = Metrics(queue=zmq_queue)
     benchmark(metrics.gauge, 'benchmark_zmq', 1)
Esempio n. 21
0
 def test_zmq(self, zmq_queue):
     metrics = Metrics(queue=zmq_queue)
     metrics.gauge('test_gauge_rq', 1)
     zmq_queue.socket.close()
Esempio n. 22
0
 def test_benchmark_celery(self, celery_queue, benchmark):
     metrics = Metrics(queue=celery_queue)
     benchmark(metrics.gauge, 'benchmark_celery', 1)
Esempio n. 23
0
 def test_rq(self, rq_queue):
     metrics = Metrics(queue=rq_queue)
     result = metrics.gauge('test_gauge_rq', 1)
     assert result
Esempio n. 24
0
 def metrics(self, dummy_backend):
     return Metrics(backend=dummy_backend)