Skip to content

Commit 5c3477d

Browse files
Merge branch 'prometheus:master' into restrict-multiprocess
2 parents b3f0d62 + 671f75c commit 5c3477d

20 files changed

Lines changed: 495 additions & 168 deletions

File tree

.circleci/config.yml

Lines changed: 0 additions & 93 deletions
This file was deleted.

.github/workflows/ci.yaml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
flake8_lint:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
16+
- name: Set up Python
17+
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
18+
with:
19+
python-version: '3.9'
20+
- name: Install tox
21+
run: pip install tox
22+
- name: Run flake8
23+
run: tox -e flake8
24+
25+
isort_lint:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
29+
- name: Set up Python
30+
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
31+
with:
32+
python-version: '3.9'
33+
- name: Install tox
34+
run: pip install tox
35+
- name: Run isort
36+
run: tox -e isort
37+
38+
mypy_lint:
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
42+
- name: Set up Python
43+
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
44+
with:
45+
python-version: '3.9'
46+
- name: Install tox
47+
run: pip install tox
48+
- name: Run mypy
49+
run: tox -e mypy
50+
51+
test:
52+
runs-on: ubuntu-latest
53+
strategy:
54+
matrix:
55+
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14']
56+
steps:
57+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
58+
- name: Set up Python ${{ matrix.python-version }}
59+
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
60+
with:
61+
python-version: ${{ matrix.python-version }}
62+
- name: Install dependencies
63+
run: |
64+
pip install --user tox "virtualenv<20.22.0"
65+
echo "$HOME/.local/bin" >> $GITHUB_PATH
66+
- name: Set tox environment
67+
id: toxenv
68+
run: |
69+
VERSION="${{ matrix.python-version }}"
70+
# Extract major.minor version (strip patch if present)
71+
TOX_VERSION=$(echo "$VERSION" | cut -d. -f1,2)
72+
echo "toxenv=py${TOX_VERSION}" >> $GITHUB_OUTPUT
73+
- name: Run tests
74+
run: tox
75+
env:
76+
TOXENV: ${{ steps.toxenv.outputs.toxenv }}
77+
78+
test_nooptionals:
79+
runs-on: ubuntu-latest
80+
env:
81+
PYTHON_VERSION: '3.9'
82+
steps:
83+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
84+
- name: Set up Python
85+
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
86+
with:
87+
python-version: ${{ env.PYTHON_VERSION }}
88+
- name: Install tox
89+
run: pip install tox
90+
- name: Run tests without optional dependencies
91+
run: tox
92+
env:
93+
TOXENV: py${{ env.PYTHON_VERSION }}-nooptionals
94+
95+
test_pypy:
96+
runs-on: ubuntu-latest
97+
env:
98+
PYTHON_VERSION: '3.9'
99+
steps:
100+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
101+
- name: Set up PyPy
102+
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
103+
with:
104+
python-version: pypy-${{ env.PYTHON_VERSION }}
105+
- name: Install tox
106+
run: pip install tox
107+
- name: Run tests with PyPy
108+
run: tox
109+
env:
110+
TOXENV: pypy${{ env.PYTHON_VERSION }}

.github/workflows/github-pages.yaml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ on:
1111
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
1212
permissions:
1313
contents: read
14-
pages: write
15-
id-token: write
16-
actions: read
1714

1815
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
1916
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
@@ -32,6 +29,9 @@ jobs:
3229
runs-on: ubuntu-latest
3330
env:
3431
HUGO_VERSION: 0.145.0
32+
permissions:
33+
pages: write
34+
id-token: write
3535
steps:
3636
- name: Install Hugo CLI
3737
run: |
@@ -40,13 +40,13 @@ jobs:
4040
#- name: Install Dart Sass
4141
# run: sudo snap install dart-sass
4242
- name: Checkout
43-
uses: actions/checkout@v4
43+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
4444
with:
4545
submodules: recursive
4646
fetch-depth: 0
4747
- name: Setup Pages
4848
id: pages
49-
uses: actions/configure-pages@v5
49+
uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b # v5.0.0
5050
- name: Install Node.js dependencies
5151
run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true"
5252
working-directory: ./docs
@@ -62,7 +62,7 @@ jobs:
6262
--baseURL "${{ steps.pages.outputs.base_url }}/"
6363
working-directory: ./docs
6464
- name: Upload artifact
65-
uses: actions/upload-pages-artifact@v3
65+
uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4.0.0
6666
with:
6767
path: ./docs/public
6868

@@ -73,7 +73,11 @@ jobs:
7373
url: ${{ steps.deployment.outputs.page_url }}
7474
runs-on: ubuntu-latest
7575
needs: build
76+
permissions:
77+
pages: write
78+
id-token: write
79+
actions: read
7680
steps:
7781
- name: Deploy to GitHub Pages
7882
id: deployment
79-
uses: actions/deploy-pages@v4
83+
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5

docs/content/exporting/http/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ to shutdown the server gracefully:
2424
```python
2525
server, t = start_http_server(8000)
2626
server.shutdown()
27+
server.server_close()
2728
t.join()
2829
```
2930

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

prometheus_client/aiohttp/exposition.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
from aiohttp.typedefs import Handler
55

66
from ..exposition import _bake_output
7-
from ..registry import CollectorRegistry, REGISTRY
7+
from ..registry import Collector, REGISTRY
88

99

1010
def make_aiohttp_handler(
11-
registry: CollectorRegistry = REGISTRY,
11+
registry: Collector = REGISTRY,
1212
disable_compression: bool = False,
1313
) -> Handler:
1414
"""Create a aiohttp handler which serves the metrics from a registry."""

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)