mirror of
https://github.com/rustfs/rustfs.git
synced 2026-09-04 11:15:39 +00:00
modify logger level from info to error (#744)
* modify logger level from `info` to `error` * fix test * improve tokio runtime config * add rustfs helm chart files (#747) * add rustfs helm chart files * update readme file with helm chart * delete helm chart license file * fix typo in readme file * fix: restore localized samples in tests (#749) * fix: restore required localized examples * style: fix formatting issues * improve code for Observability * upgrade crates version * fix * up * fix --------- Co-authored-by: majinghe <42570491+majinghe@users.noreply.github.com> Co-authored-by: 安正超 <anzhengchao@gmail.com>
This commit is contained in:
+34
-39
@@ -12,10 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use crate::AppConfig;
|
||||
use crate::telemetry::{OtelGuard, init_telemetry};
|
||||
use opentelemetry::metrics::Meter;
|
||||
use rustfs_config::APP_NAME;
|
||||
use crate::{AppConfig, SystemObserver};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use tokio::sync::{OnceCell, SetError};
|
||||
use tracing::{error, info};
|
||||
@@ -26,20 +24,11 @@ static GLOBAL_GUARD: OnceCell<Arc<Mutex<OtelGuard>>> = OnceCell::const_new();
|
||||
/// Flag indicating if observability is enabled
|
||||
pub(crate) static IS_OBSERVABILITY_ENABLED: OnceCell<bool> = OnceCell::const_new();
|
||||
|
||||
/// Name of the observability meter
|
||||
pub(crate) static OBSERVABILITY_METER_NAME: OnceCell<String> = OnceCell::const_new();
|
||||
|
||||
/// Check whether Observability is enabled
|
||||
pub fn is_observability_enabled() -> bool {
|
||||
IS_OBSERVABILITY_ENABLED.get().copied().unwrap_or(false)
|
||||
}
|
||||
|
||||
/// Get the global meter for observability
|
||||
pub fn global_meter() -> Meter {
|
||||
let meter_name = OBSERVABILITY_METER_NAME.get().map(|s| s.as_str()).unwrap_or(APP_NAME);
|
||||
opentelemetry::global::meter(meter_name)
|
||||
}
|
||||
|
||||
/// Error type for global guard operations
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum GlobalError {
|
||||
@@ -75,18 +64,33 @@ pub enum GlobalError {
|
||||
///
|
||||
/// # Example
|
||||
/// ```no_run
|
||||
/// use rustfs_obs::init_obs;
|
||||
/// # use rustfs_obs::init_obs;
|
||||
///
|
||||
/// # #[tokio::main]
|
||||
/// # async fn main() {
|
||||
/// let guard = init_obs(None).await;
|
||||
/// # let guard = init_obs(None).await;
|
||||
/// # }
|
||||
/// ```
|
||||
pub async fn init_obs(endpoint: Option<String>) -> OtelGuard {
|
||||
// Load the configuration file
|
||||
let config = AppConfig::new_with_endpoint(endpoint);
|
||||
|
||||
init_telemetry(&config.observability)
|
||||
let otel_guard = init_telemetry(&config.observability);
|
||||
// Server will be created per connection - this ensures isolation
|
||||
tokio::spawn(async move {
|
||||
// Record the PID-related metrics of the current process
|
||||
let obs_result = SystemObserver::init_process_observer().await;
|
||||
match obs_result {
|
||||
Ok(_) => {
|
||||
info!(target: "rustfs::obs::system::metrics","Process observer initialized successfully");
|
||||
}
|
||||
Err(e) => {
|
||||
error!(target: "rustfs::obs::system::metrics","Failed to initialize process observer: {}", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
otel_guard
|
||||
}
|
||||
|
||||
/// Set the global guard for OpenTelemetry
|
||||
@@ -99,14 +103,14 @@ pub async fn init_obs(endpoint: Option<String>) -> OtelGuard {
|
||||
/// * `Err(GuardError)` if setting fails
|
||||
///
|
||||
/// # Example
|
||||
/// ```rust
|
||||
/// use rustfs_obs::{ init_obs, set_global_guard};
|
||||
/// ```no_run
|
||||
/// # use rustfs_obs::{ init_obs, set_global_guard};
|
||||
///
|
||||
/// async fn init() -> Result<(), Box<dyn std::error::Error>> {
|
||||
/// let guard = init_obs(None).await;
|
||||
/// set_global_guard(guard)?;
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// # async fn init() -> Result<(), Box<dyn std::error::Error>> {
|
||||
/// # let guard = init_obs(None).await;
|
||||
/// # set_global_guard(guard)?;
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn set_global_guard(guard: OtelGuard) -> Result<(), GlobalError> {
|
||||
info!("Initializing global OpenTelemetry guard");
|
||||
@@ -120,29 +124,20 @@ pub fn set_global_guard(guard: OtelGuard) -> Result<(), GlobalError> {
|
||||
/// * `Err(GuardError)` if guard not initialized
|
||||
///
|
||||
/// # Example
|
||||
/// ```rust
|
||||
/// use rustfs_obs::get_global_guard;
|
||||
/// ```no_run
|
||||
/// # use rustfs_obs::get_global_guard;
|
||||
///
|
||||
/// async fn trace_operation() -> Result<(), Box<dyn std::error::Error>> {
|
||||
/// let guard = get_global_guard()?;
|
||||
/// let _lock = guard.lock().unwrap();
|
||||
/// // Perform traced operation
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// # async fn trace_operation() -> Result<(), Box<dyn std::error::Error>> {
|
||||
/// # let guard = get_global_guard()?;
|
||||
/// # let _lock = guard.lock().unwrap();
|
||||
/// # // Perform traced operation
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn get_global_guard() -> Result<Arc<Mutex<OtelGuard>>, GlobalError> {
|
||||
GLOBAL_GUARD.get().cloned().ok_or(GlobalError::NotInitialized)
|
||||
}
|
||||
|
||||
/// Try to get the global guard for OpenTelemetry
|
||||
///
|
||||
/// # Returns
|
||||
/// * `Some(Arc<Mutex<OtelGuard>>)` if guard exists
|
||||
/// * `None` if guard not initialized
|
||||
pub fn try_get_global_guard() -> Option<Arc<Mutex<OtelGuard>>> {
|
||||
GLOBAL_GUARD.get().cloned()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user