Skip to content

Commit 84fafc4

Browse files
aliabid94Ali Abidgradio-pr-bot
authored
Fix /monitoring endpoint (#10872)
* changes * add changeset * Update routes.py * add changeset * changes --------- Co-authored-by: Ali Abid <[email protected]> Co-authored-by: gradio-pr-bot <[email protected]>
1 parent fc23290 commit 84fafc4

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

.changeset/curly-eagles-stand.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gradio": patch
3+
---
4+
5+
fix:Fix `/monitoring` endpoint

gradio/monitoring_dashboard.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
outputs=[plot, unique_users, total_requests, process_time],
5757
)
5858
def gen_plot(start, end, selected_fn):
59+
if len(data["data"]) == 0:
60+
return {plot: gr.skip()}
5961
df = pd.DataFrame(list(data["data"].values()))
6062
if selected_fn != "All":
6163
df = df[df["function"] == selected_fn]

gradio/routes.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,7 @@ def manifest_json():
16201620
media_type="application/manifest+json",
16211621
)
16221622

1623-
@router.get("/monitoring", dependencies=[Depends(login_check)])
1623+
@app.get("/monitoring", dependencies=[Depends(login_check)])
16241624
async def analytics_login(request: fastapi.Request):
16251625
if not blocks.enable_monitoring:
16261626
raise HTTPException(
@@ -1635,7 +1635,7 @@ async def analytics_login(request: fastapi.Request):
16351635
print(f"* Monitoring URL: {monitoring_url} *")
16361636
return HTMLResponse("See console for monitoring URL.")
16371637

1638-
@router.get("/monitoring/{key}")
1638+
@app.get("/monitoring/{key}")
16391639
async def analytics_dashboard(key: str):
16401640
if not blocks.enable_monitoring:
16411641
raise HTTPException(
@@ -1866,4 +1866,5 @@ async def new_lifespan(app: FastAPI):
18661866
"assets",
18671867
"favicon.ico",
18681868
"gradio_api",
1869+
"monitoring",
18691870
]

test/test_routes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ def test_monitoring_link(self):
680680

681681
app, _, _ = demo.launch(prevent_thread_lock=True)
682682
client = TestClient(app)
683-
response = client.get(f"{API_PREFIX}/monitoring")
683+
response = client.get("/monitoring")
684684
assert response.status_code == 200
685685

686686
def test_monitoring_link_disabled(self):
@@ -691,7 +691,7 @@ def test_monitoring_link_disabled(self):
691691

692692
app, _, _ = demo.launch(prevent_thread_lock=True, enable_monitoring=False)
693693
client = TestClient(app)
694-
response = client.get(f"{API_PREFIX}/monitoring")
694+
response = client.get("/monitoring")
695695
assert response.status_code == 403
696696

697697

@@ -784,14 +784,14 @@ def test_monitoring_route(self):
784784
)
785785

786786
response = client.get(
787-
f"{API_PREFIX}/monitoring",
787+
"/monitoring",
788788
)
789789
assert response.status_code == 200
790790

791791
response = client.get("/logout")
792792

793793
response = client.get(
794-
f"{API_PREFIX}/monitoring",
794+
"/monitoring",
795795
)
796796
assert response.status_code == 401
797797

0 commit comments

Comments
 (0)