-
Notifications
You must be signed in to change notification settings - Fork 207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add ASGI root path parameter to Phoenix server #3186
Conversation
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
d388c72
to
9535709
Compare
Allow for a root path parameter so that Phoenix can be hosted behind a proxy with a path prefix
9535709
to
4779edd
Compare
I have read the CLA Document and I hereby sign the CLA |
src/phoenix/config.py
Outdated
@@ -10,6 +10,7 @@ | |||
ENV_PHOENIX_PORT = "PHOENIX_PORT" | |||
ENV_PHOENIX_GRPC_PORT = "PHOENIX_GRPC_PORT" | |||
ENV_PHOENIX_HOST = "PHOENIX_HOST" | |||
ENV_PHOENIX_ROOT_PATH = "PHOENIX_ROOT_PATH" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the changing env var name PHOENIX_HOST_ROOT_PATH
is a bit better? We manage all of our configuration via environment variables and PHOENIX_ROOT_PATH
might sound a little too generic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, should we match the CLI parameter then to also be --host-root-path
or should we stick with the --root-path
parameter as it is known from uvicorn, for example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Went with the matching CLI parameter for now.
Thanks so much for the contribution @sbachstein! This looks great, small request for a more specific config name |
The client needs to be updated, otherwise it'll have the wrong url. e.g. phoenix/src/phoenix/session/client.py Line 244 in 5e8bc3d
|
The client provides the option to take the base path from the endpoint parameter (or environment variable). Do you think this is not sufficient and we need to, additionally, offer the option to specify HOST, PORT and ROOT_PATH? |
Very good catch, thank you for the hint. I adjusted all usages of |
Thanks for the update. Can we make sure that
>>> from urllib.parse import urljoin
>>> urljoin("http://xyz.com/abc", "rst")
'http://xyz.com/rst' While we're at it, we could also add the root path as shown below. self._base_url = (
endpoint
or get_env_collector_endpoint()
or urljoin(f"http://{host}:{get_env_port()}", get_env_host_root_path())
).rstrip("/") + "/" phoenix/src/phoenix/session/client.py Lines 58 to 60 in 5e8bc3d
|
src/phoenix/server/main.py
Outdated
@@ -119,6 +120,7 @@ def _get_pid_file() -> Path: | |||
parser.add_argument("--export_path") | |||
parser.add_argument("--host", type=str, required=False) | |||
parser.add_argument("--port", type=int, required=False) | |||
parser.add_argument("--host-root-path", type=str, required=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure we need the command line argument here in addition to the environment variable. We've been deprecating command line arguments such as --enable-prometheus
that have environment variable equivalents if setting them via environment variables feels more natural, e.g., in Kubernetes. I think host root path probably falls into that category.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, I removed the CLI parameter.
CLI parameters for settings that are naturally adjusted via environment variables are discouraged for Phoenix
@RogerHYang Thank you for the hint again, that was kind of unexpected behavior for me, good to know! |
169f514
to
6890a90
Compare
@@ -18,6 +18,29 @@ | |||
from phoenix.trace.trace_dataset import TraceDataset | |||
|
|||
|
|||
def test_base_path(monkeypatch: pytest.MonkeyPatch): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for the test!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sbachstein looks like the starlette app needs to be made aware of the root path too, thanks for checking this @RogerHYang |
To me that is expected behavior. If the application is mounted at a root path with prefix by a proxy then the proxy would also make sure to rewrite the HTTP path and remove the root path from the request. That is also how I understand and have experienced the mechanisms of uvicorn/starlette root paths. Here is how FastAPI explains the behavior of the root path: https://fastapi.tiangolo.com/advanced/behind-a-proxy/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is LGTM. Sorry for the hold up.
Thank you for the thorough review! |
@sbachstein Thanks for making Phoenix better! |
Fixes #2918
Allow for a root path parameter so that Phoenix can be hosted behind a proxy with a path prefix.
Session
code has not been adjusted because the adjustment of the root path is probably not needed in this scenario.Client
andExporter
code have not been adjusted because they provide explicitendpoint
parameters where a full URL can be given.