mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-19 02:56:18 +00:00
improve code for obs
This commit is contained in:
+4
-3
@@ -11,9 +11,10 @@ members = [
|
|||||||
"iam", # Identity and Access Management
|
"iam", # Identity and Access Management
|
||||||
"crypto", # Cryptography and security features
|
"crypto", # Cryptography and security features
|
||||||
"cli/rustfs-gui", # Graphical user interface client
|
"cli/rustfs-gui", # Graphical user interface client
|
||||||
"packages/obs", # Observability utilities
|
"crates/obs", # Observability utilities
|
||||||
"s3select/api",
|
"s3select/api",
|
||||||
"s3select/query", "appauth",
|
"s3select/query",
|
||||||
|
"appauth",
|
||||||
]
|
]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
@@ -88,7 +89,7 @@ reqwest = { version = "0.12.15", default-features = false, features = ["rustls-t
|
|||||||
rfd = { version = "0.15.2", default-features = false, features = ["xdg-portal", "tokio"] }
|
rfd = { version = "0.15.2", default-features = false, features = ["xdg-portal", "tokio"] }
|
||||||
rmp = "0.8.14"
|
rmp = "0.8.14"
|
||||||
rmp-serde = "1.3.0"
|
rmp-serde = "1.3.0"
|
||||||
rustfs-obs = { path = "packages/obs", version = "0.0.1" }
|
rustfs-obs = { path = "crates/obs", version = "0.0.1" }
|
||||||
rust-embed = "8.6.0"
|
rust-embed = "8.6.0"
|
||||||
rustls = { version = "0.23" }
|
rustls = { version = "0.23" }
|
||||||
rustls-pki-types = "1.11.0"
|
rustls-pki-types = "1.11.0"
|
||||||
|
|||||||
@@ -46,10 +46,17 @@ impl ObjectVersion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for ObjectVersion {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Log kind/level enum
|
/// Log kind/level enum
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
|
||||||
pub enum LogKind {
|
pub enum LogKind {
|
||||||
#[serde(rename = "INFO")]
|
#[serde(rename = "INFO")]
|
||||||
|
#[default]
|
||||||
Info,
|
Info,
|
||||||
#[serde(rename = "WARNING")]
|
#[serde(rename = "WARNING")]
|
||||||
Warning,
|
Warning,
|
||||||
@@ -59,12 +66,6 @@ pub enum LogKind {
|
|||||||
Fatal,
|
Fatal,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for LogKind {
|
|
||||||
fn default() -> Self {
|
|
||||||
LogKind::Info
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Trait for types that can be serialized to JSON and have a timestamp
|
/// Trait for types that can be serialized to JSON and have a timestamp
|
||||||
/// This trait is used by `ServerLogEntry` to convert the log entry to JSON
|
/// This trait is used by `ServerLogEntry` to convert the log entry to JSON
|
||||||
/// and get the timestamp of the log entry
|
/// and get the timestamp of the log entry
|
||||||
@@ -99,6 +99,7 @@ impl LogRecord for ServerLogEntry {
|
|||||||
/// - `console_msg` - the console message
|
/// - `console_msg` - the console message
|
||||||
/// - `node_name` - the node name
|
/// - `node_name` - the node name
|
||||||
/// - `err` - the error message
|
/// - `err` - the error message
|
||||||
|
///
|
||||||
/// The `ConsoleLogEntry` structure contains the following methods:
|
/// The `ConsoleLogEntry` structure contains the following methods:
|
||||||
/// - `new` - create a new `ConsoleLogEntry`
|
/// - `new` - create a new `ConsoleLogEntry`
|
||||||
/// - `new_with_console_msg` - create a new `ConsoleLogEntry` with console message and node name
|
/// - `new_with_console_msg` - create a new `ConsoleLogEntry` with console message and node name
|
||||||
@@ -107,6 +108,7 @@ impl LogRecord for ServerLogEntry {
|
|||||||
/// - `set_node_name` - set the node name
|
/// - `set_node_name` - set the node name
|
||||||
/// - `set_console_msg` - set the console message
|
/// - `set_console_msg` - set the console message
|
||||||
/// - `set_err` - set the error message
|
/// - `set_err` - set the error message
|
||||||
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```
|
/// ```
|
||||||
/// use rustfs_obs::ConsoleLogEntry;
|
/// use rustfs_obs::ConsoleLogEntry;
|
||||||
@@ -180,6 +182,12 @@ impl ConsoleLogEntry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for ConsoleLogEntry {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl LogRecord for ConsoleLogEntry {
|
impl LogRecord for ConsoleLogEntry {
|
||||||
fn to_json(&self) -> String {
|
fn to_json(&self) -> String {
|
||||||
serde_json::to_string(self).unwrap_or_else(|_| String::from("{}"))
|
serde_json::to_string(self).unwrap_or_else(|_| String::from("{}"))
|
||||||
@@ -217,7 +225,7 @@ pub enum UnifiedLogEntry {
|
|||||||
Server(ServerLogEntry),
|
Server(ServerLogEntry),
|
||||||
|
|
||||||
#[serde(rename = "audit")]
|
#[serde(rename = "audit")]
|
||||||
Audit(AuditLogEntry),
|
Audit(Box<AuditLogEntry>),
|
||||||
|
|
||||||
#[serde(rename = "console")]
|
#[serde(rename = "console")]
|
||||||
Console(ConsoleLogEntry),
|
Console(ConsoleLogEntry),
|
||||||
@@ -50,7 +50,7 @@ impl Logger {
|
|||||||
/// Log an audit entry
|
/// Log an audit entry
|
||||||
#[tracing::instrument(skip(self), fields(log_source = "logger_audit"))]
|
#[tracing::instrument(skip(self), fields(log_source = "logger_audit"))]
|
||||||
pub async fn log_audit_entry(&self, entry: AuditLogEntry) -> Result<(), LogError> {
|
pub async fn log_audit_entry(&self, entry: AuditLogEntry) -> Result<(), LogError> {
|
||||||
self.log_entry(UnifiedLogEntry::Audit(entry)).await
|
self.log_entry(UnifiedLogEntry::Audit(Box::new(entry))).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Log a console entry
|
/// Log a console entry
|
||||||
@@ -61,13 +61,14 @@ impl Logger {
|
|||||||
|
|
||||||
/// Asynchronous logging of unified log entries
|
/// Asynchronous logging of unified log entries
|
||||||
#[tracing::instrument(skip(self), fields(log_source = "logger"))]
|
#[tracing::instrument(skip(self), fields(log_source = "logger"))]
|
||||||
|
#[tracing::instrument(level = "error", skip_all)]
|
||||||
pub async fn log_entry(&self, entry: UnifiedLogEntry) -> Result<(), LogError> {
|
pub async fn log_entry(&self, entry: UnifiedLogEntry) -> Result<(), LogError> {
|
||||||
// Extract information for tracing based on entry type
|
// Extract information for tracing based on entry type
|
||||||
match &entry {
|
match &entry {
|
||||||
UnifiedLogEntry::Server(server) => {
|
UnifiedLogEntry::Server(server) => {
|
||||||
tracing::Span::current()
|
tracing::Span::current()
|
||||||
.record("log_level", &server.level.0.as_str())
|
.record("log_level", server.level.0.as_str())
|
||||||
.record("log_message", &server.base.message.as_deref().unwrap_or(""))
|
.record("log_message", server.base.message.as_deref().unwrap_or("log message not set"))
|
||||||
.record("source", &server.source);
|
.record("source", &server.source);
|
||||||
|
|
||||||
// Generate tracing event based on log level
|
// Generate tracing event based on log level
|
||||||
@@ -284,7 +284,7 @@ impl FileSink {
|
|||||||
// If the file does not exist, create it
|
// If the file does not exist, create it
|
||||||
debug!("FileSink: File does not exist, creating a new file.");
|
debug!("FileSink: File does not exist, creating a new file.");
|
||||||
// Create the file and write a header or initial content if needed
|
// Create the file and write a header or initial content if needed
|
||||||
OpenOptions::new().create(true).write(true).open(&path).await?
|
OpenOptions::new().create(true).truncate(true).write(true).open(&path).await?
|
||||||
};
|
};
|
||||||
let writer = io::BufWriter::with_capacity(buffer_size, file);
|
let writer = io::BufWriter::with_capacity(buffer_size, file);
|
||||||
let now = std::time::SystemTime::now()
|
let now = std::time::SystemTime::now()
|
||||||
Reference in New Issue
Block a user