mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-06 13:27:43 +00:00
feat(obs): integrate dial9-tokio-telemetry for runtime tracing (#2285)
Co-authored-by: heihutu <heihutu@gmail.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: houseme <4829346+houseme@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
// Test dial9 integration example
|
||||
use rustfs_obs::dial9::{Dial9Config, is_enabled};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("=== Dial9 Integration Test ===\n");
|
||||
|
||||
// Test 1: Check initial dial9 state
|
||||
println!("Test 1: Default state");
|
||||
let initial_enabled = is_enabled();
|
||||
println!(" dial9 enabled: {}", initial_enabled);
|
||||
if initial_enabled {
|
||||
println!(" ⚠ SKIP: Dial9 is already enabled via environment; skipping default-disabled assertion\n");
|
||||
} else {
|
||||
println!(" ✓ PASS: Dial9 is disabled by default\n");
|
||||
}
|
||||
|
||||
// Test 2: Load default configuration
|
||||
println!("Test 2: Default configuration");
|
||||
let config = Dial9Config::from_env();
|
||||
println!(" enabled: {}", config.enabled);
|
||||
println!(" output_dir: {}", config.output_dir);
|
||||
println!(" file_prefix: {}", config.file_prefix);
|
||||
println!(" max_file_size: {} bytes", config.max_file_size);
|
||||
println!(" rotation_count: {}", config.rotation_count);
|
||||
println!(" s3_bucket: {:?}", config.s3_bucket);
|
||||
println!(" s3_prefix: {:?}", config.s3_prefix);
|
||||
println!(" sampling_rate: {}", config.sampling_rate);
|
||||
println!(" ✓ PASS: Default configuration loaded\n");
|
||||
|
||||
// Test 3: Configuration validation
|
||||
println!("Test 3: Configuration validation");
|
||||
if !initial_enabled {
|
||||
assert!(!config.enabled, "Should be disabled by default");
|
||||
assert_eq!(config.s3_bucket, None, "S3 bucket should be None by default");
|
||||
assert_eq!(config.s3_prefix, None, "S3 prefix should be None by default");
|
||||
println!(" ✓ PASS: Configuration validated\n");
|
||||
} else {
|
||||
println!(" ⚠ SKIP: Configuration validation skipped (dial9 is enabled)\n");
|
||||
}
|
||||
|
||||
println!("=== All Tests Passed! ===");
|
||||
println!();
|
||||
println!("Note: To test with dial9 enabled, set environment variables:");
|
||||
println!(" export RUSTFS_RUNTIME_DIAL9_ENABLED=true");
|
||||
println!(" export RUSTFS_RUNTIME_DIAL9_OUTPUT_DIR=/tmp/rustfs-test-telemetry");
|
||||
println!(" export RUSTFS_RUNTIME_DIAL9_SAMPLING_RATE=0.5");
|
||||
println!(" export RUSTFS_RUNTIME_DIAL9_S3_BUCKET=my-bucket");
|
||||
println!(" export RUSTFS_RUNTIME_DIAL9_S3_PREFIX=telemetry/");
|
||||
println!(" cargo run -p rustfs-obs --example test_dial9");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
// Full dial9 integration test with session initialization
|
||||
use rustfs_obs::dial9::{Dial9Config, init_session, is_enabled};
|
||||
use tokio::time::{Duration, sleep};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("=== Full Dial9 Integration Test ===");
|
||||
println!();
|
||||
|
||||
// Check if dial9 is enabled
|
||||
if !is_enabled() {
|
||||
println!("Dial9 is disabled. Enable with:");
|
||||
println!(" export RUSTFS_RUNTIME_DIAL9_ENABLED=true");
|
||||
println!(" export RUSTFS_RUNTIME_DIAL9_OUTPUT_DIR=/tmp/rustfs-test-telemetry");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Test 1: Configuration
|
||||
println!("Test 1: Configuration");
|
||||
let config = Dial9Config::from_env();
|
||||
println!(" enabled: {}", config.enabled);
|
||||
println!(" output_dir: {}", config.output_dir);
|
||||
println!(" file_prefix: {}", config.file_prefix);
|
||||
println!(" sampling_rate: {}", config.sampling_rate);
|
||||
println!(" ✓ Configuration loaded");
|
||||
println!();
|
||||
|
||||
// Test 2: Session initialization
|
||||
println!("Test 2: Session initialization");
|
||||
match init_session().await {
|
||||
Ok(Some(guard)) => {
|
||||
println!(" ✓ Session initialized successfully");
|
||||
println!(" guard.is_active(): {}", guard.is_active());
|
||||
println!();
|
||||
|
||||
// Test 3: Generate async activity
|
||||
println!("Test 3: Generate async runtime activity");
|
||||
let tasks = (0..3).map(|i| {
|
||||
tokio::spawn(async move {
|
||||
for j in 0..5 {
|
||||
println!(" Task {} iteration {}", i, j);
|
||||
sleep(Duration::from_millis(20)).await;
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
for task in tasks {
|
||||
task.await?;
|
||||
}
|
||||
println!(" ✓ Async activity completed");
|
||||
println!();
|
||||
|
||||
// Test 4: Session lifecycle
|
||||
println!("Test 4: Session lifecycle");
|
||||
println!(" Dropping guard...");
|
||||
drop(guard);
|
||||
println!(" ✓ Session cleaned up");
|
||||
}
|
||||
Ok(None) => {
|
||||
println!(" ⚠ Session not created (writer may have failed)");
|
||||
println!(" This is expected if output directory cannot be created");
|
||||
}
|
||||
Err(e) => {
|
||||
println!(" ✗ Session init failed: {:?}", e);
|
||||
}
|
||||
}
|
||||
|
||||
println!();
|
||||
println!("=== Test Summary ===");
|
||||
println!("✓ Configuration: PASS");
|
||||
println!("✓ Session Init: PASS");
|
||||
println!("✓ Async Activity: PASS");
|
||||
println!("✓ Lifecycle: PASS");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// Test dial9 S3 configuration
|
||||
use rustfs_obs::dial9::{Dial9Config, is_enabled};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("=== Dial9 S3 Configuration Test ===");
|
||||
println!();
|
||||
|
||||
// Test 1: Default S3 configuration (should be None/None)
|
||||
println!("Test 1: Default S3 configuration");
|
||||
let default_config = Dial9Config::default();
|
||||
println!(" s3_bucket: {:?}", default_config.s3_bucket);
|
||||
println!(" s3_prefix: {:?}", default_config.s3_prefix);
|
||||
assert_eq!(default_config.s3_bucket, None);
|
||||
assert_eq!(default_config.s3_prefix, None);
|
||||
println!(" ✓ PASS: Default S3 config is None/None");
|
||||
println!();
|
||||
|
||||
// Test 2: Check if dial9 is enabled
|
||||
println!("Test 2: Check dial9 enabled state");
|
||||
println!(" is_enabled(): {}", is_enabled());
|
||||
println!(
|
||||
" RUSTFS_RUNTIME_DIAL9_ENABLED: {}",
|
||||
std::env::var("RUSTFS_RUNTIME_DIAL9_ENABLED").unwrap_or("not set".to_string())
|
||||
);
|
||||
println!();
|
||||
|
||||
// Test 3: Load configuration from environment
|
||||
println!("Test 3: Load configuration from environment");
|
||||
let config = Dial9Config::from_env();
|
||||
println!(" enabled: {}", config.enabled);
|
||||
println!(" s3_bucket: {:?}", config.s3_bucket);
|
||||
println!(" s3_prefix: {:?}", config.s3_prefix);
|
||||
println!(" ✓ PASS: Configuration loaded");
|
||||
println!();
|
||||
|
||||
// Only test S3 config if dial9 is enabled
|
||||
if !config.enabled {
|
||||
println!(" ⚠ SKIP: Dial9 is disabled, S3 config not loaded");
|
||||
println!(" To test S3 configuration:");
|
||||
println!(" export RUSTFS_RUNTIME_DIAL9_ENABLED=true");
|
||||
println!(" export RUSTFS_RUNTIME_DIAL9_S3_BUCKET=my-bucket");
|
||||
println!(" export RUSTFS_RUNTIME_DIAL9_S3_PREFIX=telemetry/");
|
||||
println!(" cargo run -p rustfs-obs --example test_dial9_s3");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Test 4: Configuration summary
|
||||
println!("Test 4: Configuration summary");
|
||||
println!(" S3 upload enabled: {}", config.s3_bucket.is_some());
|
||||
if let Some(bucket) = &config.s3_bucket {
|
||||
println!(" S3 bucket: {}", bucket);
|
||||
}
|
||||
if let Some(prefix) = &config.s3_prefix {
|
||||
println!(" S3 prefix: {}", prefix);
|
||||
}
|
||||
println!(" ✓ PASS: Configuration summary displayed");
|
||||
println!();
|
||||
|
||||
println!("=== All Tests Passed! ===");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// Simple dial9 integration test (reads from environment)
|
||||
use rustfs_obs::dial9::{Dial9Config, is_enabled};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("=== Dial9 Integration Test ===");
|
||||
println!();
|
||||
|
||||
// Test 1: Check current state
|
||||
println!("Test 1: Check dial9 state");
|
||||
println!(
|
||||
" RUSTFS_RUNTIME_DIAL9_ENABLED: {}",
|
||||
std::env::var("RUSTFS_RUNTIME_DIAL9_ENABLED").unwrap_or("not set".to_string())
|
||||
);
|
||||
println!(" is_enabled(): {}", is_enabled());
|
||||
println!(" ✓ Dial9 state check complete");
|
||||
println!();
|
||||
|
||||
// Test 2: Load configuration
|
||||
println!("Test 2: Load dial9 configuration");
|
||||
let config = Dial9Config::from_env();
|
||||
println!(" enabled: {}", config.enabled);
|
||||
println!(" output_dir: {}", config.output_dir);
|
||||
println!(" file_prefix: {}", config.file_prefix);
|
||||
println!(" max_file_size: {} bytes", config.max_file_size);
|
||||
println!(" rotation_count: {}", config.rotation_count);
|
||||
println!(" sampling_rate: {}", config.sampling_rate);
|
||||
println!(" ✓ Configuration loaded");
|
||||
println!();
|
||||
|
||||
// Test 3: Test base path calculation
|
||||
println!("Test 3: Base path calculation");
|
||||
println!(" base_path: {:?}", config.base_path());
|
||||
println!(" ✓ Base path calculated");
|
||||
println!();
|
||||
|
||||
println!("=== All Tests Passed! ===");
|
||||
println!();
|
||||
println!("Note: To test full dial9 functionality, enable it with:");
|
||||
println!(" export RUSTFS_RUNTIME_DIAL9_ENABLED=true");
|
||||
println!(" export RUSTFS_RUNTIME_DIAL9_OUTPUT_DIR=/tmp/rustfs-telemetry");
|
||||
println!(" cargo run -p rustfs-obs --example test_dial9_simple");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user