Skip to content

Commit 1c621fe

Browse files
authored
fix: Fix issue when user specifies a port for feast ui (#2692)
* fix: Fix issue when user specifies a port for feast ui Signed-off-by: Danny Chiao <[email protected]> * fx Signed-off-by: Danny Chiao <[email protected]> * fix python 3.9 version of importlib Signed-off-by: Danny Chiao <[email protected]> * revert to pkg_resources Signed-off-by: Danny Chiao <[email protected]>
1 parent 2d56963 commit 1c621fe

File tree

4 files changed

+33
-41
lines changed

4 files changed

+33
-41
lines changed

sdk/python/feast/ui/README.md

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Example Feast UI App
22

3-
This is an example React App that imports the Feast UI module and relies on a "/projects-list" endpoint to get projects.
3+
This is an example React App that imports the Feast UI module.
44

55
See the module import in `src/index.js`. The main change this implements on top of a vanilla create-react-app is adding:
66

@@ -11,23 +11,15 @@ import "@feast-dev/feast-ui/dist/feast-ui.css";
1111

1212
ReactDOM.render(
1313
<React.StrictMode>
14-
<FeastUI
15-
feastUIConfigs={{
16-
projectListPromise: fetch("http://0.0.0.0:8888/projects-list", {
17-
headers: {
18-
"Content-Type": "application/json",
19-
},
20-
}).then((res) => {
21-
return res.json();
22-
})
23-
}}
24-
/>
14+
<FeastUI />
2515
</React.StrictMode>,
2616
document.getElementById("root")
2717
);
2818
```
2919

30-
It is used by the `feast ui` command to scaffold a local UI server. The feast python package bundles in resources produced from `npm run build --omit=dev
20+
It is used by the `feast ui` command to scaffold a local UI server. The feast python package bundles in resources produced from `npm run build --omit=dev.`
21+
22+
The `feast ui` command will generate the necessary `projects-list.json` file and initialize it for the UI to read.
3123

3224

3325
**Note**: yarn start will not work on this because of the above dependency.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"projects": [
3+
{
4+
"name": "Project",
5+
"description": "Test project",
6+
"id": "project_id",
7+
"registryPath": "http://0.0.0.0:8888/registry"
8+
}
9+
]
10+
}
11+

sdk/python/feast/ui/src/index.tsx

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
1-
import React from 'react';
1+
import React from "react";
22
import ReactDOM from "react-dom";
3-
import './index.css';
3+
import "./index.css";
44
import FeastUI from "@feast-dev/feast-ui";
55
import "@feast-dev/feast-ui/dist/feast-ui.css";
66

77
ReactDOM.render(
88
<React.StrictMode>
9-
<FeastUI
10-
feastUIConfigs={{
11-
projectListPromise: fetch("http://0.0.0.0:8888/projects-list", {
12-
headers: {
13-
"Content-Type": "application/json",
14-
},
15-
}).then((res) => {
16-
return res.json();
17-
})
18-
}}
19-
/>
9+
<FeastUI />
2010
</React.StrictMode>,
2111
document.getElementById("root")
22-
);
12+
);

sdk/python/feast/ui_server.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ def get_app(
1616
get_registry_dump: Callable,
1717
project_id: str,
1818
registry_ttl_secs: int,
19+
host: str,
20+
port: int,
1921
):
20-
ui_dir = pkg_resources.resource_filename(__name__, "ui/build/")
21-
2222
app = FastAPI()
2323

2424
app.add_middleware(
@@ -53,25 +53,24 @@ def shutdown_event():
5353

5454
async_refresh()
5555

56-
@app.get("/registry")
57-
def read_registry():
58-
return json.loads(registry_json)
59-
60-
# Generate projects-list json that points to the current repo's project
61-
# TODO(adchia): Enable users to also add project name + description fields in feature_store.yaml
62-
@app.get("/projects-list")
63-
def projects_list():
64-
projects = {
56+
ui_dir = pkg_resources.resource_filename(__name__, "ui/build/")
57+
# Initialize with the projects-list.json file
58+
with open(ui_dir + "projects-list.json", mode="w") as f:
59+
projects_dict = {
6560
"projects": [
6661
{
6762
"name": "Project",
6863
"description": "Test project",
6964
"id": project_id,
70-
"registryPath": "http://0.0.0.0:8888/registry",
65+
"registryPath": f"http://{host}:{port}/registry",
7166
}
7267
]
7368
}
74-
return projects
69+
f.write(json.dumps(projects_dict))
70+
71+
@app.get("/registry")
72+
def read_registry():
73+
return json.loads(registry_json)
7574

7675
# For all other paths (such as paths that would otherwise be handled by react router), pass to React
7776
@app.api_route("/p/{path_name:path}", methods=["GET"])
@@ -98,5 +97,5 @@ def start_server(
9897
project_id: str,
9998
registry_ttl_sec: int,
10099
):
101-
app = get_app(store, get_registry_dump, project_id, registry_ttl_sec)
100+
app = get_app(store, get_registry_dump, project_id, registry_ttl_sec, host, port)
102101
uvicorn.run(app, host=host, port=port)

0 commit comments

Comments
 (0)