-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Display performance metrics for API/MCP requests in View API page #11764
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
Changes from all commits
4a51871
a20824a
adb3785
e5c0370
b287c7c
1df6f6a
6fa3996
9f54dea
1e268f3
50e91bb
94c7903
9e302ed
db344c7
9ae6353
b21d867
a5046ab
9cdd5aa
1a9be5c
c8f9c12
ecde9eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@gradio/core": minor | ||
"gradio": minor | ||
--- | ||
|
||
feat:Display performance metrics for API/MCP requests in View API page |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,6 +99,7 @@ | |
}; | ||
|
||
let js_info: Record<string, any>; | ||
let analytics: Record<string, any>; | ||
|
||
get_info().then((data) => { | ||
info = data; | ||
|
@@ -108,6 +109,18 @@ | |
js_info = js_api_info; | ||
}); | ||
|
||
async function get_summary(): Promise<{ | ||
functions: any; | ||
}> { | ||
let response = await fetch(root.replace(/\/$/, "") + "/monitoring/summary"); | ||
let data = await response.json(); | ||
return data; | ||
} | ||
|
||
get_summary().then((summary) => { | ||
analytics = summary.functions; | ||
}); | ||
|
||
const dispatch = createEventDispatcher(); | ||
|
||
$: selected_tools_array = Array.from(selected_tools); | ||
|
@@ -148,6 +161,7 @@ | |
meta: { | ||
mcp_type: "tool" | "resource" | "prompt"; | ||
file_data_present: boolean; | ||
endpoint_name: string; | ||
}; | ||
} | ||
|
||
|
@@ -192,7 +206,8 @@ | |
description: tool.description || "", | ||
parameters: tool.inputSchema?.properties || {}, | ||
meta: tool.meta, | ||
expanded: false | ||
expanded: false, | ||
endpoint_name: tool.endpoint_name | ||
})); | ||
selected_tools = new Set(tools.map((tool) => tool.name)); | ||
headers = schema.map((tool: any) => tool.meta?.headers || []).flat(); | ||
|
@@ -260,6 +275,9 @@ | |
} | ||
|
||
onMount(() => { | ||
const controller = new AbortController(); | ||
const signal = controller.signal; | ||
|
||
document.body.style.overflow = "hidden"; | ||
if ("parentIFrame" in window) { | ||
window.parentIFrame?.scrollTo(0, 0); | ||
|
@@ -271,7 +289,7 @@ | |
} | ||
|
||
// Check MCP server status and fetch tools if active | ||
fetch(mcp_server_url) | ||
fetch(mcp_server_url, { signal: signal }) | ||
.then((response) => { | ||
mcp_server_active = response.ok; | ||
if (mcp_server_active) { | ||
|
@@ -284,6 +302,7 @@ | |
current_language = "python"; | ||
} | ||
} | ||
controller.abort(); | ||
}) | ||
.catch(() => { | ||
mcp_server_active = false; | ||
|
@@ -295,7 +314,7 @@ | |
}); | ||
</script> | ||
|
||
{#if info} | ||
{#if info && analytics} | ||
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. If there are no analytics, the entire api docs will not be visible? 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. I don't think so. Analytics will always be an object once the request completes. So this is just so that the page is not visible while there are requests in flight. But I will verify jic. |
||
{#if api_count} | ||
<div class="banner-wrap"> | ||
<ApiBanner | ||
|
@@ -385,6 +404,7 @@ | |
{mcp_json_stdio} | ||
{file_data_present} | ||
{mcp_docs} | ||
{analytics} | ||
/> | ||
{:else} | ||
1. Confirm that you have cURL installed on your system. | ||
|
@@ -461,6 +481,7 @@ | |
api_description={info.named_endpoints[ | ||
"/" + dependency.api_name | ||
].description} | ||
{analytics} | ||
/> | ||
|
||
<ParametersSnippet | ||
|
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.
Fetching the mcp_server_url opens a persistent connection. That means opening the view api page 5 or more times from the same browser session causes the whole page to freeze because we reach the 5 concurrent connection limit. So I changed it to close the connection immediately.
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.
got it, interesting