Skip to content

Commit

Permalink
Merge pull request #83 from dolfinus/starlette-0.35
Browse files Browse the repository at this point in the history
Update starlette to 0.35+
  • Loading branch information
stephenhillier committed Jan 17, 2024
2 parents e1c1938 + f3dc941 commit eb2f19b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:

steps:
- uses: actions/checkout@v1
- name: Set up Python 3.7
- name: Set up Python 3.12
uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: 3.12
- name: Lint with flake8
run: |
python -m pip install --upgrade pip
Expand All @@ -32,10 +32,10 @@ jobs:

steps:
- uses: actions/checkout@v1
- name: Set up Python 3.7
- name: Set up Python 3.12
uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: 3.12
- name: Type checking with mypy
run: |
python -m pip install --upgrade pip
Expand All @@ -46,7 +46,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

runs-on: ubuntu-latest

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
prometheus-client==0.15.0
starlette==0.27.0
starlette==0.35.1
requests==2.31.0
aiofiles==22.1.0
pytest==6.2.4
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
description="Prometheus metrics exporter for Starlette applications.",
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
install_requires=["prometheus_client>=0.12", "starlette"],
install_requires=["prometheus_client>=0.12", "starlette>=0.35"],
python_requires=">=3.8",
)
19 changes: 6 additions & 13 deletions tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import pytest
from prometheus_client import REGISTRY
from starlette import __version__ as starlette_version
from starlette.applications import Starlette
from starlette.background import BackgroundTask
from starlette.exceptions import HTTPException
Expand Down Expand Up @@ -159,7 +158,7 @@ def test_404_filter(self, testapp):
pass
metrics = client.get("/metrics").content.decode()

assert "404" not in metrics
assert "/404" not in metrics

def test_unhandled(self, client):
"""test that an unhandled exception still gets logged in the requests counter"""
Expand Down Expand Up @@ -218,19 +217,19 @@ def test_custom_root_path(self, testapp):
metrics = client.get("/metrics").content.decode()

assert (
"""starlette_requests_total{app_name="starlette",method="GET",path="/api/200",status_code="200"} 1.0"""
"""starlette_requests_total{app_name="starlette",method="GET",path="/200",status_code="200"} 1.0"""
in metrics
)
assert (
"""starlette_requests_total{app_name="starlette",method="GET",path="/api/500",status_code="500"} 1.0"""
"""starlette_requests_total{app_name="starlette",method="GET",path="/500",status_code="500"} 1.0"""
in metrics
)
assert (
"""starlette_requests_total{app_name="starlette",method="GET",path="/api/404",status_code="404"} 1.0"""
"""starlette_requests_total{app_name="starlette",method="GET",path="/404",status_code="404"} 1.0"""
in metrics
)
assert (
"""starlette_requests_total{app_name="starlette",method="GET",path="/api/unhandled",status_code="500"} 1.0"""
"""starlette_requests_total{app_name="starlette",method="GET",path="/unhandled",status_code="500"} 1.0"""
in metrics
)

Expand Down Expand Up @@ -509,12 +508,6 @@ def test_custom_root_path(self, testapp):

metrics = client.get("/metrics").content.decode()

starlette_version_tuple = tuple(map(int, starlette_version.split(".")))
if starlette_version_tuple < (0, 33):
# These asserts are valid only on Starlette 0.33+
# See https://github.com/encode/starlette/pull/2352"
return

assert (
"""starlette_requests_total{app_name="starlette",method="GET",path="/200/{test_param}",status_code="200"} 1.0"""
in metrics
Expand All @@ -527,7 +520,7 @@ def test_custom_root_path(self, testapp):
"""starlette_requests_total{app_name="starlette",method="GET",path="/unhandled/{test_param}",status_code="500"} 1.0"""
in metrics
)
assert "404" not in metrics
assert "/404" not in metrics

def test_mounted_path_404(self, testapp):
"""test an unhandled path that will be partially matched at the mounted base path (grouped paths)"""
Expand Down

0 comments on commit eb2f19b

Please sign in to comment.