Skip to content
Merged

Bugs #12

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ The examples below show a minimal integration of **FastAPI** and **Flask** appli
After installing Flask/FastAPI and Pyctuator, start by launching a local Spring Boot Admin instance:

```sh
docker run --rm --name spring-boot-admin -p 8082:8082 michayaak/spring-boot-admin:2.2.2
docker run --rm --name spring-boot-admin -p 8080:8080 michayaak/spring-boot-admin:2.2.3-1
```

Then go to `http://localhost:8082` to get to the web UI.
Then go to `http://localhost:8080` to get to the web UI.

### Flask
The following example is complete and should run as is.
Expand All @@ -92,17 +92,17 @@ def hello():
Pyctuator(
app,
app_name,
"http://host.docker.internal:5000",
"http://host.docker.internal:5000/pyctuator",
"http://localhost:8082/instances"
app_url="http://host.docker.internal:5000",
pyctuator_endpoint_url="http://host.docker.internal:5000/pyctuator",
registration_url="http://localhost:8080/instances"
)

app.run(debug=False, port=5000)
```

The application will automatically register with Spring Boot Admin upon start up.

Log in to the Spring Boot Admin UI at `http://localhost:8082` to interact with the application.
Log in to the Spring Boot Admin UI at `http://localhost:8080` to interact with the application.

### FastAPI
The following example is complete and should run as is.
Expand All @@ -127,17 +127,22 @@ def hello():
Pyctuator(
app,
"FastAPI Pyctuator",
"http://host.docker.internal:8000",
"http://host.docker.internal:8000/pyctuator",
"http://localhost:8080/instances"
app_url="http://host.docker.internal:8000",
pyctuator_endpoint_url="http://host.docker.internal:8000/pyctuator",
registration_url="http://localhost:8080/instances"
)

Server(config=(Config(app=app, loop="asyncio"))).run()
```

The application will automatically register with Spring Boot Admin upon start up.

Log in to the Spring Boot Admin UI at `http://localhost:8082` to interact with the application.
Log in to the Spring Boot Admin UI at `http://localhost:8080` to interact with the application.

### Registration Notes
When registering a service in Spring Boot Admin, note that:
* **Docker** - If the Spring Boot Admin is running in a container while the managed service is running in the docker-host directly, the `app_url` and `pyctuator_endpoint_url` should use `host.docker.internal` as the url's host so Spring Boot Admin will be able to connect to the monitored service.
* **Http Traces** - In order for the "Http Traces" tab to be able to hide requests sent by Spring Boot Admin to the Pyctuator endpoint, `pyctuator_endpoint_url` must be using the same host and port as `app_url`.

## Advanced Configuration
The following sections are intended for advanced users who want to configure advanced Pyctuator features.
Expand Down Expand Up @@ -260,9 +265,9 @@ auth = BasicAuth(os.getenv("sba-username"), os.getenv("sba-password"))
Pyctuator(
app,
"Flask Pyctuator",
"http://localhost:5000",
f"http://localhost:5000/pyctuator",
registration_url=f"http://spring-boot-admin:8082/instances",
app_url="http://localhost:5000",
pyctuator_endpoint_url=f"http://localhost:5000/pyctuator",
registration_url=f"http://spring-boot-admin:8080/instances",
registration_auth=auth,
)
```
Expand All @@ -274,9 +279,9 @@ To run these examples, you'll need to have Spring Boot Admin running in a local

Unless the example includes a docker-compose file, you'll need to start Spring Boot Admin using docker directly:
```sh
docker run -p 8082:8082 michayaak/spring-boot-admin:2.2.2
docker run -p 8080:8080 michayaak/spring-boot-admin:2.2.3-1
```
(the docker image's tag represents the version of Spring Boot Admin, so if you need to use version `2.0.0`, use `michayaak/spring-boot-admin:2.0.0` instead).
(the docker image's tag represents the version of Spring Boot Admin, so if you need to use version `2.0.0`, use `michayaak/spring-boot-admin:2.0.0` instead, note it accepts connections on port 8082).

The examples include
* [FastAPI Example](examples/FastAPI/README.md) - demonstrates integrating Pyctuator with the FastAPI web framework.
Expand Down
5 changes: 2 additions & 3 deletions examples/Advanced/advanced_example_app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import datetime
import logging
import random
import socket
from dataclasses import dataclass
from typing import Any, Dict, List
from starlette.requests import Request
Expand Down Expand Up @@ -36,7 +35,7 @@
},

# the URL to use when accessing the application
"public_endpoint": f"http://{socket.gethostbyname(socket.gethostname())}:8000",
"public_endpoint": f"http://host.docker.internal:8000",
},
"mysql": {
"host": "localhost:3306",
Expand All @@ -50,7 +49,7 @@
"pyctuator_endpoint": f"http://host.docker.internal:8000/pyctuator",

# Spring Boot Admin registration URL
"sba_registration_endpoint": f"http://localhost:8082/instances",
"sba_registration_endpoint": f"http://localhost:8080/instances",
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/Advanced/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ services:
sba:
image: michayaak/spring-boot-admin:2.2.2
ports:
- 8082:8082
- 8080:8080
21 changes: 14 additions & 7 deletions examples/FastAPI/fastapi_example_app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import datetime
import logging
import random
import socket

from fastapi import FastAPI
from uvicorn import Server
Expand All @@ -26,18 +25,26 @@ def read_root():
return "Hello World!"


example_app_public_address = socket.gethostbyname(socket.gethostname())
example_app_address_as_seen_from_sba_container = "host.docker.internal"
example_app_address = "host.docker.internal"
example_sba_address = "localhost"

pyctuator = Pyctuator(
app,
"Example FastAPI",
f"http://{example_app_public_address}:8000",
f"http://{example_app_address_as_seen_from_sba_container}:8000/pyctuator",
f"http://{example_sba_address}:8082/instances",
app_url=f"http://{example_app_address}:8000",
pyctuator_endpoint_url=f"http://{example_app_address}:8000/pyctuator",
registration_url=f"http://{example_sba_address}:8080/instances",
app_description=app.description,
)

server = Server(config=(Config(app=app, loop="asyncio", host="0.0.0.0")))
# Keep the console clear - configure uvicorn (FastAPI's WSGI web app) not to log the detail of every incoming request
uvicorn_logger = logging.getLogger("uvicorn")
uvicorn_logger.setLevel(logging.WARNING)

server = Server(config=(Config(
app=app,
loop="asyncio",
host="0.0.0.0",
logger=uvicorn_logger,
)))
server.run()
13 changes: 7 additions & 6 deletions examples/Flask/flask_example_app.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import datetime
import logging
import random
import socket

from flask import Flask

from pyctuator.pyctuator import Pyctuator

logging.basicConfig(level=logging.INFO)

# Keep the console clear - configure werkzeug (flask's WSGI web app) not to log the detail of every incoming request
logging.getLogger("werkzeug").setLevel(logging.WARNING)

my_logger = logging.getLogger("example")

app = Flask("Flask Example Server")
Expand All @@ -21,16 +23,15 @@ def hello():
return "Hello World!"


example_app_public_address = socket.gethostbyname(socket.gethostname())
example_app_address_as_seen_from_sba_container = "host.docker.internal"
example_app_address = "host.docker.internal"
example_sba_address = "localhost"

Pyctuator(
app,
"Flask Pyctuator",
f"http://{example_app_public_address}:5000",
f"http://{example_app_address_as_seen_from_sba_container}:5000/pyctuator",
f"http://{example_sba_address}:8082/instances",
app_url=f"http://{example_app_address}:5000",
pyctuator_endpoint_url=f"http://{example_app_address}:5000/pyctuator",
registration_url=f"http://{example_sba_address}:8080/instances",
app_description="Demonstrate Spring Boot Admin Integration with Flask",
)

Expand Down
48 changes: 0 additions & 48 deletions pyctuator/httptrace/fastapi_http_tracer.py

This file was deleted.

49 changes: 0 additions & 49 deletions pyctuator/httptrace/flask_http_tracer.py

This file was deleted.

1 change: 1 addition & 0 deletions pyctuator/impl/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SBA_V2_CONTENT_TYPE = "application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"
Loading