Skip to content

Commit 3fc7437

Browse files
authored
Merge pull request #12 from SolarEdgeTech/bugs
Fix several httptrace-related bugs
2 parents 5cd6434 + 25e63d7 commit 3fc7437

File tree

12 files changed

+177
-188
lines changed

12 files changed

+177
-188
lines changed

README.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ The examples below show a minimal integration of **FastAPI** and **Flask** appli
6868
After installing Flask/FastAPI and Pyctuator, start by launching a local Spring Boot Admin instance:
6969

7070
```sh
71-
docker run --rm --name spring-boot-admin -p 8082:8082 michayaak/spring-boot-admin:2.2.2
71+
docker run --rm --name spring-boot-admin -p 8080:8080 michayaak/spring-boot-admin:2.2.3-1
7272
```
7373

74-
Then go to `http://localhost:8082` to get to the web UI.
74+
Then go to `http://localhost:8080` to get to the web UI.
7575

7676
### Flask
7777
The following example is complete and should run as is.
@@ -92,17 +92,17 @@ def hello():
9292
Pyctuator(
9393
app,
9494
app_name,
95-
"http://host.docker.internal:5000",
96-
"http://host.docker.internal:5000/pyctuator",
97-
"http://localhost:8082/instances"
95+
app_url="http://host.docker.internal:5000",
96+
pyctuator_endpoint_url="http://host.docker.internal:5000/pyctuator",
97+
registration_url="http://localhost:8080/instances"
9898
)
9999

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

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

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

107107
### FastAPI
108108
The following example is complete and should run as is.
@@ -127,17 +127,22 @@ def hello():
127127
Pyctuator(
128128
app,
129129
"FastAPI Pyctuator",
130-
"http://host.docker.internal:8000",
131-
"http://host.docker.internal:8000/pyctuator",
132-
"http://localhost:8080/instances"
130+
app_url="http://host.docker.internal:8000",
131+
pyctuator_endpoint_url="http://host.docker.internal:8000/pyctuator",
132+
registration_url="http://localhost:8080/instances"
133133
)
134134

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

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

140-
Log in to the Spring Boot Admin UI at `http://localhost:8082` to interact with the application.
140+
Log in to the Spring Boot Admin UI at `http://localhost:8080` to interact with the application.
141+
142+
### Registration Notes
143+
When registering a service in Spring Boot Admin, note that:
144+
* **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.
145+
* **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`.
141146

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

275280
Unless the example includes a docker-compose file, you'll need to start Spring Boot Admin using docker directly:
276281
```sh
277-
docker run -p 8082:8082 michayaak/spring-boot-admin:2.2.2
282+
docker run -p 8080:8080 michayaak/spring-boot-admin:2.2.3-1
278283
```
279-
(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).
284+
(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).
280285

281286
The examples include
282287
* [FastAPI Example](examples/FastAPI/README.md) - demonstrates integrating Pyctuator with the FastAPI web framework.

examples/Advanced/advanced_example_app.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import datetime
22
import logging
33
import random
4-
import socket
54
from dataclasses import dataclass
65
from typing import Any, Dict, List
76
from starlette.requests import Request
@@ -36,7 +35,7 @@
3635
},
3736

3837
# the URL to use when accessing the application
39-
"public_endpoint": f"http://{socket.gethostbyname(socket.gethostname())}:8000",
38+
"public_endpoint": f"http://host.docker.internal:8000",
4039
},
4140
"mysql": {
4241
"host": "localhost:3306",
@@ -50,7 +49,7 @@
5049
"pyctuator_endpoint": f"http://host.docker.internal:8000/pyctuator",
5150

5251
# Spring Boot Admin registration URL
53-
"sba_registration_endpoint": f"http://localhost:8082/instances",
52+
"sba_registration_endpoint": f"http://localhost:8080/instances",
5453
}
5554
}
5655

examples/Advanced/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ services:
1313
sba:
1414
image: michayaak/spring-boot-admin:2.2.2
1515
ports:
16-
- 8082:8082
16+
- 8080:8080

examples/FastAPI/fastapi_example_app.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import datetime
22
import logging
33
import random
4-
import socket
54

65
from fastapi import FastAPI
76
from uvicorn import Server
@@ -26,18 +25,26 @@ def read_root():
2625
return "Hello World!"
2726

2827

29-
example_app_public_address = socket.gethostbyname(socket.gethostname())
30-
example_app_address_as_seen_from_sba_container = "host.docker.internal"
28+
example_app_address = "host.docker.internal"
3129
example_sba_address = "localhost"
3230

3331
pyctuator = Pyctuator(
3432
app,
3533
"Example FastAPI",
36-
f"http://{example_app_public_address}:8000",
37-
f"http://{example_app_address_as_seen_from_sba_container}:8000/pyctuator",
38-
f"http://{example_sba_address}:8082/instances",
34+
app_url=f"http://{example_app_address}:8000",
35+
pyctuator_endpoint_url=f"http://{example_app_address}:8000/pyctuator",
36+
registration_url=f"http://{example_sba_address}:8080/instances",
3937
app_description=app.description,
4038
)
4139

42-
server = Server(config=(Config(app=app, loop="asyncio", host="0.0.0.0")))
40+
# Keep the console clear - configure uvicorn (FastAPI's WSGI web app) not to log the detail of every incoming request
41+
uvicorn_logger = logging.getLogger("uvicorn")
42+
uvicorn_logger.setLevel(logging.WARNING)
43+
44+
server = Server(config=(Config(
45+
app=app,
46+
loop="asyncio",
47+
host="0.0.0.0",
48+
logger=uvicorn_logger,
49+
)))
4350
server.run()

examples/Flask/flask_example_app.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import datetime
22
import logging
33
import random
4-
import socket
54

65
from flask import Flask
76

87
from pyctuator.pyctuator import Pyctuator
98

109
logging.basicConfig(level=logging.INFO)
1110

11+
# Keep the console clear - configure werkzeug (flask's WSGI web app) not to log the detail of every incoming request
12+
logging.getLogger("werkzeug").setLevel(logging.WARNING)
13+
1214
my_logger = logging.getLogger("example")
1315

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

2325

24-
example_app_public_address = socket.gethostbyname(socket.gethostname())
25-
example_app_address_as_seen_from_sba_container = "host.docker.internal"
26+
example_app_address = "host.docker.internal"
2627
example_sba_address = "localhost"
2728

2829
Pyctuator(
2930
app,
3031
"Flask Pyctuator",
31-
f"http://{example_app_public_address}:5000",
32-
f"http://{example_app_address_as_seen_from_sba_container}:5000/pyctuator",
33-
f"http://{example_sba_address}:8082/instances",
32+
app_url=f"http://{example_app_address}:5000",
33+
pyctuator_endpoint_url=f"http://{example_app_address}:5000/pyctuator",
34+
registration_url=f"http://{example_sba_address}:8080/instances",
3435
app_description="Demonstrate Spring Boot Admin Integration with Flask",
3536
)
3637

pyctuator/httptrace/fastapi_http_tracer.py

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

pyctuator/httptrace/flask_http_tracer.py

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

pyctuator/impl/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SBA_V2_CONTENT_TYPE = "application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"

0 commit comments

Comments
 (0)