Skip to content

Commit cede2e5

Browse files
committed
Upgrade python3-prometheus-client to v0.24.1
1 parent 6a665c3 commit cede2e5

24 files changed

Lines changed: 866 additions & 83 deletions

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ workflows:
8080
- "3.11"
8181
- "3.12"
8282
- "3.13"
83+
- "3.14"
8384
- test_nooptionals:
8485
matrix:
8586
parameters:
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Index: python3-prometheus-client/pyproject.toml
2+
===================================================================
3+
--- python3-prometheus-client.orig/pyproject.toml
4+
+++ python3-prometheus-client/pyproject.toml
5+
@@ -7,11 +7,7 @@ name = "prometheus_client"
6+
version = "0.22.1"
7+
description = "Python client for the Prometheus monitoring system."
8+
readme = "README.md"
9+
-license = "Apache-2.0 AND BSD-2-Clause"
10+
-license-files = [
11+
- "LICENSE",
12+
- "NOTICE",
13+
-]
14+
+license = { file = "LICENSE" }
15+
requires-python = ">=3.9"
16+
authors = [
17+
{ name = "The Prometheus Authors", email = "prometheus-developers@googlegroups.com" },
18+
@@ -50,3 +46,17 @@ Documentation = "https://prometheus.gith
19+
20+
[tool.setuptools.package-data]
21+
prometheus_client = ['py.typed']
22+
+
23+
+[tool.setuptools.data-files]
24+
+"tests" = [
25+
+ "tests/certs/*",
26+
+ "tests/proc/stat",
27+
+ "tests/proc/584/*",
28+
+ "tests/proc/26231/limits",
29+
+ "tests/proc/26231/stat",
30+
+ "tests/proc/26231/fd/*",
31+
+]
32+
+
33+
+[tool.setuptools.packages.find]
34+
+where = ["."]
35+
+exclude = ["debian"]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: AIOHTTP
3+
weight: 6
4+
---
5+
6+
To use Prometheus with a [AIOHTTP server](https://docs.aiohttp.org/en/stable/web.html),
7+
there is `make_aiohttp_handler` which creates a handler.
8+
9+
```python
10+
from aiohttp import web
11+
from prometheus_client.aiohttp import make_aiohttp_handler
12+
13+
app = web.Application()
14+
app.router.add_get("/metrics", make_aiohttp_handler())
15+
```
16+
17+
By default, this handler will instruct AIOHTTP to automatically compress the
18+
response if requested by the client. This behaviour can be disabled by passing
19+
`disable_compression=True` when creating the app, like this:
20+
21+
```python
22+
app.router.add_get("/metrics", make_aiohttp_handler(disable_compression=True))
23+
```
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: Django
3+
weight: 5
4+
---
5+
6+
To use Prometheus with [Django](https://www.djangoproject.com/) you can use the provided view class
7+
to add a metrics endpoint to your app.
8+
9+
```python
10+
# urls.py
11+
12+
from django.urls import path
13+
from prometheus_client.django import PrometheusDjangoView
14+
15+
urlpatterns = [
16+
# ... any other urls that you want
17+
path("metrics/", PrometheusDjangoView.as_view(), name="prometheus-metrics"),
18+
# ... still more urls
19+
]
20+
```
21+
22+
By default, Multiprocessing support is activated if environment variable `PROMETHEUS_MULTIPROC_DIR` is set.
23+
You can override this through the view arguments:
24+
25+
```python
26+
from django.conf import settings
27+
28+
urlpatterns = [
29+
path(
30+
"metrics/",
31+
PrometheusDjangoView.as_view(
32+
multiprocess_mode=settings.YOUR_SETTING # or any boolean value
33+
),
34+
name="prometheus-metrics",
35+
),
36+
]
37+
```
38+
39+
Full multiprocessing instructions are provided [here]({{< ref "/multiprocess" >}}).
40+
41+
# django-prometheus
42+
43+
The included `PrometheusDjangoView` is useful if you want to define your own metrics from scratch.
44+
45+
An external package called [django-prometheus](https://github.com/django-commons/django-prometheus/)
46+
can be used instead if you want to get a bunch of ready-made monitoring metrics for your Django application
47+
and easily benefit from utilities such as models monitoring.

docs/content/exporting/pushgateway.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ g.set_to_current_time()
5454
push_to_gateway('localhost:9091', job='batchA', registry=registry, handler=my_auth_handler)
5555
```
5656

57+
# Compressing data before sending to pushgateway
58+
Pushgateway (version >= 1.5.0) supports gzip and snappy compression (v > 1.6.0). This can help in network constrained environments.
59+
To compress a push request, set the `compression` argument to `'gzip'` or `'snappy'`:
60+
```python
61+
push_to_gateway(
62+
'localhost:9091',
63+
job='batchA',
64+
registry=registry,
65+
handler=my_auth_handler,
66+
compression='gzip',
67+
)
68+
```
69+
Snappy compression requires the optional [`python-snappy`](https://github.com/andrix/python-snappy) package.
70+
5771
TLS Auth is also supported when using the push gateway with a special handler.
5872

5973
```python

mypy.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[mypy]
2-
exclude = prometheus_client/decorator.py|prometheus_client/twisted|tests/test_twisted.py
2+
exclude = prometheus_client/decorator.py|prometheus_client/twisted|tests/test_twisted.py|prometheus_client/django|tests/test_django.py
33
implicit_reexport = False
44
disallow_incomplete_defs = True
55

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from .exposition import make_aiohttp_handler
2+
3+
__all__ = [
4+
"make_aiohttp_handler",
5+
]
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from __future__ import annotations
2+
3+
from aiohttp import hdrs, web
4+
from aiohttp.typedefs import Handler
5+
6+
from ..exposition import _bake_output
7+
from ..registry import Collector, REGISTRY
8+
9+
10+
def make_aiohttp_handler(
11+
registry: Collector = REGISTRY,
12+
disable_compression: bool = False,
13+
) -> Handler:
14+
"""Create a aiohttp handler which serves the metrics from a registry."""
15+
16+
async def prometheus_handler(request: web.Request) -> web.Response:
17+
# Prepare parameters
18+
params = {key: request.query.getall(key) for key in request.query.keys()}
19+
accept_header = ",".join(request.headers.getall(hdrs.ACCEPT, []))
20+
accept_encoding_header = ""
21+
# Bake output
22+
status, headers, output = _bake_output(
23+
registry,
24+
accept_header,
25+
accept_encoding_header,
26+
params,
27+
# use AIOHTTP's compression
28+
disable_compression=True,
29+
)
30+
response = web.Response(
31+
status=int(status.split(" ")[0]),
32+
headers=headers,
33+
body=output,
34+
)
35+
if not disable_compression:
36+
response.enable_compression()
37+
return response
38+
39+
return prometheus_handler

prometheus_client/asgi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
from urllib.parse import parse_qs
33

44
from .exposition import _bake_output
5-
from .registry import CollectorRegistry, REGISTRY
5+
from .registry import Collector, REGISTRY
66

77

8-
def make_asgi_app(registry: CollectorRegistry = REGISTRY, disable_compression: bool = False) -> Callable:
8+
def make_asgi_app(registry: Collector = REGISTRY, disable_compression: bool = False) -> Callable:
99
"""Create a ASGI app which serves the metrics from a registry."""
1010

1111
async def prometheus_app(scope, receive, send):

prometheus_client/bridge/graphite.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from timeit import default_timer
99
from typing import Callable, Tuple
1010

11-
from ..registry import CollectorRegistry, REGISTRY
11+
from ..registry import Collector, REGISTRY
1212

1313
# Roughly, have to keep to what works as a file name.
1414
# We also remove periods, so labels can be distinguished.
@@ -48,7 +48,7 @@ def run(self):
4848
class GraphiteBridge:
4949
def __init__(self,
5050
address: Tuple[str, int],
51-
registry: CollectorRegistry = REGISTRY,
51+
registry: Collector = REGISTRY,
5252
timeout_seconds: float = 30,
5353
_timer: Callable[[], float] = time.time,
5454
tags: bool = False,

0 commit comments

Comments
 (0)