Add sgl_router_attempt_http_responses_total for single attempt information (#15037)
This commit is contained in:
@@ -330,10 +330,11 @@ impl RouterMetrics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO unify metric names
|
// TODO unify metric names
|
||||||
pub fn record_upstream_http_response(route: &str, status_code: u16) {
|
pub fn record_attempt_http_response(route: &str, status_code: u16, error_code: &str) {
|
||||||
counter!("sgl_router_upstream_http_responses_total",
|
counter!("sgl_router_attempt_http_responses_total",
|
||||||
"route" => route.to_string(),
|
"route" => route.to_string(),
|
||||||
"status_code" => status_code.to_string()
|
"status_code" => status_code.to_string(),
|
||||||
|
"error_code" => error_code.to_string()
|
||||||
)
|
)
|
||||||
.increment(1);
|
.increment(1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -170,8 +170,18 @@ impl Router {
|
|||||||
&self.retry_config,
|
&self.retry_config,
|
||||||
// operation per attempt
|
// operation per attempt
|
||||||
|_: u32| async {
|
|_: u32| async {
|
||||||
self.route_typed_request_once(headers, typed_req, route, model_id, is_stream, &text)
|
let res = self
|
||||||
.await
|
.route_typed_request_once(headers, typed_req, route, model_id, is_stream, &text)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
// Need to be outside `route_typed_request_once` because that function has multiple return paths
|
||||||
|
RouterMetrics::record_attempt_http_response(
|
||||||
|
route,
|
||||||
|
res.status().as_u16(),
|
||||||
|
extract_error_code_from_response(&res),
|
||||||
|
);
|
||||||
|
|
||||||
|
res
|
||||||
},
|
},
|
||||||
// should_retry predicate
|
// should_retry predicate
|
||||||
|res, _attempt| is_retryable_status(res.status()),
|
|res, _attempt| is_retryable_status(res.status()),
|
||||||
@@ -505,8 +515,6 @@ impl Router {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
RouterMetrics::record_upstream_http_response(route, res.status().as_u16());
|
|
||||||
|
|
||||||
let status = StatusCode::from_u16(res.status().as_u16())
|
let status = StatusCode::from_u16(res.status().as_u16())
|
||||||
.unwrap_or(StatusCode::INTERNAL_SERVER_ERROR);
|
.unwrap_or(StatusCode::INTERNAL_SERVER_ERROR);
|
||||||
|
|
||||||
@@ -715,6 +723,8 @@ fn convert_reqwest_error(e: reqwest::Error) -> Response {
|
|||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
|
||||||
|
use crate::routers::error::extract_error_code_from_response;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl RouterTrait for Router {
|
impl RouterTrait for Router {
|
||||||
fn as_any(&self) -> &dyn std::any::Any {
|
fn as_any(&self) -> &dyn std::any::Any {
|
||||||
|
|||||||
Reference in New Issue
Block a user