Skip to content

Commit 745ccca

Browse files
authored
Merge pull request #23 from faucetsdn/v0.24.1
Upgrade python3-prometheus-client to v0.24.1
2 parents 5382ee1 + 81fb12b commit 745ccca

26 files changed

Lines changed: 836 additions & 86 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:

.github/workflows/test-debian.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
name: "Build debian package"
1111
runs-on: ubuntu-latest
1212
container:
13-
image: "debian:latest"
13+
image: "debian:testing"
1414
steps:
1515
- name: Install dependencies
1616
run: |

debian/control

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Build-Depends: debhelper (>= 11),
88
Build-Depends-Indep: dh-python,
99
pybuild-plugin-pyproject,
1010
python3-all,
11+
python3-aiohttp,
12+
python3-asgiref,
1113
python3-decorator (>= 4.0.10),
1214
python3-pytest,
1315
python3-pytest-benchmark,

debian/patches/0002-Update-pyproject.toml.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Index: python3-prometheus-client/pyproject.toml
33
--- python3-prometheus-client.orig/pyproject.toml
44
+++ python3-prometheus-client/pyproject.toml
55
@@ -7,11 +7,7 @@ name = "prometheus_client"
6-
version = "0.23.1"
6+
version = "0.24.1"
77
description = "Python client for the Prometheus monitoring system."
88
readme = "README.md"
99
-license = "Apache-2.0 AND BSD-2-Clause"
@@ -15,7 +15,7 @@ Index: python3-prometheus-client/pyproject.toml
1515
requires-python = ">=3.9"
1616
authors = [
1717
{ name = "The Prometheus Authors", email = "prometheus-developers@googlegroups.com" },
18-
@@ -50,3 +46,17 @@ Documentation = "https://prometheus.gith
18+
@@ -57,3 +53,17 @@ Documentation = "https://prometheus.gith
1919

2020
[tool.setuptools.package-data]
2121
prometheus_client = ['py.typed']
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

0 commit comments

Comments
 (0)