mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-27 15:37:02 +00:00
improve code for observability
This commit is contained in:
Generated
+1
@@ -5633,6 +5633,7 @@ dependencies = [
|
|||||||
"mime",
|
"mime",
|
||||||
"mime_guess",
|
"mime_guess",
|
||||||
"netif",
|
"netif",
|
||||||
|
"once_cell",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"prost",
|
"prost",
|
||||||
"prost-build",
|
"prost-build",
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ lazy_static = "1.5.0"
|
|||||||
local-ip-address = "0.6.3"
|
local-ip-address = "0.6.3"
|
||||||
mime = "0.3.17"
|
mime = "0.3.17"
|
||||||
netif = "0.1.6"
|
netif = "0.1.6"
|
||||||
|
once_cell = "1.21.1"
|
||||||
opentelemetry = { version = "0.28" }
|
opentelemetry = { version = "0.28" }
|
||||||
opentelemetry-appender-tracing = { version = "0.28.1", features = ["experimental_use_tracing_span_context", "experimental_metadata_attributes"] }
|
opentelemetry-appender-tracing = { version = "0.28.1", features = ["experimental_use_tracing_span_context", "experimental_metadata_attributes"] }
|
||||||
opentelemetry_sdk = { version = "0.28" }
|
opentelemetry_sdk = { version = "0.28" }
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[observability]
|
[observability]
|
||||||
endpoint = "http://localhost:4317"
|
endpoint = "http://localhost:4317"
|
||||||
use_stdout = false
|
use_stdout = true
|
||||||
sample_ratio = 0.5
|
sample_ratio = 0.5
|
||||||
meter_interval = 30
|
meter_interval = 30
|
||||||
service_name = "rustfs_obs_service"
|
service_name = "rustfs_obs_service"
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use opentelemetry::global;
|
use opentelemetry::global;
|
||||||
use rustfs_obs::{get_logger, init_obs, load_config, log_info, ServerLogEntry};
|
use rustfs_obs::{get_logger, init_obs, load_config, log_info, BaseLogEntry, ServerLogEntry};
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::time::{Duration, SystemTime};
|
use std::time::{Duration, SystemTime};
|
||||||
use tracing::{info, instrument};
|
use tracing::{info, instrument};
|
||||||
use tracing_core::Level;
|
use tracing_core::Level;
|
||||||
@@ -34,7 +35,14 @@ async fn run(bucket: String, object: String, user: String, service_name: String)
|
|||||||
&[opentelemetry::KeyValue::new("operation", "run")],
|
&[opentelemetry::KeyValue::new("operation", "run")],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let base_entry = BaseLogEntry::new()
|
||||||
|
.message(Some("run logger api_handler info".to_string()))
|
||||||
|
.request_id(Some("request_id".to_string()))
|
||||||
|
.timestamp(chrono::DateTime::from(start_time))
|
||||||
|
.tags(Some(HashMap::default()));
|
||||||
|
|
||||||
let server_entry = ServerLogEntry::new(Level::INFO, "api_handler".to_string())
|
let server_entry = ServerLogEntry::new(Level::INFO, "api_handler".to_string())
|
||||||
|
.with_base(base_entry)
|
||||||
.user_id(Some(user.clone()))
|
.user_id(Some(user.clone()))
|
||||||
.add_field("operation".to_string(), "login".to_string())
|
.add_field("operation".to_string(), "login".to_string())
|
||||||
.add_field("bucket".to_string(), bucket.clone())
|
.add_field("bucket".to_string(), bucket.clone())
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ http-body.workspace = true
|
|||||||
lock.workspace = true
|
lock.workspace = true
|
||||||
mime.workspace = true
|
mime.workspace = true
|
||||||
netif.workspace = true
|
netif.workspace = true
|
||||||
|
once_cell.workspace = true
|
||||||
pin-project-lite.workspace = true
|
pin-project-lite.workspace = true
|
||||||
prost.workspace = true
|
prost.workspace = true
|
||||||
prost-types.workspace = true
|
prost-types.workspace = true
|
||||||
|
|||||||
+24
-7
@@ -34,6 +34,7 @@ use hyper_util::{
|
|||||||
service::TowerToHyperService,
|
service::TowerToHyperService,
|
||||||
};
|
};
|
||||||
use iam::init_iam_sys;
|
use iam::init_iam_sys;
|
||||||
|
use once_cell::sync::OnceCell;
|
||||||
use protos::proto_gen::node_service::node_service_server::NodeServiceServer;
|
use protos::proto_gen::node_service::node_service_server::NodeServiceServer;
|
||||||
use rustfs_obs::{init_obs, load_config};
|
use rustfs_obs::{init_obs, load_config};
|
||||||
use s3s::{host::MultiDomain, service::S3ServiceBuilder};
|
use s3s::{host::MultiDomain, service::S3ServiceBuilder};
|
||||||
@@ -46,6 +47,20 @@ use tracing::{debug, error, info, warn};
|
|||||||
use tracing_error::ErrorLayer;
|
use tracing_error::ErrorLayer;
|
||||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||||
|
|
||||||
|
/// Guard that holds a reference to the global observability subsystem.
|
||||||
|
/// This struct ensures that tracing/logging components remain alive for the
|
||||||
|
/// application's lifetime. The underlying guard is dropped when this struct
|
||||||
|
/// is dropped, which may flush logs or perform cleanup operations.
|
||||||
|
#[allow(dead_code)]
|
||||||
|
struct TracingGuard(Box<dyn std::any::Any + Send + Sync>);
|
||||||
|
|
||||||
|
impl Drop for TracingGuard {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
debug!("Dropping global tracing guard, flushing logs");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static GLOBAL_GUARD: OnceCell<TracingGuard> = OnceCell::new();
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn setup_tracing() {
|
fn setup_tracing() {
|
||||||
use tracing_subscriber::EnvFilter;
|
use tracing_subscriber::EnvFilter;
|
||||||
@@ -87,26 +102,28 @@ fn print_server_info() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
//解析获得到的参数
|
// Parse the obtained parameters
|
||||||
let opt = config::Opt::parse();
|
let opt = config::Opt::parse();
|
||||||
|
|
||||||
//设置 trace
|
// 设置 trace
|
||||||
// setup_tracing();
|
// setup_tracing();
|
||||||
|
|
||||||
let config = load_config(Some(opt.clone().obs_config));
|
let config = load_config(Some(opt.clone().obs_config));
|
||||||
// Initialize Observability
|
// Initialize Observability
|
||||||
let (_logger, _guard) = tokio::runtime::Runtime::new()?.block_on(async { init_obs(config).await });
|
let (_logger, guard) = tokio::runtime::Runtime::new()?.block_on(async { init_obs(config).await });
|
||||||
|
|
||||||
//运行参数
|
// Pack and store the guard
|
||||||
|
GLOBAL_GUARD.set(TracingGuard(Box::new(guard))).unwrap_or_else(|_| {
|
||||||
|
error!("Unable to set global tracing guard");
|
||||||
|
});
|
||||||
|
|
||||||
|
// Run parameters
|
||||||
run(opt)
|
run(opt)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn run(opt: config::Opt) -> Result<()> {
|
async fn run(opt: config::Opt) -> Result<()> {
|
||||||
debug!("opt: {:?}", &opt);
|
debug!("opt: {:?}", &opt);
|
||||||
// let config = load_config(Some(opt.clone().obs_config));
|
|
||||||
// Initialize Observability
|
|
||||||
// let (_logger, _guard) = init_obs(config).await;
|
|
||||||
|
|
||||||
let mut server_addr = net::check_local_server_addr(opt.address.as_str()).unwrap();
|
let mut server_addr = net::check_local_server_addr(opt.address.as_str()).unwrap();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user