django-prometheus 2.4.0.dev27__tar.gz → 2.5.0.dev3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {django_prometheus-2.4.0.dev27/django_prometheus.egg-info → django_prometheus-2.5.0.dev3}/PKG-INFO +1 -1
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/__init__.py +1 -1
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/cache/backends/memcached.py +0 -4
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/cache/backends/redis.py +4 -6
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/db/backends/mysql/base.py +0 -2
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/db/backends/spatialite/base.py +0 -2
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/db/backends/sqlite3/base.py +0 -2
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/db/common.py +0 -1
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/exports.py +1 -1
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/migrations.py +0 -1
- django_prometheus-2.5.0.dev3/django_prometheus/tests/test_django_prometheus.py +11 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/tests/test_testutils.py +30 -15
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/testutils.py +1 -1
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/utils.py +2 -2
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3/django_prometheus.egg-info}/PKG-INFO +1 -1
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/pyproject.toml +0 -7
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/setup.py +1 -1
- django_prometheus-2.4.0.dev27/django_prometheus/tests/test_django_prometheus.py +0 -11
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/LICENSE +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/MANIFEST.in +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/README.md +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/apps.py +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/cache/__init__.py +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/cache/backends/__init__.py +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/cache/backends/django_memcached_consul.py +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/cache/backends/filebased.py +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/cache/backends/locmem.py +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/cache/metrics.py +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/conf/__init__.py +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/db/__init__.py +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/db/backends/__init__.py +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/db/backends/mysql/__init__.py +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/db/backends/postgis/__init__.py +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/db/backends/postgis/base.py +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/db/backends/postgresql/__init__.py +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/db/backends/postgresql/base.py +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/db/backends/spatialite/__init__.py +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/db/backends/sqlite3/__init__.py +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/db/metrics.py +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/middleware.py +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/models.py +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/tests/__init__.py +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/tests/test_exports.py +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/urls.py +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus.egg-info/SOURCES.txt +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus.egg-info/dependency_links.txt +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus.egg-info/requires.txt +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus.egg-info/top_level.txt +0 -0
- {django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/setup.cfg +0 -0
|
@@ -22,10 +22,6 @@ class MemcachedPrometheusCacheMixin:
|
|
|
22
22
|
class PyLibMCCache(MemcachedPrometheusCacheMixin, memcached.PyLibMCCache):
|
|
23
23
|
"""Inherit memcached to add metrics about hit/miss ratio"""
|
|
24
24
|
|
|
25
|
-
pass
|
|
26
|
-
|
|
27
25
|
|
|
28
26
|
class PyMemcacheCache(MemcachedPrometheusCacheMixin, memcached.PyMemcacheCache):
|
|
29
27
|
"""Inherit memcached to add metrics about hit/miss ratio"""
|
|
30
|
-
|
|
31
|
-
pass
|
|
@@ -28,9 +28,8 @@ class RedisCache(cache.RedisCache):
|
|
|
28
28
|
if cached is not None:
|
|
29
29
|
django_cache_hits_total.labels(backend="redis").inc()
|
|
30
30
|
return cached
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return default
|
|
31
|
+
django_cache_misses_total.labels(backend="redis").inc()
|
|
32
|
+
return default
|
|
34
33
|
|
|
35
34
|
|
|
36
35
|
class NativeRedisCache(DjangoRedisCache):
|
|
@@ -44,6 +43,5 @@ class NativeRedisCache(DjangoRedisCache):
|
|
|
44
43
|
if result is not None:
|
|
45
44
|
django_cache_hits_total.labels(backend="native_redis").inc()
|
|
46
45
|
return result
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return default
|
|
46
|
+
django_cache_misses_total.labels(backend="native_redis").inc()
|
|
47
|
+
return default
|
|
@@ -6,8 +6,6 @@ from django_prometheus.db.common import DatabaseWrapperMixin, ExportingCursorWra
|
|
|
6
6
|
class DatabaseFeatures(base.DatabaseFeatures):
|
|
7
7
|
"""Our database has the exact same features as the base one."""
|
|
8
8
|
|
|
9
|
-
pass
|
|
10
|
-
|
|
11
9
|
|
|
12
10
|
class DatabaseWrapper(DatabaseWrapperMixin, base.DatabaseWrapper):
|
|
13
11
|
CURSOR_CLASS = base.CursorWrapper
|
|
@@ -7,8 +7,6 @@ from django_prometheus.db.common import DatabaseWrapperMixin
|
|
|
7
7
|
class DatabaseFeatures(features.DatabaseFeatures):
|
|
8
8
|
"""Our database has the exact same features as the base one."""
|
|
9
9
|
|
|
10
|
-
pass
|
|
11
|
-
|
|
12
10
|
|
|
13
11
|
class DatabaseWrapper(DatabaseWrapperMixin, base.DatabaseWrapper):
|
|
14
12
|
CURSOR_CLASS = sqlite_base.SQLiteCursorWrapper
|
|
@@ -6,8 +6,6 @@ from django_prometheus.db.common import DatabaseWrapperMixin
|
|
|
6
6
|
class DatabaseFeatures(base.DatabaseFeatures):
|
|
7
7
|
"""Our database has the exact same features as the base one."""
|
|
8
8
|
|
|
9
|
-
pass
|
|
10
|
-
|
|
11
9
|
|
|
12
10
|
class DatabaseWrapper(DatabaseWrapperMixin, base.DatabaseWrapper):
|
|
13
11
|
CURSOR_CLASS = base.SQLiteCursorWrapper
|
|
@@ -91,7 +91,7 @@ def SetupPrometheusEndpointOnPortRange(port_range, addr=""):
|
|
|
91
91
|
thread = PrometheusEndpointServer(httpd)
|
|
92
92
|
thread.daemon = True
|
|
93
93
|
thread.start()
|
|
94
|
-
logger.info("Exporting Prometheus /metrics/ on port
|
|
94
|
+
logger.info(f"Exporting Prometheus /metrics/ on port {port}")
|
|
95
95
|
return port # Stop trying ports at this point
|
|
96
96
|
logger.warning("Cannot export Prometheus /metrics/ - no available ports in supplied range")
|
|
97
97
|
return None
|
{django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/migrations.py
RENAMED
|
@@ -31,7 +31,6 @@ def ExportMigrations():
|
|
|
31
31
|
This is meant to be called during app startup, ideally by
|
|
32
32
|
django_prometheus.apps.AppConfig.
|
|
33
33
|
"""
|
|
34
|
-
|
|
35
34
|
# Import MigrationExecutor lazily. MigrationExecutor checks at
|
|
36
35
|
# import time that the apps are ready, and they are not when
|
|
37
36
|
# django_prometheus is imported. ExportMigrations() should be
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
from django_prometheus.utils import PowersOf
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class TestDjangoPrometheus:
|
|
6
|
+
def testPowersOf(self):
|
|
7
|
+
"""Tests utils.PowersOf."""
|
|
8
|
+
assert PowersOf(2, 4) == [0, 1, 2, 4, 8]
|
|
9
|
+
assert PowersOf(3, 5, lower=1) == [0, 3, 9, 27, 81, 243]
|
|
10
|
+
assert PowersOf(2, 4, include_zero=False) == [1, 2, 4, 8]
|
|
11
|
+
assert PowersOf(2, 6, lower=2, include_zero=False) == [4, 8, 16, 32, 64, 128]
|
|
@@ -17,7 +17,7 @@ from django_prometheus.testutils import (
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
class TestPrometheusTestCaseMixin:
|
|
20
|
-
@pytest.fixture
|
|
20
|
+
@pytest.fixture
|
|
21
21
|
def registry(self):
|
|
22
22
|
return prometheus_client.CollectorRegistry()
|
|
23
23
|
|
|
@@ -43,20 +43,23 @@ class TestPrometheusTestCaseMixin:
|
|
|
43
43
|
|
|
44
44
|
def test_get_metric(self, registry):
|
|
45
45
|
"""Tests get_metric."""
|
|
46
|
-
assert
|
|
47
|
-
assert
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
assert get_metric("some_gauge", registry=registry) == 42
|
|
47
|
+
assert (
|
|
48
|
+
get_metric(
|
|
49
|
+
"some_labelled_gauge",
|
|
50
|
+
registry=registry,
|
|
51
|
+
labelred="pink",
|
|
52
|
+
labelblue="indigo",
|
|
53
|
+
)
|
|
54
|
+
== 1
|
|
52
55
|
)
|
|
53
56
|
|
|
54
57
|
def test_get_metrics_vector(self, registry):
|
|
55
58
|
"""Tests get_metrics_vector."""
|
|
56
59
|
vector = get_metrics_vector("some_nonexistent_gauge", registry=registry)
|
|
57
|
-
assert
|
|
60
|
+
assert vector == []
|
|
58
61
|
vector = get_metrics_vector("some_gauge", registry=registry)
|
|
59
|
-
assert [({}, 42)]
|
|
62
|
+
assert vector == [({}, 42)]
|
|
60
63
|
vector = get_metrics_vector("some_labelled_gauge", registry=registry)
|
|
61
64
|
assert sorted(
|
|
62
65
|
[
|
|
@@ -99,18 +102,30 @@ class TestPrometheusTestCaseMixin:
|
|
|
99
102
|
"""Tests save_registry and frozen registries operations."""
|
|
100
103
|
frozen_registry = save_registry(registry=registry)
|
|
101
104
|
# Test that we can manipulate a frozen scalar metric.
|
|
102
|
-
assert
|
|
105
|
+
assert get_metric_from_frozen_registry("some_gauge", frozen_registry) == 42
|
|
103
106
|
some_gauge.set(99)
|
|
104
|
-
assert
|
|
107
|
+
assert get_metric_from_frozen_registry("some_gauge", frozen_registry) == 42
|
|
105
108
|
assert_metric_diff(frozen_registry, 99 - 42, "some_gauge", registry=registry)
|
|
106
109
|
assert_metric_no_diff(frozen_registry, 1, "some_gauge", registry=registry)
|
|
107
110
|
# Now test the same thing with a labelled metric.
|
|
108
|
-
assert
|
|
109
|
-
|
|
111
|
+
assert (
|
|
112
|
+
get_metric_from_frozen_registry(
|
|
113
|
+
"some_labelled_gauge",
|
|
114
|
+
frozen_registry,
|
|
115
|
+
labelred="pink",
|
|
116
|
+
labelblue="indigo",
|
|
117
|
+
)
|
|
118
|
+
== 1
|
|
110
119
|
)
|
|
111
120
|
some_labelled_gauge.labels("pink", "indigo").set(5)
|
|
112
|
-
assert
|
|
113
|
-
|
|
121
|
+
assert (
|
|
122
|
+
get_metric_from_frozen_registry(
|
|
123
|
+
"some_labelled_gauge",
|
|
124
|
+
frozen_registry,
|
|
125
|
+
labelred="pink",
|
|
126
|
+
labelblue="indigo",
|
|
127
|
+
)
|
|
128
|
+
== 1
|
|
114
129
|
)
|
|
115
130
|
assert_metric_diff(
|
|
116
131
|
frozen_registry,
|
{django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/testutils.py
RENAMED
|
@@ -189,7 +189,7 @@ def format_labels(labels):
|
|
|
189
189
|
Out:
|
|
190
190
|
'{method="GET",port="80"}'
|
|
191
191
|
"""
|
|
192
|
-
return "{
|
|
192
|
+
return "{{{}}}".format(",".join([f'{k}="{v}"' for k, v in labels.items()]))
|
|
193
193
|
|
|
194
194
|
|
|
195
195
|
def format_vector(vector):
|
|
@@ -17,6 +17,7 @@ def TimeSince(t):
|
|
|
17
17
|
|
|
18
18
|
Returns:
|
|
19
19
|
the time since t, in fractional seconds.
|
|
20
|
+
|
|
20
21
|
"""
|
|
21
22
|
return default_timer() - t
|
|
22
23
|
|
|
@@ -25,5 +26,4 @@ def PowersOf(logbase, count, lower=0, include_zero=True):
|
|
|
25
26
|
"""Returns a list of count powers of logbase (from logbase**lower)."""
|
|
26
27
|
if not include_zero:
|
|
27
28
|
return [logbase**i for i in range(lower, count + lower)]
|
|
28
|
-
|
|
29
|
-
return [0] + [logbase**i for i in range(lower, count + lower)]
|
|
29
|
+
return [0] + [logbase**i for i in range(lower, count + lower)]
|
|
@@ -4,10 +4,3 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[tool.pytest.ini_options]
|
|
6
6
|
addopts = " --ignore django_prometheus/tests/end2end"
|
|
7
|
-
|
|
8
|
-
[tool.ruff]
|
|
9
|
-
line-length = 120
|
|
10
|
-
target-version = "py39"
|
|
11
|
-
|
|
12
|
-
[tool.ruff.lint]
|
|
13
|
-
select = ["B", "C4", "E", "F", "I", "T10", "YTT", "W"]
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
from django_prometheus.utils import PowersOf
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class TestDjangoPrometheus:
|
|
6
|
-
def testPowersOf(self):
|
|
7
|
-
"""Tests utils.PowersOf."""
|
|
8
|
-
assert [0, 1, 2, 4, 8] == PowersOf(2, 4)
|
|
9
|
-
assert [0, 3, 9, 27, 81, 243] == PowersOf(3, 5, lower=1)
|
|
10
|
-
assert [1, 2, 4, 8] == PowersOf(2, 4, include_zero=False)
|
|
11
|
-
assert [4, 8, 16, 32, 64, 128] == PowersOf(2, 6, lower=2, include_zero=False)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/cache/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/cache/metrics.py
RENAMED
|
File without changes
|
{django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/conf/__init__.py
RENAMED
|
File without changes
|
{django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/db/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/db/metrics.py
RENAMED
|
File without changes
|
{django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/middleware.py
RENAMED
|
File without changes
|
|
File without changes
|
{django_prometheus-2.4.0.dev27 → django_prometheus-2.5.0.dev3}/django_prometheus/tests/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|