mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-27 15:37:02 +00:00
@@ -16,8 +16,8 @@
|
|||||||
//! This module defines the configuration for audit systems, including
|
//! This module defines the configuration for audit systems, including
|
||||||
//! webhook and MQTT audit-related settings.
|
//! webhook and MQTT audit-related settings.
|
||||||
|
|
||||||
pub(crate) mod mqtt;
|
mod mqtt;
|
||||||
pub(crate) mod webhook;
|
mod webhook;
|
||||||
|
|
||||||
pub use mqtt::*;
|
pub use mqtt::*;
|
||||||
pub use webhook::*;
|
pub use webhook::*;
|
||||||
|
|||||||
@@ -151,8 +151,8 @@ pub const DEFAULT_LOG_KEEP_FILES: u16 = 30;
|
|||||||
/// This is the default log local logging enabled for rustfs.
|
/// This is the default log local logging enabled for rustfs.
|
||||||
/// It is used to enable or disable local logging of the application.
|
/// It is used to enable or disable local logging of the application.
|
||||||
/// Default value: false
|
/// Default value: false
|
||||||
/// Environment variable: RUSTFS_OBS_LOCAL_LOGGING_ENABLED
|
/// Environment variable: RUSTFS_OBS_LOGL_STDOUT_ENABLED
|
||||||
pub const DEFAULT_LOG_LOCAL_LOGGING_ENABLED: bool = false;
|
pub const DEFAULT_OBS_LOG_STDOUT_ENABLED: bool = false;
|
||||||
|
|
||||||
/// Constant representing 1 Kibibyte (1024 bytes)
|
/// Constant representing 1 Kibibyte (1024 bytes)
|
||||||
/// Default value: 1024
|
/// Default value: 1024
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ pub const ENV_OBS_SERVICE_NAME: &str = "RUSTFS_OBS_SERVICE_NAME";
|
|||||||
pub const ENV_OBS_SERVICE_VERSION: &str = "RUSTFS_OBS_SERVICE_VERSION";
|
pub const ENV_OBS_SERVICE_VERSION: &str = "RUSTFS_OBS_SERVICE_VERSION";
|
||||||
pub const ENV_OBS_ENVIRONMENT: &str = "RUSTFS_OBS_ENVIRONMENT";
|
pub const ENV_OBS_ENVIRONMENT: &str = "RUSTFS_OBS_ENVIRONMENT";
|
||||||
pub const ENV_OBS_LOGGER_LEVEL: &str = "RUSTFS_OBS_LOGGER_LEVEL";
|
pub const ENV_OBS_LOGGER_LEVEL: &str = "RUSTFS_OBS_LOGGER_LEVEL";
|
||||||
pub const ENV_OBS_LOCAL_LOGGING_ENABLED: &str = "RUSTFS_OBS_LOCAL_LOGGING_ENABLED";
|
pub const ENV_OBS_LOG_STDOUT_ENABLED: &str = "RUSTFS_OBS_LOG_STDOUT_ENABLED";
|
||||||
pub const ENV_OBS_LOG_DIRECTORY: &str = "RUSTFS_OBS_LOG_DIRECTORY";
|
pub const ENV_OBS_LOG_DIRECTORY: &str = "RUSTFS_OBS_LOG_DIRECTORY";
|
||||||
pub const ENV_OBS_LOG_FILENAME: &str = "RUSTFS_OBS_LOG_FILENAME";
|
pub const ENV_OBS_LOG_FILENAME: &str = "RUSTFS_OBS_LOG_FILENAME";
|
||||||
pub const ENV_OBS_LOG_ROTATION_SIZE_MB: &str = "RUSTFS_OBS_LOG_ROTATION_SIZE_MB";
|
pub const ENV_OBS_LOG_ROTATION_SIZE_MB: &str = "RUSTFS_OBS_LOG_ROTATION_SIZE_MB";
|
||||||
@@ -47,12 +47,6 @@ pub const DEFAULT_OBS_LOG_MESSAGE_CAPA: usize = 32768;
|
|||||||
/// Default values for flush interval in milliseconds
|
/// Default values for flush interval in milliseconds
|
||||||
pub const DEFAULT_OBS_LOG_FLUSH_MS: u64 = 200;
|
pub const DEFAULT_OBS_LOG_FLUSH_MS: u64 = 200;
|
||||||
|
|
||||||
/// Audit logger queue capacity environment variable key
|
|
||||||
pub const ENV_AUDIT_LOGGER_QUEUE_CAPACITY: &str = "RUSTFS_AUDIT_LOGGER_QUEUE_CAPACITY";
|
|
||||||
|
|
||||||
/// Default values for observability configuration
|
|
||||||
pub const DEFAULT_AUDIT_LOGGER_QUEUE_CAPACITY: usize = 10000;
|
|
||||||
|
|
||||||
/// Default values for observability configuration
|
/// Default values for observability configuration
|
||||||
// ### Supported Environment Values
|
// ### Supported Environment Values
|
||||||
// - `production` - Secure file-only logging
|
// - `production` - Secure file-only logging
|
||||||
@@ -78,18 +72,16 @@ mod tests {
|
|||||||
assert_eq!(ENV_OBS_SERVICE_VERSION, "RUSTFS_OBS_SERVICE_VERSION");
|
assert_eq!(ENV_OBS_SERVICE_VERSION, "RUSTFS_OBS_SERVICE_VERSION");
|
||||||
assert_eq!(ENV_OBS_ENVIRONMENT, "RUSTFS_OBS_ENVIRONMENT");
|
assert_eq!(ENV_OBS_ENVIRONMENT, "RUSTFS_OBS_ENVIRONMENT");
|
||||||
assert_eq!(ENV_OBS_LOGGER_LEVEL, "RUSTFS_OBS_LOGGER_LEVEL");
|
assert_eq!(ENV_OBS_LOGGER_LEVEL, "RUSTFS_OBS_LOGGER_LEVEL");
|
||||||
assert_eq!(ENV_OBS_LOCAL_LOGGING_ENABLED, "RUSTFS_OBS_LOCAL_LOGGING_ENABLED");
|
assert_eq!(ENV_OBS_LOG_STDOUT_ENABLED, "RUSTFS_OBS_LOG_STDOUT_ENABLED");
|
||||||
assert_eq!(ENV_OBS_LOG_DIRECTORY, "RUSTFS_OBS_LOG_DIRECTORY");
|
assert_eq!(ENV_OBS_LOG_DIRECTORY, "RUSTFS_OBS_LOG_DIRECTORY");
|
||||||
assert_eq!(ENV_OBS_LOG_FILENAME, "RUSTFS_OBS_LOG_FILENAME");
|
assert_eq!(ENV_OBS_LOG_FILENAME, "RUSTFS_OBS_LOG_FILENAME");
|
||||||
assert_eq!(ENV_OBS_LOG_ROTATION_SIZE_MB, "RUSTFS_OBS_LOG_ROTATION_SIZE_MB");
|
assert_eq!(ENV_OBS_LOG_ROTATION_SIZE_MB, "RUSTFS_OBS_LOG_ROTATION_SIZE_MB");
|
||||||
assert_eq!(ENV_OBS_LOG_ROTATION_TIME, "RUSTFS_OBS_LOG_ROTATION_TIME");
|
assert_eq!(ENV_OBS_LOG_ROTATION_TIME, "RUSTFS_OBS_LOG_ROTATION_TIME");
|
||||||
assert_eq!(ENV_OBS_LOG_KEEP_FILES, "RUSTFS_OBS_LOG_KEEP_FILES");
|
assert_eq!(ENV_OBS_LOG_KEEP_FILES, "RUSTFS_OBS_LOG_KEEP_FILES");
|
||||||
assert_eq!(ENV_AUDIT_LOGGER_QUEUE_CAPACITY, "RUSTFS_AUDIT_LOGGER_QUEUE_CAPACITY");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_default_values() {
|
fn test_default_values() {
|
||||||
assert_eq!(DEFAULT_AUDIT_LOGGER_QUEUE_CAPACITY, 10000);
|
|
||||||
assert_eq!(DEFAULT_OBS_ENVIRONMENT_PRODUCTION, "production");
|
assert_eq!(DEFAULT_OBS_ENVIRONMENT_PRODUCTION, "production");
|
||||||
assert_eq!(DEFAULT_OBS_ENVIRONMENT_DEVELOPMENT, "development");
|
assert_eq!(DEFAULT_OBS_ENVIRONMENT_DEVELOPMENT, "development");
|
||||||
assert_eq!(DEFAULT_OBS_ENVIRONMENT_TEST, "test");
|
assert_eq!(DEFAULT_OBS_ENVIRONMENT_TEST, "test");
|
||||||
|
|||||||
+16
-15
@@ -13,13 +13,14 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use rustfs_config::observability::{
|
use rustfs_config::observability::{
|
||||||
ENV_OBS_ENDPOINT, ENV_OBS_ENVIRONMENT, ENV_OBS_LOCAL_LOGGING_ENABLED, ENV_OBS_LOG_DIRECTORY, ENV_OBS_LOG_FILENAME,
|
ENV_OBS_ENDPOINT, ENV_OBS_ENVIRONMENT, ENV_OBS_LOG_DIRECTORY, ENV_OBS_LOG_FILENAME, ENV_OBS_LOG_KEEP_FILES,
|
||||||
ENV_OBS_LOG_KEEP_FILES, ENV_OBS_LOG_ROTATION_SIZE_MB, ENV_OBS_LOG_ROTATION_TIME, ENV_OBS_LOGGER_LEVEL,
|
ENV_OBS_LOG_ROTATION_SIZE_MB, ENV_OBS_LOG_ROTATION_TIME, ENV_OBS_LOG_STDOUT_ENABLED, ENV_OBS_LOGGER_LEVEL,
|
||||||
ENV_OBS_METER_INTERVAL, ENV_OBS_SAMPLE_RATIO, ENV_OBS_SERVICE_NAME, ENV_OBS_SERVICE_VERSION, ENV_OBS_USE_STDOUT,
|
ENV_OBS_METER_INTERVAL, ENV_OBS_SAMPLE_RATIO, ENV_OBS_SERVICE_NAME, ENV_OBS_SERVICE_VERSION, ENV_OBS_USE_STDOUT,
|
||||||
};
|
};
|
||||||
use rustfs_config::{
|
use rustfs_config::{
|
||||||
APP_NAME, DEFAULT_LOG_KEEP_FILES, DEFAULT_LOG_LEVEL, DEFAULT_LOG_LOCAL_LOGGING_ENABLED, DEFAULT_LOG_ROTATION_SIZE_MB,
|
APP_NAME, DEFAULT_LOG_KEEP_FILES, DEFAULT_LOG_LEVEL, DEFAULT_LOG_ROTATION_SIZE_MB, DEFAULT_LOG_ROTATION_TIME,
|
||||||
DEFAULT_LOG_ROTATION_TIME, DEFAULT_OBS_LOG_FILENAME, ENVIRONMENT, METER_INTERVAL, SAMPLE_RATIO, SERVICE_VERSION, USE_STDOUT,
|
DEFAULT_OBS_LOG_FILENAME, DEFAULT_OBS_LOG_STDOUT_ENABLED, ENVIRONMENT, METER_INTERVAL, SAMPLE_RATIO, SERVICE_VERSION,
|
||||||
|
USE_STDOUT,
|
||||||
};
|
};
|
||||||
use rustfs_utils::dirs::get_log_directory_to_string;
|
use rustfs_utils::dirs::get_log_directory_to_string;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@@ -53,15 +54,15 @@ use std::env;
|
|||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||||
pub struct OtelConfig {
|
pub struct OtelConfig {
|
||||||
pub endpoint: String, // Endpoint for metric collection
|
pub endpoint: String, // Endpoint for metric collection
|
||||||
pub use_stdout: Option<bool>, // Output to stdout
|
pub use_stdout: Option<bool>, // Output to stdout
|
||||||
pub sample_ratio: Option<f64>, // Trace sampling ratio
|
pub sample_ratio: Option<f64>, // Trace sampling ratio
|
||||||
pub meter_interval: Option<u64>, // Metric collection interval
|
pub meter_interval: Option<u64>, // Metric collection interval
|
||||||
pub service_name: Option<String>, // Service name
|
pub service_name: Option<String>, // Service name
|
||||||
pub service_version: Option<String>, // Service version
|
pub service_version: Option<String>, // Service version
|
||||||
pub environment: Option<String>, // Environment
|
pub environment: Option<String>, // Environment
|
||||||
pub logger_level: Option<String>, // Logger level
|
pub logger_level: Option<String>, // Logger level
|
||||||
pub local_logging_enabled: Option<bool>, // Local logging enabled
|
pub log_stdout_enabled: Option<bool>, // Stdout logging enabled
|
||||||
// Added flexi_logger related configurations
|
// Added flexi_logger related configurations
|
||||||
pub log_directory: Option<String>, // LOG FILE DIRECTORY
|
pub log_directory: Option<String>, // LOG FILE DIRECTORY
|
||||||
pub log_filename: Option<String>, // The name of the log file
|
pub log_filename: Option<String>, // The name of the log file
|
||||||
@@ -117,10 +118,10 @@ impl OtelConfig {
|
|||||||
.ok()
|
.ok()
|
||||||
.and_then(|v| v.parse().ok())
|
.and_then(|v| v.parse().ok())
|
||||||
.or(Some(DEFAULT_LOG_LEVEL.to_string())),
|
.or(Some(DEFAULT_LOG_LEVEL.to_string())),
|
||||||
local_logging_enabled: env::var(ENV_OBS_LOCAL_LOGGING_ENABLED)
|
log_stdout_enabled: env::var(ENV_OBS_LOG_STDOUT_ENABLED)
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|v| v.parse().ok())
|
.and_then(|v| v.parse().ok())
|
||||||
.or(Some(DEFAULT_LOG_LOCAL_LOGGING_ENABLED)),
|
.or(Some(DEFAULT_OBS_LOG_STDOUT_ENABLED)),
|
||||||
log_directory: Some(get_log_directory_to_string(ENV_OBS_LOG_DIRECTORY)),
|
log_directory: Some(get_log_directory_to_string(ENV_OBS_LOG_DIRECTORY)),
|
||||||
log_filename: env::var(ENV_OBS_LOG_FILENAME)
|
log_filename: env::var(ENV_OBS_LOG_FILENAME)
|
||||||
.ok()
|
.ok()
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ use opentelemetry_semantic_conventions::{
|
|||||||
attribute::{DEPLOYMENT_ENVIRONMENT_NAME, NETWORK_LOCAL_ADDRESS, SERVICE_VERSION as OTEL_SERVICE_VERSION},
|
attribute::{DEPLOYMENT_ENVIRONMENT_NAME, NETWORK_LOCAL_ADDRESS, SERVICE_VERSION as OTEL_SERVICE_VERSION},
|
||||||
};
|
};
|
||||||
use rustfs_config::{
|
use rustfs_config::{
|
||||||
APP_NAME, DEFAULT_LOG_KEEP_FILES, DEFAULT_LOG_LEVEL, DEFAULT_LOG_LOCAL_LOGGING_ENABLED, ENVIRONMENT, METER_INTERVAL,
|
APP_NAME, DEFAULT_LOG_KEEP_FILES, DEFAULT_LOG_LEVEL, DEFAULT_OBS_LOG_STDOUT_ENABLED, ENVIRONMENT, METER_INTERVAL,
|
||||||
SAMPLE_RATIO, SERVICE_VERSION, USE_STDOUT,
|
SAMPLE_RATIO, SERVICE_VERSION, USE_STDOUT,
|
||||||
observability::{
|
observability::{
|
||||||
DEFAULT_OBS_ENVIRONMENT_PRODUCTION, DEFAULT_OBS_LOG_FLUSH_MS, DEFAULT_OBS_LOG_MESSAGE_CAPA, DEFAULT_OBS_LOG_POOL_CAPA,
|
DEFAULT_OBS_ENVIRONMENT_PRODUCTION, DEFAULT_OBS_LOG_FLUSH_MS, DEFAULT_OBS_LOG_MESSAGE_CAPA, DEFAULT_OBS_LOG_POOL_CAPA,
|
||||||
@@ -304,7 +304,7 @@ pub(crate) fn init_telemetry(config: &OtelConfig) -> OtelGuard {
|
|||||||
tracing_subscriber::registry()
|
tracing_subscriber::registry()
|
||||||
.with(filter)
|
.with(filter)
|
||||||
.with(ErrorLayer::default())
|
.with(ErrorLayer::default())
|
||||||
.with(if config.local_logging_enabled.unwrap_or(DEFAULT_LOG_LOCAL_LOGGING_ENABLED) {
|
.with(if config.log_stdout_enabled.unwrap_or(DEFAULT_OBS_LOG_STDOUT_ENABLED) {
|
||||||
Some(fmt_layer)
|
Some(fmt_layer)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@@ -395,6 +395,23 @@ pub(crate) fn init_telemetry(config: &OtelConfig) -> OtelGuard {
|
|||||||
.with(env_filter)
|
.with(env_filter)
|
||||||
.with(ErrorLayer::default())
|
.with(ErrorLayer::default())
|
||||||
.with(fmt_layer)
|
.with(fmt_layer)
|
||||||
|
.with(if config.log_stdout_enabled.unwrap_or(DEFAULT_OBS_LOG_STDOUT_ENABLED) {
|
||||||
|
let stdout_fmt_layer = tracing_subscriber::fmt::layer()
|
||||||
|
.with_timer(LocalTime::rfc_3339())
|
||||||
|
.with_target(true)
|
||||||
|
.with_thread_names(true)
|
||||||
|
.with_thread_ids(true)
|
||||||
|
.with_file(true)
|
||||||
|
.with_line_number(true)
|
||||||
|
.with_writer(std::io::stdout) // Specify writing file
|
||||||
|
.json()
|
||||||
|
.with_current_span(true)
|
||||||
|
.with_span_list(true)
|
||||||
|
.with_span_events(FmtSpan::CLOSE); // Log span lifecycle events, including trace_id;
|
||||||
|
Some(stdout_fmt_layer)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
})
|
||||||
.init();
|
.init();
|
||||||
|
|
||||||
info!("Tracing telemetry initialized for non-production with trace_id logging.");
|
info!("Tracing telemetry initialized for non-production with trace_id logging.");
|
||||||
|
|||||||
+1
-1
@@ -59,7 +59,7 @@ export RUSTFS_CONSOLE_ADDRESS=":9001"
|
|||||||
#export RUSTFS_OBS_SERVICE_VERSION=0.1.0 # Service version
|
#export RUSTFS_OBS_SERVICE_VERSION=0.1.0 # Service version
|
||||||
export RUSTFS_OBS_ENVIRONMENT=develop # Environment name
|
export RUSTFS_OBS_ENVIRONMENT=develop # Environment name
|
||||||
export RUSTFS_OBS_LOGGER_LEVEL=info # Log level, supports trace, debug, info, warn, error
|
export RUSTFS_OBS_LOGGER_LEVEL=info # Log level, supports trace, debug, info, warn, error
|
||||||
export RUSTFS_OBS_LOCAL_LOGGING_ENABLED=true # Whether to enable local logging
|
export RUSTFS_OBS_LOG_STDOUT_ENABLED=true # Whether to enable local stdout logging
|
||||||
export RUSTFS_OBS_LOG_DIRECTORY="$current_dir/deploy/logs" # Log directory
|
export RUSTFS_OBS_LOG_DIRECTORY="$current_dir/deploy/logs" # Log directory
|
||||||
export RUSTFS_OBS_LOG_ROTATION_TIME="hour" # Log rotation time unit, can be "second", "minute", "hour", "day"
|
export RUSTFS_OBS_LOG_ROTATION_TIME="hour" # Log rotation time unit, can be "second", "minute", "hour", "day"
|
||||||
export RUSTFS_OBS_LOG_ROTATION_SIZE_MB=100 # Log rotation size in MB
|
export RUSTFS_OBS_LOG_ROTATION_SIZE_MB=100 # Log rotation size in MB
|
||||||
|
|||||||
Reference in New Issue
Block a user