diff --git a/django_prometheus/db/common.py b/django_prometheus/db/common.py index 538810c0..7f87dfca 100644 --- a/django_prometheus/db/common.py +++ b/django_prometheus/db/common.py @@ -63,16 +63,18 @@ class CursorWrapper(cursor_class): def execute(self, *args, **kwargs): execute_total.labels(alias, vendor).inc() - with query_duration_seconds.labels(**labels).time(), ExceptionCounterByType( - errors_total, extra_labels=labels + with ( + query_duration_seconds.labels(**labels).time(), + ExceptionCounterByType(errors_total, extra_labels=labels), ): return super().execute(*args, **kwargs) def executemany(self, query, param_list, *args, **kwargs): execute_total.labels(alias, vendor).inc(len(param_list)) execute_many_total.labels(alias, vendor).inc(len(param_list)) - with query_duration_seconds.labels(**labels).time(), ExceptionCounterByType( - errors_total, extra_labels=labels + with ( + query_duration_seconds.labels(**labels).time(), + ExceptionCounterByType(errors_total, extra_labels=labels), ): return super().executemany(query, param_list, *args, **kwargs) diff --git a/django_prometheus/tests/end2end/testapp/test_caches.py b/django_prometheus/tests/end2end/testapp/test_caches.py index ed34989f..7c6a94e7 100644 --- a/django_prometheus/tests/end2end/testapp/test_caches.py +++ b/django_prometheus/tests/end2end/testapp/test_caches.py @@ -6,6 +6,7 @@ _SUPPORTED_CACHES = ["memcached.PyLibMCCache", "memcached.PyMemcacheCache", "filebased", "locmem", "native_redis"] + class TestCachesMetrics: """Test django_prometheus.caches metrics.""" @@ -33,7 +34,7 @@ def test_counters(self, supported_cache): def test_redis_cache_fail(self): # Note: test use fake service config (like if server was stopped) - supported_cache = "native_redis" + supported_cache = "redis" total_before = get_metric("django_cache_get_total", backend=supported_cache) or 0 fail_before = get_metric("django_cache_get_fail_total", backend=supported_cache) or 0 hit_before = get_metric("django_cache_get_hits_total", backend=supported_cache) or 0