From d081198a0e4d286b88724e32035e096638f09bc4 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 6 Mar 2026 15:49:12 -0800 Subject: [PATCH] Convert to lib+bin crate and fix axum route parameter syntax for 0.7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds lib.rs re-exporting all public modules for integration test access. Refactors main.rs to import from seaweed_volume:: lib crate. Fixes route parameter syntax from {path} (axum 0.8) to :path (axum 0.7) — the old brace syntax silently failed to match requests. --- seaweed-volume/src/lib.rs | 18 ++++++++++ seaweed-volume/src/main.rs | 40 +++++++--------------- seaweed-volume/src/server/volume_server.rs | 13 +++---- 3 files changed, 38 insertions(+), 33 deletions(-) create mode 100644 seaweed-volume/src/lib.rs diff --git a/seaweed-volume/src/lib.rs b/seaweed-volume/src/lib.rs new file mode 100644 index 000000000..462c01336 --- /dev/null +++ b/seaweed-volume/src/lib.rs @@ -0,0 +1,18 @@ +pub mod config; +pub mod storage; +pub mod security; +pub mod server; +pub mod metrics; + +/// Generated protobuf modules. +pub mod pb { + pub mod remote_pb { + tonic::include_proto!("remote_pb"); + } + pub mod volume_server_pb { + tonic::include_proto!("volume_server_pb"); + } + pub mod master_pb { + tonic::include_proto!("master_pb"); + } +} diff --git a/seaweed-volume/src/main.rs b/seaweed-volume/src/main.rs index 6a0d58c0d..5a4e25b0a 100644 --- a/seaweed-volume/src/main.rs +++ b/seaweed-volume/src/main.rs @@ -1,32 +1,15 @@ -mod config; -mod storage; -mod security; -mod server; - -/// Generated protobuf modules. -pub mod pb { - pub mod remote_pb { - tonic::include_proto!("remote_pb"); - } - pub mod volume_server_pb { - tonic::include_proto!("volume_server_pb"); - } - pub mod master_pb { - tonic::include_proto!("master_pb"); - } -} - use std::sync::{Arc, RwLock}; use tracing::{info, error}; -use crate::config::VolumeServerConfig; -use crate::security::{Guard, SigningKey}; -use crate::server::grpc_server::VolumeGrpcService; -use crate::server::volume_server::VolumeServerState; -use crate::storage::store::Store; -use crate::storage::types::DiskType; -use crate::pb::volume_server_pb::volume_server_server::VolumeServerServer; +use seaweed_volume::config::{self, VolumeServerConfig}; +use seaweed_volume::metrics; +use seaweed_volume::security::{Guard, SigningKey}; +use seaweed_volume::server::grpc_server::VolumeGrpcService; +use seaweed_volume::server::volume_server::VolumeServerState; +use seaweed_volume::storage::store::Store; +use seaweed_volume::storage::types::DiskType; +use seaweed_volume::pb::volume_server_pb::volume_server_server::VolumeServerServer; fn main() { // Initialize tracing @@ -40,6 +23,9 @@ fn main() { let config = config::parse_cli(); info!("SeaweedFS Volume Server (Rust) v{}", env!("CARGO_PKG_VERSION")); + // Register Prometheus metrics + metrics::register_metrics(); + // Build the tokio runtime and run the async entry point let rt = tokio::runtime::Builder::new_multi_thread() .enable_all() @@ -94,7 +80,7 @@ async fn run(config: VolumeServerConfig) { }); // Build HTTP routers - let admin_router = server::volume_server::build_admin_router(state.clone()); + let admin_router = seaweed_volume::server::volume_server::build_admin_router(state.clone()); let admin_addr = format!("{}:{}", config.bind_ip, config.port); let public_port = config.public_port; @@ -160,7 +146,7 @@ async fn run(config: VolumeServerConfig) { }); let public_handle = if needs_public { - let public_router = server::volume_server::build_public_router(state.clone()); + let public_router = seaweed_volume::server::volume_server::build_public_router(state.clone()); let public_addr = format!("{}:{}", config.bind_ip, public_port); let listener = tokio::net::TcpListener::bind(&public_addr) .await diff --git a/seaweed-volume/src/server/volume_server.rs b/seaweed-volume/src/server/volume_server.rs index faebe2fcb..5bdafc491 100644 --- a/seaweed-volume/src/server/volume_server.rs +++ b/seaweed-volume/src/server/volume_server.rs @@ -30,9 +30,10 @@ pub fn build_admin_router(state: Arc) -> Router { Router::new() .route("/status", get(handlers::status_handler)) .route("/healthz", get(handlers::healthz_handler)) + .route("/metrics", get(handlers::metrics_handler)) // Volume operations: GET/HEAD/POST/PUT/DELETE on /{vid},{fid} .route( - "/{path}", + "/:path", get(handlers::get_or_head_handler) .head(handlers::get_or_head_handler) .post(handlers::post_handler) @@ -41,7 +42,7 @@ pub fn build_admin_router(state: Arc) -> Router { ) // Also support /{vid}/{fid} and /{vid}/{fid}/{filename} paths .route( - "/{vid}/{fid}", + "/:vid/:fid", get(handlers::get_or_head_handler) .head(handlers::get_or_head_handler) .post(handlers::post_handler) @@ -49,7 +50,7 @@ pub fn build_admin_router(state: Arc) -> Router { .delete(handlers::delete_handler), ) .route( - "/{vid}/{fid}/{filename}", + "/:vid/:fid/:filename", get(handlers::get_or_head_handler) .head(handlers::get_or_head_handler), ) @@ -61,17 +62,17 @@ pub fn build_public_router(state: Arc) -> Router { Router::new() .route("/healthz", get(handlers::healthz_handler)) .route( - "/{path}", + "/:path", get(handlers::get_or_head_handler) .head(handlers::get_or_head_handler), ) .route( - "/{vid}/{fid}", + "/:vid/:fid", get(handlers::get_or_head_handler) .head(handlers::get_or_head_handler), ) .route( - "/{vid}/{fid}/{filename}", + "/:vid/:fid/:filename", get(handlers::get_or_head_handler) .head(handlers::get_or_head_handler), )