mirror of
https://github.com/rustfs/rustfs.git
synced 2026-07-29 01:29:00 +00:00
add Error test, fix clippy
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use crate::event::config::NotifierConfig;
|
||||
use crate::ObservabilityConfig;
|
||||
use crate::event::config::NotifierConfig;
|
||||
|
||||
/// RustFs configuration
|
||||
pub struct RustFsConfig {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use rustfs_event_notifier::create_adapters;
|
||||
use rustfs_event_notifier::NotifierSystem;
|
||||
use rustfs_event_notifier::create_adapters;
|
||||
use rustfs_event_notifier::{AdapterConfig, NotifierConfig, WebhookConfig};
|
||||
use rustfs_event_notifier::{Bucket, Event, Identity, Metadata, Name, Object, Source};
|
||||
use std::collections::HashMap;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use axum::{extract::Json, http::StatusCode, routing::post, Router};
|
||||
use axum::{Router, extract::Json, http::StatusCode, routing::post};
|
||||
use serde_json::Value;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::Error;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_with::{DeserializeFromStr, SerializeDisplay};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::{create_adapters, Error, Event, NotifierConfig, NotifierSystem};
|
||||
use std::sync::{atomic, Arc};
|
||||
use crate::{Error, Event, NotifierConfig, NotifierSystem, create_adapters};
|
||||
use std::sync::{Arc, atomic};
|
||||
use tokio::sync::{Mutex, OnceCell};
|
||||
use tracing::instrument;
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ mod global;
|
||||
mod notifier;
|
||||
mod store;
|
||||
|
||||
pub use adapter::ChannelAdapter;
|
||||
pub use adapter::create_adapters;
|
||||
#[cfg(all(feature = "kafka", target_os = "linux"))]
|
||||
pub use adapter::kafka::KafkaAdapter;
|
||||
@@ -14,7 +15,6 @@ pub use adapter::kafka::KafkaAdapter;
|
||||
pub use adapter::mqtt::MqttAdapter;
|
||||
#[cfg(feature = "webhook")]
|
||||
pub use adapter::webhook::WebhookAdapter;
|
||||
pub use adapter::ChannelAdapter;
|
||||
pub use bus::event_bus;
|
||||
#[cfg(all(feature = "kafka", target_os = "linux"))]
|
||||
pub use config::KafkaConfig;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{event_bus, ChannelAdapter, Error, Event, EventStore, NotifierConfig};
|
||||
use crate::{ChannelAdapter, Error, Event, EventStore, NotifierConfig, event_bus};
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::mpsc;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::Error;
|
||||
use crate::Log;
|
||||
use std::sync::Arc;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use tokio::fs::{create_dir_all, File, OpenOptions};
|
||||
use tokio::fs::{File, OpenOptions, create_dir_all};
|
||||
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader, BufWriter};
|
||||
use tokio::sync::RwLock;
|
||||
use tracing::instrument;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use rustfs_filemeta::{test_data::*, FileMeta};
|
||||
use criterion::{Criterion, black_box, criterion_group, criterion_main};
|
||||
use rustfs_filemeta::{FileMeta, test_data::*};
|
||||
|
||||
fn bench_create_real_xlmeta(c: &mut Criterion) {
|
||||
c.bench_function("create_real_xlmeta", |b| b.iter(|| black_box(create_real_xlmeta().unwrap())));
|
||||
|
||||
@@ -176,3 +176,378 @@ pub fn is_io_eof(e: &Error) -> bool {
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::io::{Error as IoError, ErrorKind};
|
||||
|
||||
#[test]
|
||||
fn test_filemeta_error_from_io_error() {
|
||||
let io_error = IoError::new(ErrorKind::PermissionDenied, "permission denied");
|
||||
let filemeta_error: Error = io_error.into();
|
||||
|
||||
match filemeta_error {
|
||||
Error::Io(inner_io) => {
|
||||
assert_eq!(inner_io.kind(), ErrorKind::PermissionDenied);
|
||||
assert!(inner_io.to_string().contains("permission denied"));
|
||||
}
|
||||
_ => panic!("Expected Io variant"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_filemeta_error_other_function() {
|
||||
let custom_error = "Custom filemeta error";
|
||||
let filemeta_error = Error::other(custom_error);
|
||||
|
||||
match filemeta_error {
|
||||
Error::Io(io_error) => {
|
||||
assert!(io_error.to_string().contains(custom_error));
|
||||
assert_eq!(io_error.kind(), ErrorKind::Other);
|
||||
}
|
||||
_ => panic!("Expected Io variant"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_filemeta_error_conversions() {
|
||||
// Test various error conversions
|
||||
let serde_decode_err =
|
||||
rmp_serde::decode::Error::InvalidMarkerRead(std::io::Error::new(ErrorKind::InvalidData, "invalid"));
|
||||
let filemeta_error: Error = serde_decode_err.into();
|
||||
assert!(matches!(filemeta_error, Error::RmpSerdeDecode(_)));
|
||||
|
||||
// Test with string-based error that we can actually create
|
||||
let encode_error_string = "test encode error";
|
||||
let filemeta_error = Error::RmpSerdeEncode(encode_error_string.to_string());
|
||||
assert!(matches!(filemeta_error, Error::RmpSerdeEncode(_)));
|
||||
|
||||
let utf8_err = std::string::String::from_utf8(vec![0xFF]).unwrap_err();
|
||||
let filemeta_error: Error = utf8_err.into();
|
||||
assert!(matches!(filemeta_error, Error::FromUtf8(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_filemeta_error_clone() {
|
||||
let test_cases = vec![
|
||||
Error::FileNotFound,
|
||||
Error::FileVersionNotFound,
|
||||
Error::VolumeNotFound,
|
||||
Error::FileCorrupt,
|
||||
Error::DoneForNow,
|
||||
Error::MethodNotAllowed,
|
||||
Error::Unexpected,
|
||||
Error::Io(IoError::new(ErrorKind::NotFound, "test")),
|
||||
Error::RmpSerdeDecode("test decode error".to_string()),
|
||||
Error::RmpSerdeEncode("test encode error".to_string()),
|
||||
Error::FromUtf8("test utf8 error".to_string()),
|
||||
Error::RmpDecodeValueRead("test value read error".to_string()),
|
||||
Error::RmpEncodeValueWrite("test value write error".to_string()),
|
||||
Error::RmpDecodeNumValueRead("test num read error".to_string()),
|
||||
Error::RmpDecodeMarkerRead("test marker read error".to_string()),
|
||||
Error::TimeComponentRange("test time error".to_string()),
|
||||
Error::UuidParse("test uuid error".to_string()),
|
||||
];
|
||||
|
||||
for original_error in test_cases {
|
||||
let cloned_error = original_error.clone();
|
||||
assert_eq!(original_error, cloned_error);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_filemeta_error_partial_eq() {
|
||||
// Test equality for simple variants
|
||||
assert_eq!(Error::FileNotFound, Error::FileNotFound);
|
||||
assert_ne!(Error::FileNotFound, Error::FileVersionNotFound);
|
||||
|
||||
// Test equality for Io variants
|
||||
let io1 = Error::Io(IoError::new(ErrorKind::NotFound, "test"));
|
||||
let io2 = Error::Io(IoError::new(ErrorKind::NotFound, "test"));
|
||||
let io3 = Error::Io(IoError::new(ErrorKind::PermissionDenied, "test"));
|
||||
assert_eq!(io1, io2);
|
||||
assert_ne!(io1, io3);
|
||||
|
||||
// Test equality for string variants
|
||||
let decode1 = Error::RmpSerdeDecode("error message".to_string());
|
||||
let decode2 = Error::RmpSerdeDecode("error message".to_string());
|
||||
let decode3 = Error::RmpSerdeDecode("different message".to_string());
|
||||
assert_eq!(decode1, decode2);
|
||||
assert_ne!(decode1, decode3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_filemeta_error_display() {
|
||||
let test_cases = vec![
|
||||
(Error::FileNotFound, "File not found"),
|
||||
(Error::FileVersionNotFound, "File version not found"),
|
||||
(Error::VolumeNotFound, "Volume not found"),
|
||||
(Error::FileCorrupt, "File corrupt"),
|
||||
(Error::DoneForNow, "Done for now"),
|
||||
(Error::MethodNotAllowed, "Method not allowed"),
|
||||
(Error::Unexpected, "Unexpected error"),
|
||||
(Error::RmpSerdeDecode("test".to_string()), "rmp serde decode error: test"),
|
||||
(Error::RmpSerdeEncode("test".to_string()), "rmp serde encode error: test"),
|
||||
(Error::FromUtf8("test".to_string()), "Invalid UTF-8: test"),
|
||||
(Error::TimeComponentRange("test".to_string()), "time component range error: test"),
|
||||
(Error::UuidParse("test".to_string()), "uuid parse error: test"),
|
||||
];
|
||||
|
||||
for (error, expected_message) in test_cases {
|
||||
assert_eq!(error.to_string(), expected_message);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rmp_conversions() {
|
||||
// Test rmp value read error (this one works since it has the same signature)
|
||||
let value_read_err = rmp::decode::ValueReadError::InvalidMarkerRead(std::io::Error::new(ErrorKind::InvalidData, "test"));
|
||||
let filemeta_error: Error = value_read_err.into();
|
||||
assert!(matches!(filemeta_error, Error::RmpDecodeValueRead(_)));
|
||||
|
||||
// Test rmp num value read error
|
||||
let num_value_err =
|
||||
rmp::decode::NumValueReadError::InvalidMarkerRead(std::io::Error::new(ErrorKind::InvalidData, "test"));
|
||||
let filemeta_error: Error = num_value_err.into();
|
||||
assert!(matches!(filemeta_error, Error::RmpDecodeNumValueRead(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_time_and_uuid_conversions() {
|
||||
// Test time component range error
|
||||
use time::{Date, Month};
|
||||
let time_result = Date::from_calendar_date(2023, Month::January, 32); // Invalid day
|
||||
assert!(time_result.is_err());
|
||||
let time_error = time_result.unwrap_err();
|
||||
let filemeta_error: Error = time_error.into();
|
||||
assert!(matches!(filemeta_error, Error::TimeComponentRange(_)));
|
||||
|
||||
// Test UUID parse error
|
||||
let uuid_result = uuid::Uuid::parse_str("invalid-uuid");
|
||||
assert!(uuid_result.is_err());
|
||||
let uuid_error = uuid_result.unwrap_err();
|
||||
let filemeta_error: Error = uuid_error.into();
|
||||
assert!(matches!(filemeta_error, Error::UuidParse(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_marker_read_error_conversion() {
|
||||
// Test rmp marker read error conversion
|
||||
let marker_err = rmp::decode::MarkerReadError(std::io::Error::new(ErrorKind::InvalidData, "marker test"));
|
||||
let filemeta_error: Error = marker_err.into();
|
||||
assert!(matches!(filemeta_error, Error::RmpDecodeMarkerRead(_)));
|
||||
assert!(filemeta_error.to_string().contains("marker"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_io_eof_function() {
|
||||
// Test is_io_eof helper function
|
||||
let eof_error = Error::Io(IoError::new(ErrorKind::UnexpectedEof, "eof"));
|
||||
assert!(is_io_eof(&eof_error));
|
||||
|
||||
let not_eof_error = Error::Io(IoError::new(ErrorKind::NotFound, "not found"));
|
||||
assert!(!is_io_eof(¬_eof_error));
|
||||
|
||||
let non_io_error = Error::FileNotFound;
|
||||
assert!(!is_io_eof(&non_io_error));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_filemeta_error_to_io_error_conversion() {
|
||||
// Test conversion from FileMeta Error to io::Error through other function
|
||||
let original_io_error = IoError::new(ErrorKind::InvalidData, "test data");
|
||||
let filemeta_error = Error::other(original_io_error);
|
||||
|
||||
match filemeta_error {
|
||||
Error::Io(io_err) => {
|
||||
assert_eq!(io_err.kind(), ErrorKind::Other);
|
||||
assert!(io_err.to_string().contains("test data"));
|
||||
}
|
||||
_ => panic!("Expected Io variant"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_filemeta_error_roundtrip_conversion() {
|
||||
// Test roundtrip conversion: io::Error -> FileMeta Error -> io::Error
|
||||
let original_io_error = IoError::new(ErrorKind::PermissionDenied, "permission test");
|
||||
|
||||
// Convert to FileMeta Error
|
||||
let filemeta_error: Error = original_io_error.into();
|
||||
|
||||
// Extract the io::Error back
|
||||
match filemeta_error {
|
||||
Error::Io(extracted_io_error) => {
|
||||
assert_eq!(extracted_io_error.kind(), ErrorKind::PermissionDenied);
|
||||
assert!(extracted_io_error.to_string().contains("permission test"));
|
||||
}
|
||||
_ => panic!("Expected Io variant"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_filemeta_error_io_error_kinds_preservation() {
|
||||
let io_error_kinds = vec![
|
||||
ErrorKind::NotFound,
|
||||
ErrorKind::PermissionDenied,
|
||||
ErrorKind::ConnectionRefused,
|
||||
ErrorKind::ConnectionReset,
|
||||
ErrorKind::ConnectionAborted,
|
||||
ErrorKind::NotConnected,
|
||||
ErrorKind::AddrInUse,
|
||||
ErrorKind::AddrNotAvailable,
|
||||
ErrorKind::BrokenPipe,
|
||||
ErrorKind::AlreadyExists,
|
||||
ErrorKind::WouldBlock,
|
||||
ErrorKind::InvalidInput,
|
||||
ErrorKind::InvalidData,
|
||||
ErrorKind::TimedOut,
|
||||
ErrorKind::WriteZero,
|
||||
ErrorKind::Interrupted,
|
||||
ErrorKind::UnexpectedEof,
|
||||
ErrorKind::Other,
|
||||
];
|
||||
|
||||
for kind in io_error_kinds {
|
||||
let io_error = IoError::new(kind, format!("test error for {:?}", kind));
|
||||
let filemeta_error: Error = io_error.into();
|
||||
|
||||
match filemeta_error {
|
||||
Error::Io(extracted_io_error) => {
|
||||
assert_eq!(extracted_io_error.kind(), kind);
|
||||
assert!(extracted_io_error.to_string().contains("test error"));
|
||||
}
|
||||
_ => panic!("Expected Io variant for kind {:?}", kind),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_filemeta_error_downcast_chain() {
|
||||
// Test error downcast chain functionality
|
||||
let original_io_error = IoError::new(ErrorKind::InvalidData, "original error");
|
||||
let filemeta_error = Error::other(original_io_error);
|
||||
|
||||
// The error should be wrapped as an Io variant
|
||||
if let Error::Io(io_err) = filemeta_error {
|
||||
// The wrapped error should be Other kind (from std::io::Error::other)
|
||||
assert_eq!(io_err.kind(), ErrorKind::Other);
|
||||
// But the message should still contain the original error information
|
||||
assert!(io_err.to_string().contains("original error"));
|
||||
} else {
|
||||
panic!("Expected Io variant");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_filemeta_error_maintains_error_information() {
|
||||
let test_cases = vec![
|
||||
(ErrorKind::NotFound, "file not found"),
|
||||
(ErrorKind::PermissionDenied, "access denied"),
|
||||
(ErrorKind::InvalidData, "corrupt data"),
|
||||
(ErrorKind::TimedOut, "operation timed out"),
|
||||
];
|
||||
|
||||
for (kind, message) in test_cases {
|
||||
let io_error = IoError::new(kind, message);
|
||||
let error_message = io_error.to_string();
|
||||
let filemeta_error: Error = io_error.into();
|
||||
|
||||
match filemeta_error {
|
||||
Error::Io(extracted_io_error) => {
|
||||
assert_eq!(extracted_io_error.kind(), kind);
|
||||
assert_eq!(extracted_io_error.to_string(), error_message);
|
||||
}
|
||||
_ => panic!("Expected Io variant"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_filemeta_error_complex_conversion_chain() {
|
||||
// Test conversion from string error types that we can actually create
|
||||
|
||||
// Test with UUID error conversion
|
||||
let uuid_result = uuid::Uuid::parse_str("invalid-uuid-format");
|
||||
assert!(uuid_result.is_err());
|
||||
let uuid_error = uuid_result.unwrap_err();
|
||||
let filemeta_error: Error = uuid_error.into();
|
||||
|
||||
match filemeta_error {
|
||||
Error::UuidParse(message) => {
|
||||
assert!(message.contains("invalid"));
|
||||
}
|
||||
_ => panic!("Expected UuidParse variant"),
|
||||
}
|
||||
|
||||
// Test with time error conversion
|
||||
use time::{Date, Month};
|
||||
let time_result = Date::from_calendar_date(2023, Month::January, 32); // Invalid day
|
||||
assert!(time_result.is_err());
|
||||
let time_error = time_result.unwrap_err();
|
||||
let filemeta_error2: Error = time_error.into();
|
||||
|
||||
match filemeta_error2 {
|
||||
Error::TimeComponentRange(message) => {
|
||||
assert!(message.contains("range"));
|
||||
}
|
||||
_ => panic!("Expected TimeComponentRange variant"),
|
||||
}
|
||||
|
||||
// Test with UTF8 error conversion
|
||||
let utf8_result = std::string::String::from_utf8(vec![0xFF]);
|
||||
assert!(utf8_result.is_err());
|
||||
let utf8_error = utf8_result.unwrap_err();
|
||||
let filemeta_error3: Error = utf8_error.into();
|
||||
|
||||
match filemeta_error3 {
|
||||
Error::FromUtf8(message) => {
|
||||
assert!(message.contains("utf"));
|
||||
}
|
||||
_ => panic!("Expected FromUtf8 variant"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_filemeta_error_equality_with_io_errors() {
|
||||
// Test equality comparison for Io variants
|
||||
let io_error1 = IoError::new(ErrorKind::NotFound, "test message");
|
||||
let io_error2 = IoError::new(ErrorKind::NotFound, "test message");
|
||||
let io_error3 = IoError::new(ErrorKind::PermissionDenied, "test message");
|
||||
let io_error4 = IoError::new(ErrorKind::NotFound, "different message");
|
||||
|
||||
let filemeta_error1 = Error::Io(io_error1);
|
||||
let filemeta_error2 = Error::Io(io_error2);
|
||||
let filemeta_error3 = Error::Io(io_error3);
|
||||
let filemeta_error4 = Error::Io(io_error4);
|
||||
|
||||
// Same kind and message should be equal
|
||||
assert_eq!(filemeta_error1, filemeta_error2);
|
||||
|
||||
// Different kinds should not be equal
|
||||
assert_ne!(filemeta_error1, filemeta_error3);
|
||||
|
||||
// Different messages should not be equal
|
||||
assert_ne!(filemeta_error1, filemeta_error4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_filemeta_error_clone_io_variants() {
|
||||
let io_error = IoError::new(ErrorKind::ConnectionReset, "connection lost");
|
||||
let original_error = Error::Io(io_error);
|
||||
let cloned_error = original_error.clone();
|
||||
|
||||
// Cloned error should be equal to original
|
||||
assert_eq!(original_error, cloned_error);
|
||||
|
||||
// Both should maintain the same properties
|
||||
match (original_error, cloned_error) {
|
||||
(Error::Io(orig_io), Error::Io(cloned_io)) => {
|
||||
assert_eq!(orig_io.kind(), cloned_io.kind());
|
||||
assert_eq!(orig_io.to_string(), cloned_io.to_string());
|
||||
}
|
||||
_ => panic!("Both should be Io variants"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,11 +27,7 @@ impl InlineData {
|
||||
}
|
||||
|
||||
pub fn after_version(&self) -> &[u8] {
|
||||
if self.0.is_empty() {
|
||||
&self.0
|
||||
} else {
|
||||
&self.0[1..]
|
||||
}
|
||||
if self.0.is_empty() { &self.0 } else { &self.0[1..] }
|
||||
}
|
||||
|
||||
pub fn find(&self, key: &str) -> Result<Option<Vec<u8>>> {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::error::{Error, Result};
|
||||
use crate::{merge_file_meta_versions, FileInfo, FileInfoVersions, FileMeta, FileMetaShallowVersion, VersionType};
|
||||
use crate::{FileInfo, FileInfoVersions, FileMeta, FileMetaShallowVersion, VersionType, merge_file_meta_versions};
|
||||
use rmp::Marker;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::cmp::Ordering;
|
||||
@@ -10,8 +10,8 @@ use std::{
|
||||
pin::Pin,
|
||||
ptr,
|
||||
sync::{
|
||||
atomic::{AtomicPtr, AtomicU64, Ordering as AtomicOrdering},
|
||||
Arc,
|
||||
atomic::{AtomicPtr, AtomicU64, Ordering as AtomicOrdering},
|
||||
},
|
||||
time::{Duration, SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use opentelemetry::global;
|
||||
use rustfs_obs::{get_logger, init_obs, log_info, BaseLogEntry, ServerLogEntry, SystemObserver};
|
||||
use rustfs_obs::{BaseLogEntry, ServerLogEntry, SystemObserver, get_logger, init_obs, log_info};
|
||||
use std::collections::HashMap;
|
||||
use std::time::{Duration, SystemTime};
|
||||
use tracing::{error, info, instrument};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::logger::InitLogStatus;
|
||||
use crate::telemetry::{init_telemetry, OtelGuard};
|
||||
use crate::{get_global_logger, init_global_logger, AppConfig, Logger};
|
||||
use crate::telemetry::{OtelGuard, init_telemetry};
|
||||
use crate::{AppConfig, Logger, get_global_logger, init_global_logger};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use tokio::sync::{OnceCell, SetError};
|
||||
use tracing::{error, info};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::sinks::Sink;
|
||||
use crate::{
|
||||
sinks, AppConfig, AuditLogEntry, BaseLogEntry, ConsoleLogEntry, GlobalError, OtelConfig, ServerLogEntry, UnifiedLogEntry,
|
||||
AppConfig, AuditLogEntry, BaseLogEntry, ConsoleLogEntry, GlobalError, OtelConfig, ServerLogEntry, UnifiedLogEntry, sinks,
|
||||
};
|
||||
use rustfs_config::{APP_NAME, ENVIRONMENT, SERVICE_VERSION};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::sinks::Sink;
|
||||
use crate::UnifiedLogEntry;
|
||||
use crate::sinks::Sink;
|
||||
use async_trait::async_trait;
|
||||
|
||||
/// Webhook Sink Implementation
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use crate::GlobalError;
|
||||
use crate::system::attributes::ProcessAttributes;
|
||||
use crate::system::gpu::GpuCollector;
|
||||
use crate::system::metrics::{Metrics, DIRECTION, INTERFACE, STATUS};
|
||||
use crate::GlobalError;
|
||||
use crate::system::metrics::{DIRECTION, INTERFACE, Metrics, STATUS};
|
||||
use opentelemetry::KeyValue;
|
||||
use std::time::SystemTime;
|
||||
use sysinfo::{Networks, Pid, ProcessStatus, System};
|
||||
use tokio::time::{sleep, Duration};
|
||||
use tokio::time::{Duration, sleep};
|
||||
|
||||
/// Collector is responsible for collecting system metrics and attributes.
|
||||
/// It uses the sysinfo crate to gather information about the system and processes.
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#[cfg(feature = "gpu")]
|
||||
use crate::GlobalError;
|
||||
#[cfg(feature = "gpu")]
|
||||
use crate::system::attributes::ProcessAttributes;
|
||||
#[cfg(feature = "gpu")]
|
||||
use crate::system::metrics::Metrics;
|
||||
#[cfg(feature = "gpu")]
|
||||
use crate::GlobalError;
|
||||
use nvml_wrapper::Nvml;
|
||||
#[cfg(feature = "gpu")]
|
||||
use nvml_wrapper::enums::device::UsedGpuMemory;
|
||||
#[cfg(feature = "gpu")]
|
||||
use nvml_wrapper::Nvml;
|
||||
#[cfg(feature = "gpu")]
|
||||
use sysinfo::Pid;
|
||||
#[cfg(feature = "gpu")]
|
||||
use tracing::warn;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{sinks::Sink, UnifiedLogEntry};
|
||||
use crate::{UnifiedLogEntry, sinks::Sink};
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::mpsc::Receiver;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{Reader, Writer};
|
||||
use pin_project_lite::pin_project;
|
||||
use rustfs_utils::{read_full, write_all, HashAlgorithm};
|
||||
use rustfs_utils::{HashAlgorithm, read_full, write_all};
|
||||
use tokio::io::{AsyncRead, AsyncReadExt};
|
||||
|
||||
pin_project! {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::compress::{compress_block, decompress_block, CompressionAlgorithm};
|
||||
use crate::compress::{CompressionAlgorithm, compress_block, decompress_block};
|
||||
use crate::{EtagResolvable, HashReaderDetector};
|
||||
use crate::{HashReaderMut, Reader};
|
||||
use pin_project_lite::pin_project;
|
||||
|
||||
@@ -284,7 +284,7 @@ impl HashReaderDetector for HashReader {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{encrypt_reader, DecryptReader};
|
||||
use crate::{DecryptReader, encrypt_reader};
|
||||
use std::io::Cursor;
|
||||
use tokio::io::{AsyncReadExt, BufReader};
|
||||
|
||||
|
||||
@@ -396,10 +396,12 @@ mod tests {
|
||||
// Should fail because no certificates found
|
||||
let result = load_all_certs_from_directory(temp_dir.path().to_str().unwrap());
|
||||
assert!(result.is_err());
|
||||
assert!(result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("No valid certificate/private key pair found"));
|
||||
assert!(
|
||||
result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("No valid certificate/private key pair found")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -412,10 +414,12 @@ mod tests {
|
||||
|
||||
let result = load_all_certs_from_directory(unicode_dir.to_str().unwrap());
|
||||
assert!(result.is_err());
|
||||
assert!(result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("No valid certificate/private key pair found"));
|
||||
assert!(
|
||||
result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("No valid certificate/private key pair found")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -114,7 +114,7 @@ mod tests {
|
||||
let data = b"test data";
|
||||
let hash = HashAlgorithm::BLAKE2b512.hash_encode(data);
|
||||
assert_eq!(hash.len(), 32); // blake3 outputs 32 bytes by default
|
||||
// BLAKE2b512 should be deterministic
|
||||
// BLAKE2b512 should be deterministic
|
||||
let hash2 = HashAlgorithm::BLAKE2b512.hash_encode(data);
|
||||
assert_eq!(hash, hash2);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use nix::sys::stat::{self, stat};
|
||||
use nix::sys::statfs::{self, statfs, FsType};
|
||||
use nix::sys::statfs::{self, FsType, statfs};
|
||||
use std::fs::File;
|
||||
use std::io::{self, BufRead, Error, ErrorKind};
|
||||
use std::path::Path;
|
||||
@@ -26,7 +26,7 @@ pub fn get_info(p: impl AsRef<Path>) -> std::io::Result<DiskInfo> {
|
||||
bfree,
|
||||
p.as_ref().display()
|
||||
),
|
||||
))
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -41,7 +41,7 @@ pub fn get_info(p: impl AsRef<Path>) -> std::io::Result<DiskInfo> {
|
||||
blocks,
|
||||
p.as_ref().display()
|
||||
),
|
||||
))
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -57,7 +57,7 @@ pub fn get_info(p: impl AsRef<Path>) -> std::io::Result<DiskInfo> {
|
||||
total,
|
||||
p.as_ref().display()
|
||||
),
|
||||
))
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ pub fn get_info(p: impl AsRef<Path>) -> std::io::Result<DiskInfo> {
|
||||
bavail,
|
||||
bfree,
|
||||
p.as_ref().display()
|
||||
)))
|
||||
)));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -32,7 +32,7 @@ pub fn get_info(p: impl AsRef<Path>) -> std::io::Result<DiskInfo> {
|
||||
reserved,
|
||||
blocks,
|
||||
p.as_ref().display()
|
||||
)))
|
||||
)));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -45,7 +45,7 @@ pub fn get_info(p: impl AsRef<Path>) -> std::io::Result<DiskInfo> {
|
||||
free,
|
||||
total,
|
||||
p.as_ref().display()
|
||||
)))
|
||||
)));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -608,8 +608,8 @@ mod tests {
|
||||
#[tokio::test]
|
||||
async fn test_decompress_with_invalid_format() {
|
||||
// Test decompression with invalid format
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
let sample_content = b"Hello, compression world!";
|
||||
let cursor = Cursor::new(sample_content);
|
||||
@@ -634,8 +634,8 @@ mod tests {
|
||||
#[tokio::test]
|
||||
async fn test_decompress_with_zip_format() {
|
||||
// Test decompression with Zip format (currently not supported)
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
let sample_content = b"Hello, compression world!";
|
||||
let cursor = Cursor::new(sample_content);
|
||||
@@ -660,8 +660,8 @@ mod tests {
|
||||
#[tokio::test]
|
||||
async fn test_decompress_error_propagation() {
|
||||
// Test error propagation during decompression process
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
let sample_content = b"Hello, compression world!";
|
||||
let cursor = Cursor::new(sample_content);
|
||||
@@ -690,8 +690,8 @@ mod tests {
|
||||
#[tokio::test]
|
||||
async fn test_decompress_callback_execution() {
|
||||
// Test callback function execution during decompression
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
let sample_content = b"Hello, compression world!";
|
||||
let cursor = Cursor::new(sample_content);
|
||||
|
||||
Reference in New Issue
Block a user