Skip to content

Commit 6fd72b5

Browse files
paweldudzinskikorfuri
authored andcommitted
Fixed tests and added a new metric (#96)
* Would be good to have those additional data in response * Fix tests * Fix end2end tests * Bump version * Eliminate flake8 errors * More updates * extend buckets in django_http_requests_latency_seconds_by_view_method
1 parent 210639e commit 6fd72b5

31 files changed

+152
-79
lines changed

django_prometheus/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
33
https://github.com/korfuri/django-prometheus
44
"""
5-
65
# Import all files that define metrics. This has the effect that
76
# `import django_prometheus` will always instanciate all metric
87
# objects right away.
9-
import django_prometheus.middleware
10-
import django_prometheus.models
8+
from django_prometheus import middleware
9+
from django_prometheus import models
10+
11+
__all__ = ['middleware', 'models', 'pip_prometheus']
1112

1213
# Import pip_prometheus to export the pip metrics automatically.
1314
try:

django_prometheus/apps.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from django.apps import AppConfig
22
from django.conf import settings
3+
4+
import django_prometheus
35
from django_prometheus.exports import SetupPrometheusExportsFromConfig
46
from django_prometheus.migrations import ExportMigrations
5-
# unused import to force instantiating the metric objects at startup.
6-
import django_prometheus
77

88

99
class DjangoPrometheusConfig(AppConfig):
10-
name = 'django_prometheus'
10+
name = django_prometheus.__name__
1111
verbose_name = 'Django-Prometheus'
1212

1313
def ready(self):

django_prometheus/cache/backends/django_memcached_consul.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
from __future__ import absolute_import
2-
from django_memcached_consul import memcached
2+
33
from django_prometheus.cache.metrics import (
4-
django_cache_get_total, django_cache_hits_total, django_cache_misses_total)
4+
django_cache_get_total,
5+
django_cache_hits_total,
6+
django_cache_misses_total)
7+
8+
from django_memcached_consul import memcached
59

610

711
class MemcachedCache(memcached.MemcachedCache):

django_prometheus/cache/backends/locmem.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from django.core.cache.backends import locmem
2+
23
from django_prometheus.cache.metrics import (
3-
django_cache_get_total, django_cache_hits_total, django_cache_misses_total)
4+
django_cache_get_total,
5+
django_cache_hits_total,
6+
django_cache_misses_total)
47

58

69
class LocMemCache(locmem.LocMemCache):

django_prometheus/cache/backends/memcached.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from django.core.cache.backends import memcached
2+
23
from django_prometheus.cache.metrics import (
3-
django_cache_get_total, django_cache_hits_total, django_cache_misses_total)
4+
django_cache_get_total,
5+
django_cache_hits_total,
6+
django_cache_misses_total)
47

58

69
class MemcachedCache(memcached.MemcachedCache):

django_prometheus/cache/backends/redis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from django_redis import cache, exceptions
2-
31
from django_prometheus.cache.metrics import (
42
django_cache_get_fail_total,
53
django_cache_get_total,
64
django_cache_hits_total,
75
django_cache_misses_total,
86
)
97

8+
from django_redis import cache, exceptions
9+
1010

1111
class RedisCache(cache.RedisCache):
1212
"""Inherit redis to add metrics about hit/miss/interruption ratio"""

django_prometheus/db/__init__.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,15 @@
11
# Import all metrics
2-
from django_prometheus.db.metrics import *
2+
from django_prometheus.db.metrics import (
3+
Counter,
4+
connection_errors_total,
5+
connections_total,
6+
errors_total,
7+
execute_many_total,
8+
execute_total)
9+
__all__ = [
10+
'Counter',
11+
'connection_errors_total',
12+
'connections_total',
13+
'errors_total',
14+
'execute_many_total',
15+
'execute_total']

django_prometheus/db/backends/mysql/base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
from django_prometheus.db.common import (
2-
DatabaseWrapperMixin, ExportingCursorWrapper)
31
from django.db.backends.mysql import base
42

3+
from django_prometheus.db.common import (
4+
DatabaseWrapperMixin,
5+
ExportingCursorWrapper)
6+
57

68
class DatabaseFeatures(base.DatabaseFeatures):
79
"""Our database has the exact same features as the base one."""

django_prometheus/db/backends/postgresql/base.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import django
2-
import psycopg2.extensions
32

4-
from django_prometheus.db.common import DatabaseWrapperMixin, \
3+
from django_prometheus.db.common import (
4+
DatabaseWrapperMixin,
55
ExportingCursorWrapper
6+
)
7+
8+
import psycopg2.extensions
69

710
if django.VERSION >= (1, 9):
811
from django.db.backends.postgresql import base

django_prometheus/db/backends/sqlite3/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from django_prometheus.db.common import DatabaseWrapperMixin
21
from django.db.backends.sqlite3 import base
32

3+
from django_prometheus.db.common import DatabaseWrapperMixin
4+
45

56
class DatabaseFeatures(base.DatabaseFeatures):
67
"""Our database has the exact same features as the base one."""

0 commit comments

Comments
 (0)