From cf2ed47fe882fdac6f12e35a2a863d9b89f84172 Mon Sep 17 00:00:00 2001 From: weisd Date: Wed, 23 Apr 2025 16:34:39 +0800 Subject: [PATCH] fix: #331 admin info version,uptime --- Cargo.lock | 1 + ecstore/Cargo.toml | 4 ++++ ecstore/build.rs | 4 ++++ ecstore/src/admin_server_info.rs | 25 ++++++++++++++++++++++--- ecstore/src/global.rs | 4 +++- ecstore/src/notification_sys.rs | 9 ++++++++- ecstore/src/store.rs | 5 ++++- 7 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 ecstore/build.rs diff --git a/Cargo.lock b/Cargo.lock index f69232ec..447d8070 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3090,6 +3090,7 @@ dependencies = [ "serde", "serde_json", "sha2 0.11.0-pre.5", + "shadow-rs", "siphasher 1.0.1", "smallvec", "tempfile", diff --git a/ecstore/Cargo.toml b/ecstore/Cargo.toml index 13c8edc5..c0d5c933 100644 --- a/ecstore/Cargo.toml +++ b/ecstore/Cargo.toml @@ -69,6 +69,7 @@ workers.workspace = true reqwest = { workspace = true } urlencoding = "2.1.3" smallvec = "1.15.0" +shadow-rs.workspace = true [target.'cfg(not(windows))'.dependencies] @@ -81,3 +82,6 @@ winapi = "0.3.9" [dev-dependencies] tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } + +[build-dependencies] +shadow-rs.workspace = true diff --git a/ecstore/build.rs b/ecstore/build.rs new file mode 100644 index 00000000..7969b782 --- /dev/null +++ b/ecstore/build.rs @@ -0,0 +1,4 @@ +fn main() -> shadow_rs::SdResult<()> { + shadow_rs::ShadowBuilder::builder().build()?; + Ok(()) +} diff --git a/ecstore/src/admin_server_info.rs b/ecstore/src/admin_server_info.rs index 696ab391..ef07aa54 100644 --- a/ecstore/src/admin_server_info.rs +++ b/ecstore/src/admin_server_info.rs @@ -1,6 +1,6 @@ use crate::{ disk::endpoint::Endpoint, - global::GLOBAL_Endpoints, + global::{GLOBAL_Endpoints, GLOBAL_BOOT_TIME}, heal::{ data_usage::{load_data_usage_from_backend, DATA_USAGE_CACHE_NAME, DATA_USAGE_ROOT}, data_usage_cache::DataUsageCache, @@ -22,12 +22,16 @@ use protos::{ }; use std::{ collections::{HashMap, HashSet}, - time::{SystemTime, UNIX_EPOCH}, + time::SystemTime, }; use time::OffsetDateTime; use tonic::Request; use tracing::warn; +use shadow_rs::shadow; + +shadow!(build); + // pub const ITEM_OFFLINE: &str = "offline"; // pub const ITEM_INITIALIZING: &str = "initializing"; // pub const ITEM_ONLINE: &str = "online"; @@ -140,8 +144,12 @@ pub async fn get_local_server_property() -> ServerProperties { let mut props = ServerProperties { endpoint: addr, - uptime: SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs(), + uptime: SystemTime::now() + .duration_since(*GLOBAL_BOOT_TIME.get().unwrap()) + .unwrap_or_default() + .as_secs(), network, + version: get_commit_id(), ..Default::default() }; @@ -356,3 +364,14 @@ async fn get_pools_info(all_disks: &[Disk]) -> Result String { + if !build::TAG.is_empty() { + build::TAG.to_string() + } else if !build::SHORT_COMMIT.is_empty() { + format!("@{}", build::SHORT_COMMIT) + } else { + build::PKG_VERSION.to_string() + } +} diff --git a/ecstore/src/global.rs b/ecstore/src/global.rs index f6fc4bdb..162aa9d3 100644 --- a/ecstore/src/global.rs +++ b/ecstore/src/global.rs @@ -2,8 +2,9 @@ use lazy_static::lazy_static; use std::{ collections::HashMap, sync::{Arc, OnceLock}, + time::SystemTime, }; -use tokio::sync::RwLock; +use tokio::sync::{OnceCell, RwLock}; use uuid::Uuid; use crate::heal::mrf::MRFState; @@ -37,6 +38,7 @@ lazy_static! { pub static ref GLOBAL_ALlHealState: Arc = AllHealState::new(false); pub static ref GLOBAL_MRFState: Arc = Arc::new(MRFState::new()); static ref globalDeploymentIDPtr: OnceLock = OnceLock::new(); + pub static ref GLOBAL_BOOT_TIME: OnceCell = OnceCell::new(); } pub fn global_rustfs_port() -> u16 { diff --git a/ecstore/src/notification_sys.rs b/ecstore/src/notification_sys.rs index 8bc810fd..d364cc28 100644 --- a/ecstore/src/notification_sys.rs +++ b/ecstore/src/notification_sys.rs @@ -1,4 +1,5 @@ -use crate::global::get_global_endpoints; +use crate::admin_server_info::get_commit_id; +use crate::global::{get_global_endpoints, GLOBAL_BOOT_TIME}; use crate::peer_rest_client::PeerRestClient; use crate::StorageAPI; use crate::{endpoints::EndpointServerPools, new_object_layer_fn}; @@ -7,6 +8,7 @@ use futures::future::join_all; use lazy_static::lazy_static; use madmin::{ItemState, ServerProperties}; use std::sync::OnceLock; +use std::time::SystemTime; use tracing::error; lazy_static! { @@ -104,6 +106,11 @@ impl NotificationSys { match client.server_info().await { Ok(info) => info, Err(_) => ServerProperties { + uptime: SystemTime::now() + .duration_since(*GLOBAL_BOOT_TIME.get().unwrap()) + .unwrap_or_default() + .as_secs(), + version: get_commit_id(), endpoint: client.host.to_string(), state: ItemState::Offline.to_string().to_owned(), disks: get_offline_disks(&client.host.to_string(), &get_global_endpoints()), diff --git a/ecstore/src/store.rs b/ecstore/src/store.rs index 5be291b1..4a7e06ec 100644 --- a/ecstore/src/store.rs +++ b/ecstore/src/store.rs @@ -9,7 +9,8 @@ use crate::disk::{DiskAPI, DiskInfo, DiskInfoOptions, MetaCacheEntry}; use crate::error::clone_err; use crate::global::{ get_global_endpoints, is_dist_erasure, is_erasure_sd, set_global_deployment_id, set_object_layer, DISK_ASSUME_UNKNOWN_SIZE, - DISK_FILL_FRACTION, DISK_MIN_INODES, DISK_RESERVE_FRACTION, GLOBAL_LOCAL_DISK_MAP, GLOBAL_LOCAL_DISK_SET_DRIVES, + DISK_FILL_FRACTION, DISK_MIN_INODES, DISK_RESERVE_FRACTION, GLOBAL_BOOT_TIME, GLOBAL_LOCAL_DISK_MAP, + GLOBAL_LOCAL_DISK_SET_DRIVES, }; use crate::heal::data_usage::{DataUsageInfo, DATA_USAGE_ROOT}; use crate::heal::data_usage_cache::{DataUsageCache, DataUsageCacheInfo}; @@ -257,6 +258,8 @@ impl ECStore { } pub async fn init(self: &Arc) -> Result<()> { + GLOBAL_BOOT_TIME.get_or_init(|| async { SystemTime::now() }).await; + if self.load_rebalance_meta().await.is_ok() { self.start_rebalance().await; }