-
Notifications
You must be signed in to change notification settings - Fork 30
add raw data path to apps #740
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
Open
cosmicBboy
wants to merge
4
commits into
main
Choose a base branch
from
nielsb/add-raw-data-path-to-apps
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| """FastAPI app that returns the raw data path from flyte.app.ctx.""" | ||
|
|
||
| from fastapi import FastAPI | ||
|
|
||
| import flyte | ||
| from flyte.app import ctx | ||
| from flyte.app.extras import FastAPIAppEnvironment | ||
|
|
||
| app = FastAPI( | ||
| title="Raw Data Path Demo", | ||
| description="Returns the raw data path from flyte.app.ctx", | ||
| version="1.0.0", | ||
| ) | ||
|
|
||
| app_env = FastAPIAppEnvironment( | ||
| name="raw-data-path-demo", | ||
| app=app, | ||
| description="App that returns the raw data path from ctx", | ||
| image=flyte.Image.from_debian_base().with_pip_packages("fastapi", "uvicorn"), | ||
| resources=flyte.Resources(cpu=1, memory="512Mi"), | ||
| requires_auth=False, | ||
| env_vars={"LOG_LEVEL": "10"}, | ||
| ) | ||
|
|
||
|
|
||
| @app.get("/") | ||
| async def root() -> str: | ||
| """Return the raw data path from flyte.app.ctx.""" | ||
| return ctx().raw_data_path or "" | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| import pathlib | ||
|
|
||
| flyte.init_from_config(root_dir=pathlib.Path(__file__).parent) | ||
| app_handle = flyte.serve(app_env) | ||
| print(f"Deployed app: {app_handle.url}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -345,6 +345,7 @@ def __init__( | |
| health_check_timeout: float | None = None, | ||
| health_check_interval: float | None = None, | ||
| health_check_path: str | None = None, | ||
| raw_data_path: str | None = None, | ||
| ): | ||
| """ | ||
| Initialize serve context. | ||
|
|
@@ -375,6 +376,10 @@ def __init__( | |
| Defaults to `1` second. | ||
| health_check_path: URL path used for the local health-check probe (e.g. `"/healthz"`). | ||
| Defaults to `"/health"`. | ||
| raw_data_path: Raw data path for the app. For local serving, used when testing apps | ||
| that read ctx().raw_data_path. Defaults to ``/tmp/flyte/raw_data`` when mode is | ||
| local and not specified. For remote serving, the backend provides this via the | ||
| container command. | ||
| """ | ||
| from flyte._initialize import _get_init_config | ||
|
|
||
|
|
@@ -407,6 +412,9 @@ def __init__( | |
| health_check_interval if health_check_interval is not None else _LOCAL_IS_ACTIVE_INTERVAL | ||
| ) | ||
| self._health_check_path = health_check_path if health_check_path is not None else _LOCAL_HEALTH_CHECK_PATH | ||
| self._raw_data_path = ( | ||
| raw_data_path if raw_data_path is not None else ("/tmp/flyte/raw_data" if self._mode == "local" else "") | ||
| ) | ||
|
|
||
| # ------------------------------------------------------------------ | ||
| # Local serving | ||
|
|
@@ -478,6 +486,12 @@ def _serve_local_with_server_func( | |
| local_app = _LocalApp(app_env=app_env, _serve_obj=self, host=host, port=port) | ||
|
|
||
| def _run(): | ||
| # Contextvars don't propagate to new threads. Set raw_data_path in this | ||
| # thread's context so ctx().raw_data_path works in request handlers. | ||
| from flyte.app._context import set_raw_data_path | ||
|
|
||
| set_raw_data_path(self._raw_data_path or "") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does it work if we run two apps locally? Both of them will override the same env vars, right?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep, but it should be the same raw data path in |
||
|
|
||
| loop = asyncio.new_event_loop() | ||
| asyncio.set_event_loop(loop) | ||
| local_app._thread_loop = loop | ||
|
|
@@ -757,6 +771,7 @@ def with_servecontext( | |
| health_check_timeout: float | None = None, | ||
| health_check_interval: float | None = None, | ||
| health_check_path: str | None = None, | ||
| raw_data_path: str | None = None, | ||
| ) -> _Serve: | ||
| """ | ||
| Create a serve context with custom configuration. | ||
|
|
@@ -821,6 +836,9 @@ def with_servecontext( | |
| Defaults to 1 s. | ||
| health_check_path: URL path used for the local health-check probe (e.g. ``"/healthz"``). | ||
| Defaults to ``"/health"``. | ||
| raw_data_path: Raw data path for the app. For local serving, sets ctx().raw_data_path | ||
| so apps can read it. Defaults to ``/tmp/flyte/raw_data`` when mode is local. | ||
| For remote serving, the backend provides this via the container command. | ||
|
|
||
| Returns: | ||
| _Serve: Serve context manager with configured settings | ||
|
|
@@ -853,6 +871,7 @@ def with_servecontext( | |
| health_check_timeout=health_check_timeout, | ||
| health_check_interval=health_check_interval, | ||
| health_check_path=health_check_path, | ||
| raw_data_path=raw_data_path, | ||
| ) | ||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Instead of updating the env var in set_raw_data_path, would it be better to just pass raw_data_path to _serve()?
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.
done, can you re-+1?