Skip to content

Commit

Permalink
Modify to test async stuff as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Brett Beutell committed May 9, 2023
1 parent a29a178 commit d6abce3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 27 deletions.
15 changes: 2 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
env/
venv/
.venv/
.DS_Store

# Custom
.vscode/
personal-notes.md

shame-deps/*.whl


#custom
data/
.vscode/
my_testing/
autometrics-venv/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ PROMETHEUS_URL=http://localhost:8063
Create and activate virtual env

```sh
python3 -m venv env
python3 -m venv .venv
source env/bin/activate
```

Expand All @@ -53,7 +53,7 @@ pip install -r requirements.txt
Run app

```sh
uvicorn fastapi-example:app --reload
uvicorn fastapi-example:app --reload --port=8080
```

### Install and Configure Autometrics VSCode Extension
Expand Down
30 changes: 27 additions & 3 deletions fastapi-example.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,42 @@
from fastapi import FastAPI
from fastapi import FastAPI, Response
import uvicorn
from autometrics import autometrics
from prometheus_client import generate_latest

app = FastAPI()


# Set up a metrics endpoint for Prometheus to scrape
# `generate_lates` returns the latest metrics data in the Prometheus text format
@app.get("/metrics")
def metrics():
return Response(generate_latest())


@app.get("/")
@autometrics
def read_root():
do_something()
return {"Hello": "World"}


@app.get("/async-test")
@autometrics
async def async_test_route():
message = await my_async_function()
return {"Hello": message}


@autometrics
def do_something():
print("I did something")

if __name__ == "__main__":
uvicorn.run(app, host="localhost", port=8080)

@autometrics
async def my_async_function():
print("I did something async")
return "Hello, async world!"


if __name__ == "__main__":
uvicorn.run(app, host="localhost", port=8080)
7 changes: 0 additions & 7 deletions prometheus.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
scrape_configs:
- job_name: python-autometrics-example-fastapi
metrics_path: /metrics
static_configs:
- targets: ["host.docker.internal:8000"]
# For a real deployment, you would want the scrape interval to be
# longer but for testing, you want the data to show up quickly
scrape_interval: 500ms
- job_name: python-autometrics-example-example
metrics_path: /metrics
static_configs:
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
anyio==3.6.2
# autometrics==0.4
shame-deps/autometrics-0.5-py3-none-any.whl
# shame-deps/autometrics-0.5-py3-none-any.whl
# -e git+ssh://[email protected]/autometrics-dev/autometrics-py.git@0a11a33315bba5ba843b6b543e464b2871dd5206#egg=autometrics
# -e ../autometrics-py
-e ../autometrics-py
click==8.1.3
fastapi==0.95.0
h11==0.14.0
Expand Down

0 comments on commit d6abce3

Please sign in to comment.