diff --git a/sgl-model-gateway/bindings/python/src/lib.rs b/sgl-model-gateway/bindings/python/src/lib.rs index 9181abb252b5..67082a618031 100644 --- a/sgl-model-gateway/bindings/python/src/lib.rs +++ b/sgl-model-gateway/bindings/python/src/lib.rs @@ -659,7 +659,7 @@ impl Router { } fn start(&self) -> PyResult<()> { - use metrics::PrometheusConfig; + use observability::metrics::PrometheusConfig; let router_config = self.to_router_config().map_err(|e| { pyo3::exceptions::PyValueError::new_err(format!("Configuration error: {}", e)) diff --git a/sgl-model-gateway/src/core/job_queue.rs b/sgl-model-gateway/src/core/job_queue.rs index 8d9f9a65613d..68c633fe72c1 100644 --- a/sgl-model-gateway/src/core/job_queue.rs +++ b/sgl-model-gateway/src/core/job_queue.rs @@ -24,7 +24,7 @@ use crate::{ WorkflowContext, WorkflowEngine, WorkflowId, WorkflowInstanceId, WorkflowStatus, }, mcp::McpConfig, - metrics::RouterMetrics, + observability::metrics::RouterMetrics, protocols::worker_spec::{JobStatus, WorkerConfigRequest}, }; diff --git a/sgl-model-gateway/src/core/worker.rs b/sgl-model-gateway/src/core/worker.rs index 697d21a951cd..05307428605c 100644 --- a/sgl-model-gateway/src/core/worker.rs +++ b/sgl-model-gateway/src/core/worker.rs @@ -17,7 +17,7 @@ use super::{ }; use crate::{ core::{BasicWorkerBuilder, CircuitState, DPAwareWorkerBuilder}, - metrics::RouterMetrics, + observability::metrics::RouterMetrics, protocols::worker_spec::WorkerInfo, routers::grpc::client::GrpcClient, }; diff --git a/sgl-model-gateway/src/lib.rs b/sgl-model-gateway/src/lib.rs index 8d1144dce1ea..91b02976c839 100644 --- a/sgl-model-gateway/src/lib.rs +++ b/sgl-model-gateway/src/lib.rs @@ -1,15 +1,12 @@ pub mod app_context; pub mod config; -pub mod logging; - pub mod core; pub mod data_connector; pub mod grpc_client; pub mod mcp; -pub mod metrics; pub mod middleware; pub mod multimodal; -pub mod otel_trace; +pub mod observability; pub mod policies; pub mod protocols; pub mod reasoning_parser; diff --git a/sgl-model-gateway/src/main.rs b/sgl-model-gateway/src/main.rs index 97f24f711c8a..a6689907085f 100644 --- a/sgl-model-gateway/src/main.rs +++ b/sgl-model-gateway/src/main.rs @@ -8,8 +8,10 @@ use sgl_model_gateway::{ RouterConfig, RoutingMode, TokenizerCacheConfig, TraceConfig, }, core::ConnectionMode, - metrics::PrometheusConfig, - otel_trace::{is_otel_enabled, shutdown_otel}, + observability::{ + metrics::PrometheusConfig, + otel_trace::{is_otel_enabled, shutdown_otel}, + }, server::{self, ServerConfig}, service_discovery::ServiceDiscoveryConfig, version, diff --git a/sgl-model-gateway/src/middleware.rs b/sgl-model-gateway/src/middleware.rs index 7ea623c032b5..5cd188d7ec01 100644 --- a/sgl-model-gateway/src/middleware.rs +++ b/sgl-model-gateway/src/middleware.rs @@ -22,7 +22,7 @@ use tracing::{debug, error, field::Empty, info, info_span, warn, Span}; pub use crate::core::token_bucket::TokenBucket; use crate::{ - metrics::RouterMetrics, + observability::metrics::RouterMetrics, server::AppState, wasm::{ module::{MiddlewareAttachPoint, WasmModuleAttachPoint}, diff --git a/sgl-model-gateway/src/routers/http/events.rs b/sgl-model-gateway/src/observability/events.rs similarity index 96% rename from sgl-model-gateway/src/routers/http/events.rs rename to sgl-model-gateway/src/observability/events.rs index 096c49a754ad..fc537c3a99da 100644 --- a/sgl-model-gateway/src/routers/http/events.rs +++ b/sgl-model-gateway/src/observability/events.rs @@ -2,7 +2,7 @@ use tracing::{debug, event, Level}; -use crate::otel_trace::is_otel_enabled; +use crate::observability::otel_trace::is_otel_enabled; pub fn get_module_path() -> &'static str { module_path!() diff --git a/sgl-model-gateway/src/logging.rs b/sgl-model-gateway/src/observability/logging.rs similarity index 98% rename from sgl-model-gateway/src/logging.rs rename to sgl-model-gateway/src/observability/logging.rs index fa8e57157b31..4c8afb401a37 100644 --- a/sgl-model-gateway/src/logging.rs +++ b/sgl-model-gateway/src/observability/logging.rs @@ -10,7 +10,8 @@ use tracing_subscriber::{ fmt::time::ChronoUtc, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Layer, }; -use crate::{config::TraceConfig, otel_trace::get_otel_layer}; +use super::otel_trace::get_otel_layer; +use crate::config::TraceConfig; #[derive(Debug, Clone)] pub struct LoggingConfig { diff --git a/sgl-model-gateway/src/metrics.rs b/sgl-model-gateway/src/observability/metrics.rs similarity index 100% rename from sgl-model-gateway/src/metrics.rs rename to sgl-model-gateway/src/observability/metrics.rs diff --git a/sgl-model-gateway/src/observability/mod.rs b/sgl-model-gateway/src/observability/mod.rs new file mode 100644 index 000000000000..8a8f436d540d --- /dev/null +++ b/sgl-model-gateway/src/observability/mod.rs @@ -0,0 +1,6 @@ +//! Observability utilities for logging, metrics, and tracing. + +pub mod events; +pub mod logging; +pub mod metrics; +pub mod otel_trace; diff --git a/sgl-model-gateway/src/otel_trace.rs b/sgl-model-gateway/src/observability/otel_trace.rs similarity index 98% rename from sgl-model-gateway/src/otel_trace.rs rename to sgl-model-gateway/src/observability/otel_trace.rs index 6043d80c7dad..ea91e267449f 100644 --- a/sgl-model-gateway/src/otel_trace.rs +++ b/sgl-model-gateway/src/observability/otel_trace.rs @@ -25,7 +25,7 @@ use tracing_subscriber::{ Layer, }; -use crate::routers::http::events::get_module_path as http_router_get_module_path; +use super::events::get_module_path as http_router_get_module_path; static ENABLED: AtomicBool = AtomicBool::new(false); diff --git a/sgl-model-gateway/src/policies/cache_aware.rs b/sgl-model-gateway/src/policies/cache_aware.rs index c43d34ed8acb..0d6c31234fba 100644 --- a/sgl-model-gateway/src/policies/cache_aware.rs +++ b/sgl-model-gateway/src/policies/cache_aware.rs @@ -66,7 +66,7 @@ use rand::Rng; use tracing::debug; use super::{get_healthy_worker_indices, tree::Tree, CacheAwareConfig, LoadBalancingPolicy}; -use crate::{core::Worker, metrics::RouterMetrics}; +use crate::{core::Worker, observability::metrics::RouterMetrics}; /// Cache-aware routing policy /// diff --git a/sgl-model-gateway/src/policies/power_of_two.rs b/sgl-model-gateway/src/policies/power_of_two.rs index b7edef82273e..851c83cb15bb 100644 --- a/sgl-model-gateway/src/policies/power_of_two.rs +++ b/sgl-model-gateway/src/policies/power_of_two.rs @@ -9,7 +9,7 @@ use rand::Rng; use tracing::info; use super::{get_healthy_worker_indices, LoadBalancingPolicy}; -use crate::{core::Worker, metrics::RouterMetrics}; +use crate::{core::Worker, observability::metrics::RouterMetrics}; /// Power-of-two choices policy /// diff --git a/sgl-model-gateway/src/policies/random.rs b/sgl-model-gateway/src/policies/random.rs index 5b92b2d738db..e316f95c7424 100644 --- a/sgl-model-gateway/src/policies/random.rs +++ b/sgl-model-gateway/src/policies/random.rs @@ -5,7 +5,7 @@ use std::sync::Arc; use rand::Rng; use super::{get_healthy_worker_indices, LoadBalancingPolicy}; -use crate::{core::Worker, metrics::RouterMetrics}; +use crate::{core::Worker, observability::metrics::RouterMetrics}; /// Random selection policy /// diff --git a/sgl-model-gateway/src/policies/round_robin.rs b/sgl-model-gateway/src/policies/round_robin.rs index 5b0776253cfb..1c50884f5a84 100644 --- a/sgl-model-gateway/src/policies/round_robin.rs +++ b/sgl-model-gateway/src/policies/round_robin.rs @@ -6,7 +6,7 @@ use std::sync::{ }; use super::{get_healthy_worker_indices, LoadBalancingPolicy}; -use crate::{core::Worker, metrics::RouterMetrics}; +use crate::{core::Worker, observability::metrics::RouterMetrics}; /// Round-robin selection policy /// diff --git a/sgl-model-gateway/src/routers/http/mod.rs b/sgl-model-gateway/src/routers/http/mod.rs index 5beafc8d1315..3f31b6f86964 100644 --- a/sgl-model-gateway/src/routers/http/mod.rs +++ b/sgl-model-gateway/src/routers/http/mod.rs @@ -1,6 +1,5 @@ //! HTTP router implementations -pub mod events; pub mod pd_router; pub mod pd_types; pub mod router; diff --git a/sgl-model-gateway/src/routers/http/pd_router.rs b/sgl-model-gateway/src/routers/http/pd_router.rs index 98d464c8537f..94b620babdb9 100644 --- a/sgl-model-gateway/src/routers/http/pd_router.rs +++ b/sgl-model-gateway/src/routers/http/pd_router.rs @@ -14,17 +14,17 @@ use serde_json::{json, Value}; use tokio_stream::wrappers::UnboundedReceiverStream; use tracing::{debug, error, warn}; -use super::{ - events::{self, Event}, - pd_types::api_path, -}; +use super::pd_types::api_path; use crate::{ config::types::RetryConfig, core::{ is_retryable_status, RetryExecutor, Worker, WorkerLoadGuard, WorkerRegistry, WorkerType, }, - metrics::RouterMetrics, - otel_trace::inject_trace_context_http, + observability::{ + events::{self, Event}, + metrics::RouterMetrics, + otel_trace::inject_trace_context_http, + }, policies::{LoadBalancingPolicy, PolicyRegistry}, protocols::{ chat::{ChatCompletionRequest, ChatMessage, MessageContent}, diff --git a/sgl-model-gateway/src/routers/http/router.rs b/sgl-model-gateway/src/routers/http/router.rs index d7ca65b10a9e..a5614fa5acc2 100644 --- a/sgl-model-gateway/src/routers/http/router.rs +++ b/sgl-model-gateway/src/routers/http/router.rs @@ -15,14 +15,16 @@ use reqwest::Client; use tokio_stream::wrappers::UnboundedReceiverStream; use tracing::{debug, error}; -use super::events::{self, Event}; use crate::{ config::types::RetryConfig, core::{ is_retryable_status, ConnectionMode, RetryExecutor, Worker, WorkerRegistry, WorkerType, }, - metrics::RouterMetrics, - otel_trace::inject_trace_context_http, + observability::{ + events::{self, Event}, + metrics::RouterMetrics, + otel_trace::inject_trace_context_http, + }, policies::PolicyRegistry, protocols::{ chat::ChatCompletionRequest, diff --git a/sgl-model-gateway/src/server.rs b/sgl-model-gateway/src/server.rs index dde36f5a3313..f3dd82b3278d 100644 --- a/sgl-model-gateway/src/server.rs +++ b/sgl-model-gateway/src/server.rs @@ -32,10 +32,12 @@ use crate::{ }, Job, JobQueue, JobQueueConfig, WorkerManager, WorkerType, }, - logging::{self, LoggingConfig}, - metrics::{self, PrometheusConfig}, middleware::{self, AuthConfig, QueuedRequest}, - otel_trace, + observability::{ + logging::{self, LoggingConfig}, + metrics::{self, PrometheusConfig}, + otel_trace, + }, protocols::{ chat::ChatCompletionRequest, classify::ClassifyRequest, diff --git a/sgl-model-gateway/tests/otel_tracing_test.rs b/sgl-model-gateway/tests/otel_tracing_test.rs index 8453aebea82a..fc2c165906e1 100644 --- a/sgl-model-gateway/tests/otel_tracing_test.rs +++ b/sgl-model-gateway/tests/otel_tracing_test.rs @@ -20,7 +20,7 @@ use serial_test::serial; use sgl_model_gateway::{ config::{RouterConfig, TraceConfig}, core::Job, - logging, otel_trace, + observability::{logging, otel_trace}, routers::RouterFactory, }; use tokio::sync::oneshot;