Super tiny move error.rs (#14944)

This commit is contained in:
fzyzcjy
2025-12-12 14:25:30 +08:00
committed by GitHub
parent bd91f8824a
commit a7fa31ff17
29 changed files with 125 additions and 87 deletions
@@ -318,8 +318,7 @@ impl RouterMetrics {
} }
pub fn record_request_duration(duration: Duration) { pub fn record_request_duration(duration: Duration) {
histogram!("sgl_router_request_duration_seconds") histogram!("sgl_router_request_duration_seconds").record(duration.as_secs_f64());
.record(duration.as_secs_f64());
} }
pub fn record_request_error(route: &str, error_type: &str) { pub fn record_request_error(route: &str, error_type: &str) {
@@ -5,8 +5,9 @@
use axum::response::Response; use axum::response::Response;
use crate::routers::grpc::{ use crate::routers::{
context::ExecutionResult, error, proto_wrapper::ProtoGenerateComplete, utils, error,
grpc::{context::ExecutionResult, proto_wrapper::ProtoGenerateComplete, utils},
}; };
/// Collect and merge responses from execution result /// Collect and merge responses from execution result
@@ -18,7 +18,7 @@ use crate::{
responses::{ResponseTool, ResponseToolType, ResponsesRequest, ResponsesResponse}, responses::{ResponseTool, ResponseToolType, ResponsesRequest, ResponsesResponse},
}, },
routers::{ routers::{
grpc::error, error,
openai::{conversations::persist_conversation_items, mcp::ensure_request_mcp_client}, openai::{conversations::persist_conversation_items, mcp::ensure_request_mcp_client},
}, },
}; };
@@ -5,9 +5,12 @@ use axum::response::Response;
use tracing::error; use tracing::error;
use super::PipelineStage; use super::PipelineStage;
use crate::routers::grpc::{ use crate::routers::{
context::{ClientSelection, RequestContext, WorkerSelection}, error,
error, utils, grpc::{
context::{ClientSelection, RequestContext, WorkerSelection},
utils,
},
}; };
/// Client acquisition stage: Get gRPC clients from selected workers /// Client acquisition stage: Get gRPC clients from selected workers
@@ -7,9 +7,9 @@ use axum::response::Response;
use tracing::error; use tracing::error;
use super::PipelineStage; use super::PipelineStage;
use crate::routers::grpc::{ use crate::routers::{
context::{DispatchMetadata, RequestContext, RequestType, WorkerSelection},
error, error,
grpc::context::{DispatchMetadata, RequestContext, RequestType, WorkerSelection},
}; };
/// Dispatch metadata stage: Prepare metadata for dispatch /// Dispatch metadata stage: Prepare metadata for dispatch
@@ -5,10 +5,12 @@ use axum::response::Response;
use tracing::{error, info_span, Instrument}; use tracing::{error, info_span, Instrument};
use super::PipelineStage; use super::PipelineStage;
use crate::routers::grpc::{ use crate::routers::{
context::{ClientSelection, ExecutionResult, RequestContext},
error, error,
proto_wrapper::{ProtoGenerateRequest, ProtoStream}, grpc::{
context::{ClientSelection, ExecutionResult, RequestContext},
proto_wrapper::{ProtoGenerateRequest, ProtoStream},
},
}; };
type StreamResult = Result<ProtoStream, Box<dyn std::error::Error + Send + Sync>>; type StreamResult = Result<ProtoStream, Box<dyn std::error::Error + Send + Sync>>;
@@ -10,9 +10,9 @@ use super::PipelineStage;
use crate::{ use crate::{
core::{ConnectionMode, Worker, WorkerRegistry, WorkerType}, core::{ConnectionMode, Worker, WorkerRegistry, WorkerType},
policies::PolicyRegistry, policies::PolicyRegistry,
routers::grpc::{ routers::{
context::{RequestContext, WorkerSelection},
error, error,
grpc::context::{RequestContext, WorkerSelection},
}, },
}; };
@@ -16,10 +16,12 @@ use crate::{
ResponseStatus, ResponseUsage, ResponsesRequest, ResponsesResponse, ResponsesUsage, ResponseStatus, ResponseUsage, ResponsesRequest, ResponsesResponse, ResponsesUsage,
}, },
}, },
routers::grpc::{ routers::{
common::{response_collection, response_formatting},
context::{DispatchMetadata, ExecutionResult},
error, error,
grpc::{
common::{response_collection, response_formatting},
context::{DispatchMetadata, ExecutionResult},
},
}, },
}; };
@@ -54,15 +54,17 @@ use crate::{
ResponsesUsage, StringOrContentParts, ResponsesUsage, StringOrContentParts,
}, },
}, },
routers::grpc::{ routers::{
common::responses::{
build_sse_response, ensure_mcp_connection, persist_response_if_needed,
streaming::{OutputItemType, ResponseStreamEventEmitter},
},
context::SharedComponents,
error, error,
harmony::{processor::ResponsesIterationResult, streaming::HarmonyStreamingProcessor}, grpc::{
pipeline::RequestPipeline, common::responses::{
build_sse_response, ensure_mcp_connection, persist_response_if_needed,
streaming::{OutputItemType, ResponseStreamEventEmitter},
},
context::SharedComponents,
harmony::{processor::ResponsesIterationResult, streaming::HarmonyStreamingProcessor},
pipeline::RequestPipeline,
},
}, },
}; };
@@ -12,10 +12,13 @@ use crate::{
common::{Tool, ToolChoice, ToolChoiceValue}, common::{Tool, ToolChoice, ToolChoiceValue},
responses::ResponsesRequest, responses::ResponsesRequest,
}, },
routers::grpc::{ routers::{
common::{responses::utils::extract_tools_from_response_tools, stages::PipelineStage}, error,
context::{PreparationOutput, RequestContext, RequestType}, grpc::{
error, utils, common::{responses::utils::extract_tools_from_response_tools, stages::PipelineStage},
context::{PreparationOutput, RequestContext, RequestType},
utils,
},
}, },
}; };
@@ -5,11 +5,13 @@ use axum::response::Response;
use tracing::{debug, error}; use tracing::{debug, error};
use uuid::Uuid; use uuid::Uuid;
use crate::routers::grpc::{ use crate::routers::{
common::stages::{helpers, PipelineStage},
context::{ClientSelection, RequestContext, RequestType, WorkerSelection},
error, error,
proto_wrapper::ProtoGenerateRequest, grpc::{
common::stages::{helpers, PipelineStage},
context::{ClientSelection, RequestContext, RequestType, WorkerSelection},
proto_wrapper::ProtoGenerateRequest,
},
}; };
/// Harmony Request Building stage: Convert Harmony tokens to gRPC request /// Harmony Request Building stage: Convert Harmony tokens to gRPC request
@@ -7,10 +7,12 @@ use axum::response::Response;
use tracing::error; use tracing::error;
use super::super::{HarmonyResponseProcessor, HarmonyStreamingProcessor}; use super::super::{HarmonyResponseProcessor, HarmonyStreamingProcessor};
use crate::routers::grpc::{ use crate::routers::{
common::stages::PipelineStage,
context::{FinalResponse, RequestContext, RequestType},
error, error,
grpc::{
common::stages::PipelineStage,
context::{FinalResponse, RequestContext, RequestType},
},
}; };
/// Harmony Response Processing stage: Parse and format Harmony responses /// Harmony Response Processing stage: Parse and format Harmony responses
@@ -5,7 +5,6 @@ use crate::{grpc_client::sglang_proto::MultimodalInputs, protocols::common::Stri
pub mod client; pub mod client;
pub mod common; pub mod common;
pub mod context; pub mod context;
pub mod error;
pub mod harmony; pub mod harmony;
pub mod pd_router; pub mod pd_router;
pub mod pipeline; pub mod pipeline;
@@ -11,7 +11,7 @@ use tracing::error;
use super::{ use super::{
common::stages::*, common::stages::*,
context::*, context::*,
error, harmony, harmony,
regular::{processor, stages::*, streaming}, regular::{processor, stages::*, streaming},
}; };
use crate::{ use crate::{
@@ -22,6 +22,7 @@ use crate::{
generate::GenerateRequest, generate::GenerateRequest,
}, },
reasoning_parser::ParserFactory as ReasoningParserFactory, reasoning_parser::ParserFactory as ReasoningParserFactory,
routers::error,
tokenizer::traits::Tokenizer, tokenizer::traits::Tokenizer,
tool_parser::ParserFactory as ToolParserFactory, tool_parser::ParserFactory as ToolParserFactory,
}; };
@@ -16,12 +16,14 @@ use crate::{
generate::{GenerateMetaInfo, GenerateRequest, GenerateResponse}, generate::{GenerateMetaInfo, GenerateRequest, GenerateResponse},
}, },
reasoning_parser::ParserFactory as ReasoningParserFactory, reasoning_parser::ParserFactory as ReasoningParserFactory,
routers::grpc::{ routers::{
common::{response_collection, response_formatting},
context::{DispatchMetadata, ExecutionResult},
error, error,
proto_wrapper::ProtoGenerateComplete, grpc::{
utils, common::{response_collection, response_formatting},
context::{DispatchMetadata, ExecutionResult},
proto_wrapper::ProtoGenerateComplete,
utils,
},
}, },
tokenizer::{ tokenizer::{
stop::{SequenceDecoderOutput, StopSequenceDecoder}, stop::{SequenceDecoderOutput, StopSequenceDecoder},
@@ -64,12 +64,12 @@ use crate::{
ResponsesUsage, ResponsesUsage,
}, },
}, },
routers::grpc::{ routers::{
common::responses::{ error,
grpc::common::responses::{
build_sse_response, ensure_mcp_connection, persist_response_if_needed, build_sse_response, ensure_mcp_connection, persist_response_if_needed,
streaming::ResponseStreamEventEmitter, streaming::ResponseStreamEventEmitter,
}, },
error,
}, },
}; };
@@ -34,9 +34,9 @@ use crate::{
ResponsesResponse, ResponsesResponse,
}, },
}, },
routers::grpc::{ routers::{
common::responses::streaming::{OutputItemType, ResponseStreamEventEmitter},
error, error,
grpc::common::responses::streaming::{OutputItemType, ResponseStreamEventEmitter},
}, },
}; };
@@ -8,10 +8,13 @@ use tracing::error;
use crate::{ use crate::{
protocols::chat::ChatCompletionRequest, protocols::chat::ChatCompletionRequest,
routers::grpc::{ routers::{
common::stages::PipelineStage, error,
context::{PreparationOutput, RequestContext}, grpc::{
error, utils, common::stages::PipelineStage,
context::{PreparationOutput, RequestContext},
utils,
},
}, },
}; };
@@ -5,12 +5,14 @@ use axum::response::Response;
use tracing::error; use tracing::error;
use uuid::Uuid; use uuid::Uuid;
use crate::routers::grpc::{ use crate::routers::{
client::GrpcClient,
common::stages::{helpers, PipelineStage},
context::{ClientSelection, RequestContext, WorkerSelection},
error, error,
proto_wrapper::ProtoGenerateRequest, grpc::{
client::GrpcClient,
common::stages::{helpers, PipelineStage},
context::{ClientSelection, RequestContext, WorkerSelection},
proto_wrapper::ProtoGenerateRequest,
},
}; };
/// Chat request building stage /// Chat request building stage
@@ -9,11 +9,13 @@ use async_trait::async_trait;
use axum::response::Response; use axum::response::Response;
use tracing::error; use tracing::error;
use crate::routers::grpc::{ use crate::routers::{
common::stages::PipelineStage,
context::{FinalResponse, RequestContext},
error, error,
regular::{processor, streaming}, grpc::{
common::stages::PipelineStage,
context::{FinalResponse, RequestContext},
regular::{processor, streaming},
},
}; };
/// Chat response processing stage /// Chat response processing stage
@@ -8,10 +8,13 @@ use tracing::error;
use crate::{ use crate::{
protocols::{common::InputIds, generate::GenerateRequest}, protocols::{common::InputIds, generate::GenerateRequest},
routers::grpc::{ routers::{
common::stages::PipelineStage, error,
context::{PreparationOutput, RequestContext}, grpc::{
error, utils, common::stages::PipelineStage,
context::{PreparationOutput, RequestContext},
utils,
},
}, },
tokenizer::traits::Tokenizer, tokenizer::traits::Tokenizer,
}; };
@@ -5,12 +5,14 @@ use axum::response::Response;
use tracing::error; use tracing::error;
use uuid::Uuid; use uuid::Uuid;
use crate::routers::grpc::{ use crate::routers::{
client::GrpcClient,
common::stages::{helpers, PipelineStage},
context::{ClientSelection, RequestContext, WorkerSelection},
error, error,
proto_wrapper::ProtoGenerateRequest, grpc::{
client::GrpcClient,
common::stages::{helpers, PipelineStage},
context::{ClientSelection, RequestContext, WorkerSelection},
proto_wrapper::ProtoGenerateRequest,
},
}; };
/// Generate request building stage /// Generate request building stage
@@ -6,11 +6,13 @@ use async_trait::async_trait;
use axum::response::Response; use axum::response::Response;
use tracing::error; use tracing::error;
use crate::routers::grpc::{ use crate::routers::{
common::stages::PipelineStage,
context::{FinalResponse, RequestContext},
error, error,
regular::{processor, streaming}, grpc::{
common::stages::PipelineStage,
context::{FinalResponse, RequestContext},
regular::{processor, streaming},
},
}; };
/// Generate response processing stage /// Generate response processing stage
@@ -8,10 +8,12 @@ use axum::response::Response;
use tracing::error; use tracing::error;
use super::{chat::ChatPreparationStage, generate::GeneratePreparationStage}; use super::{chat::ChatPreparationStage, generate::GeneratePreparationStage};
use crate::routers::grpc::{ use crate::routers::{
common::stages::PipelineStage,
context::{RequestContext, RequestType},
error as grpc_error, error as grpc_error,
grpc::{
common::stages::PipelineStage,
context::{RequestContext, RequestType},
},
}; };
/// Preparation stage (delegates to endpoint-specific implementations) /// Preparation stage (delegates to endpoint-specific implementations)
@@ -5,10 +5,12 @@ use axum::response::Response;
use tracing::error; use tracing::error;
use super::{chat::ChatRequestBuildingStage, generate::GenerateRequestBuildingStage}; use super::{chat::ChatRequestBuildingStage, generate::GenerateRequestBuildingStage};
use crate::routers::grpc::{ use crate::routers::{
common::stages::PipelineStage,
context::{RequestContext, RequestType},
error as grpc_error, error as grpc_error,
grpc::{
common::stages::PipelineStage,
context::{RequestContext, RequestType},
},
}; };
/// Request building stage (delegates to endpoint-specific implementations) /// Request building stage (delegates to endpoint-specific implementations)
@@ -7,11 +7,13 @@ use axum::response::Response;
use tracing::error; use tracing::error;
use super::{chat::ChatResponseProcessingStage, generate::GenerateResponseProcessingStage}; use super::{chat::ChatResponseProcessingStage, generate::GenerateResponseProcessingStage};
use crate::routers::grpc::{ use crate::routers::{
common::stages::PipelineStage,
context::{RequestContext, RequestType},
error, error,
regular::{processor, streaming}, grpc::{
common::stages::PipelineStage,
context::{RequestContext, RequestType},
regular::{processor, streaming},
},
}; };
/// Response processing stage (delegates to endpoint-specific implementations) /// Response processing stage (delegates to endpoint-specific implementations)
+1 -2
View File
@@ -9,7 +9,6 @@ use uuid::Uuid;
use super::{ use super::{
client::GrpcClient, client::GrpcClient,
error,
proto_wrapper::{ProtoGenerateComplete, ProtoStream}, proto_wrapper::{ProtoGenerateComplete, ProtoStream},
ProcessedMessages, ProcessedMessages,
}; };
@@ -28,7 +27,7 @@ use crate::{
ParserFactory as ReasoningParserFactory, PooledParser as ReasoningPooledParser, ParserFactory as ReasoningParserFactory, PooledParser as ReasoningPooledParser,
ReasoningParser, ReasoningParser,
}, },
routers::grpc::proto_wrapper::ProtoResponseVariant, routers::{error, grpc::proto_wrapper::ProtoResponseVariant},
tokenizer::{ tokenizer::{
cache::CachedTokenizer, cache::CachedTokenizer,
chat_template::{ChatTemplateContentFormat, ChatTemplateParams}, chat_template::{ChatTemplateContentFormat, ChatTemplateParams},
+1
View File
@@ -21,6 +21,7 @@ use crate::protocols::{
}; };
pub mod conversations; pub mod conversations;
pub mod error;
pub mod factory; pub mod factory;
pub mod grpc; pub mod grpc;
pub mod header_utils; pub mod header_utils;