mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-11 23:56:53 +00:00
chore(obs): standardize runtime logging batch one (#3438)
This commit is contained in:
@@ -122,6 +122,7 @@ mod tests {
|
||||
use crate::config::{RustFSBufferConfig, WorkloadProfile};
|
||||
use rustfs_ecstore::disk::endpoint::Endpoint;
|
||||
use rustfs_ecstore::endpoints::{Endpoints, PoolEndpoints};
|
||||
use rustfs_ecstore::new_object_layer_fn;
|
||||
use rustfs_ecstore::store::init_local_disks;
|
||||
use rustfs_iam::{store::object::ObjectStore, sys::IamSys};
|
||||
use std::path::PathBuf;
|
||||
@@ -211,6 +212,11 @@ mod tests {
|
||||
}
|
||||
|
||||
async fn test_store() -> (TempDir, Arc<ECStore>, EndpointServerPools) {
|
||||
if let Some(store) = new_object_layer_fn() {
|
||||
let endpoints = EndpointServerPools(store.pools.iter().map(|pool| pool.endpoints.clone()).collect());
|
||||
return (tempfile::tempdir().expect("compat test temp dir"), store, endpoints);
|
||||
}
|
||||
|
||||
let temp_dir = tempfile::tempdir().expect("test temp dir");
|
||||
let disk_paths = (0..4)
|
||||
.map(|index| temp_dir.path().join(format!("disk{index}")))
|
||||
|
||||
+21
-5
@@ -119,13 +119,21 @@ static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
|
||||
#[global_allocator]
|
||||
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
|
||||
|
||||
fn format_fatal_stderr_message(context: &str, error: impl std::fmt::Display) -> String {
|
||||
format!("[FATAL] {context}: {error}")
|
||||
}
|
||||
|
||||
fn emit_fatal_stderr(context: &str, error: impl std::fmt::Display) {
|
||||
eprintln!("{}", format_fatal_stderr_message(context, error));
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Build Tokio runtime with optional dial9 telemetry support
|
||||
let runtime = rustfs::server::build_tokio_runtime().expect("Failed to build Tokio runtime");
|
||||
let result = runtime.block_on(async_main());
|
||||
if let Err(ref e) = result {
|
||||
// Use eprintln as tracing may not be initialized at this point
|
||||
eprintln!("[FATAL] Server encountered an error and is shutting down: {e}");
|
||||
// Tracing may not be initialized when startup fails this early.
|
||||
emit_fatal_stderr("Server runtime failed", e);
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
@@ -158,7 +166,7 @@ async fn async_main() -> Result<()> {
|
||||
let command_result = match rustfs::config::Opt::parse_command(args) {
|
||||
Ok(result) => result,
|
||||
Err(e) => {
|
||||
eprintln!("Command parse failed, error: {}", e);
|
||||
emit_fatal_stderr("Command parse failed", e);
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
@@ -183,8 +191,8 @@ async fn async_main() -> Result<()> {
|
||||
let guard = match init_obs(Some(config.clone().obs_endpoint)).await {
|
||||
Ok(g) => g,
|
||||
Err(e) => {
|
||||
// Use eprintln as tracing is not yet initialized
|
||||
eprintln!("[FATAL] Failed to initialize observability: {e}");
|
||||
// Structured logging is unavailable until observability initializes.
|
||||
emit_fatal_stderr("Observability initialization failed", &e);
|
||||
return Err(Error::other(e));
|
||||
}
|
||||
};
|
||||
@@ -1284,6 +1292,14 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fatal_stderr_message_uses_consistent_prefix_and_context() {
|
||||
assert_eq!(
|
||||
format_fatal_stderr_message("Observability initialization failed", "collector unavailable"),
|
||||
"[FATAL] Observability initialization failed: collector unavailable"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_using_default_credentials_returns_true_for_default_keys() {
|
||||
let mut config = rustfs::config::Config::new("127.0.0.1:9000", Vec::new());
|
||||
|
||||
Reference in New Issue
Block a user