From 1d90b194b2da76b585717f78946a2c21a0993b7a Mon Sep 17 00:00:00 2001 From: shuwenn <47200617+alphabetc1@users.noreply.github.com> Date: Sun, 21 Dec 2025 04:37:53 +0800 Subject: [PATCH] [model-gateway] bugfix: backward compatibility for GET endpoints (#15413) --- .../steps/worker/local/discover_metadata.rs | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/sgl-model-gateway/src/core/steps/worker/local/discover_metadata.rs b/sgl-model-gateway/src/core/steps/worker/local/discover_metadata.rs index 62c4d47fa..ef7a6d150 100644 --- a/sgl-model-gateway/src/core/steps/worker/local/discover_metadata.rs +++ b/sgl-model-gateway/src/core/steps/worker/local/discover_metadata.rs @@ -58,6 +58,48 @@ fn strip_protocol(url: &str) -> String { .to_string() } +/// Fallback function to GET JSON from old endpoint (with "get_" prefix) for backward compatibility. +async fn get_json_fallback( + base_url: &str, + endpoint: &str, + api_key: Option<&str>, +) -> Result { + // FIXME: This fallback logic should be removed together with /get_server_info + // and /get_model_info endpoints in http_server.py + warn!( + concat!( + "Endpoint '/{}' returned 404, falling back to '/get_{}' for backward compatibility. ", + "The '/get_{}' endpoint is deprecated and will be removed in a future version. ", + "Please use '/{}' instead." + ), + endpoint, endpoint, endpoint, endpoint + ); + + let old_url = format!("{}/get_{}", base_url, endpoint); + let mut req = HTTP_CLIENT.get(&old_url); + if let Some(key) = api_key { + req = req.bearer_auth(key); + } + + let response = req + .send() + .await + .map_err(|e| format!("Failed to connect to {}: {}", old_url, e))?; + + if !response.status().is_success() { + return Err(format!( + "Server returned status {} from {}", + response.status(), + old_url + )); + } + + response + .json::() + .await + .map_err(|e| format!("Failed to parse response from {}: {}", old_url, e)) +} + /// Get server info from /server_info endpoint. pub async fn get_server_info(url: &str, api_key: Option<&str>) -> Result { let base_url = url.trim_end_matches('/'); @@ -73,6 +115,13 @@ pub async fn get_server_info(url: &str, api_key: Option<&str>) -> Result) -> Result