mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-13 08:36:54 +00:00
test(io-metrics): assert metric emission in six modules of record_* smoke tests (#6021)
This commit is contained in:
@@ -315,6 +315,44 @@ impl Default for AccessTracker {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// Replaces the per-helper smoke tests that called the record_* helpers
|
||||
/// and asserted nothing: the calls (same literals) now run against a local
|
||||
/// DebuggingRecorder and every metric name the helpers own must actually
|
||||
/// be emitted (rustfs/backlog#1836 PR3).
|
||||
#[test]
|
||||
fn record_helpers_emit_their_metrics() {
|
||||
let recorder = metrics_util::debugging::DebuggingRecorder::new();
|
||||
let snapshotter = recorder.snapshotter();
|
||||
metrics::with_local_recorder(&recorder, || {
|
||||
record_ttl_adjustment("test-key", 100, 150);
|
||||
record_ttl_adjustment("test-key", 100, 50);
|
||||
record_ttl_expiration();
|
||||
record_early_eviction("cold");
|
||||
record_early_eviction("low_priority");
|
||||
record_access_pattern_change("sequential", "random");
|
||||
record_access_pattern_change("random", "sequential");
|
||||
});
|
||||
|
||||
let emitted: std::collections::HashSet<String> = snapshotter
|
||||
.snapshot()
|
||||
.into_vec()
|
||||
.into_iter()
|
||||
.map(|(composite, _, _, _)| composite.key().name().to_string())
|
||||
.collect();
|
||||
for expected in [
|
||||
"rustfs_cache_ttl_adjustments",
|
||||
"rustfs_cache_ttl_base",
|
||||
"rustfs_cache_ttl_adjusted",
|
||||
"rustfs_cache_ttl_extensions",
|
||||
"rustfs_cache_ttl_reductions",
|
||||
"rustfs_cache_ttl_expirations",
|
||||
"rustfs_cache_evictions_early",
|
||||
"rustfs_cache_access_pattern_changes",
|
||||
] {
|
||||
assert!(emitted.contains(expected), "{expected} must be emitted by its record helper");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_adaptive_ttl_stats() {
|
||||
let mut stats = AdaptiveTTLStats::new();
|
||||
@@ -335,30 +373,6 @@ mod tests {
|
||||
assert!((stats.reduction_rate() - 0.3333333333333333).abs() < 0.01);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_record_ttl_adjustment() {
|
||||
// This test verifies the function compiles and runs
|
||||
record_ttl_adjustment("test-key", 100, 150);
|
||||
record_ttl_adjustment("test-key", 100, 50);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_record_ttl_expiration() {
|
||||
record_ttl_expiration();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_record_early_eviction() {
|
||||
record_early_eviction("cold");
|
||||
record_early_eviction("low_priority");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_record_access_pattern_change() {
|
||||
record_access_pattern_change("sequential", "random");
|
||||
record_access_pattern_change("random", "sequential");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_access_record() {
|
||||
let mut record = AccessRecord::new();
|
||||
|
||||
@@ -53,30 +53,38 @@ pub fn record_backpressure_deactivation() {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// Replaces the per-helper smoke tests that called the record_* helpers
|
||||
/// and asserted nothing: the calls (same literals) now run against a local
|
||||
/// DebuggingRecorder and every metric name the helpers own must actually
|
||||
/// be emitted (rustfs/backlog#1836 PR3).
|
||||
#[test]
|
||||
fn test_record_backpressure_state_change() {
|
||||
record_backpressure_state_change("normal", "warning");
|
||||
record_backpressure_state_change("warning", "critical");
|
||||
}
|
||||
fn record_helpers_emit_their_metrics() {
|
||||
let recorder = metrics_util::debugging::DebuggingRecorder::new();
|
||||
let snapshotter = recorder.snapshotter();
|
||||
metrics::with_local_recorder(&recorder, || {
|
||||
record_backpressure_state_change("normal", "warning");
|
||||
record_backpressure_state_change("warning", "critical");
|
||||
record_backpressure_rejection();
|
||||
record_concurrent_operations(10);
|
||||
record_concurrent_operations(32);
|
||||
record_backpressure_activation();
|
||||
record_backpressure_deactivation();
|
||||
});
|
||||
|
||||
#[test]
|
||||
fn test_record_backpressure_rejection() {
|
||||
record_backpressure_rejection();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_record_concurrent_operations() {
|
||||
record_concurrent_operations(10);
|
||||
record_concurrent_operations(32);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_record_backpressure_activation() {
|
||||
record_backpressure_activation();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_record_backpressure_deactivation() {
|
||||
record_backpressure_deactivation();
|
||||
let emitted: std::collections::HashSet<String> = snapshotter
|
||||
.snapshot()
|
||||
.into_vec()
|
||||
.into_iter()
|
||||
.map(|(composite, _, _, _)| composite.key().name().to_string())
|
||||
.collect();
|
||||
for expected in [
|
||||
"rustfs_backpressure_state_changes",
|
||||
"rustfs_backpressure_rejections",
|
||||
"rustfs_backpressure_concurrent",
|
||||
"rustfs_backpressure_activations",
|
||||
"rustfs_backpressure_deactivations",
|
||||
] {
|
||||
assert!(emitted.contains(expected), "{expected} must be emitted by its record helper");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,39 +72,48 @@ pub fn record_wait_edge_removed() {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// Replaces the per-helper smoke tests that called the record_* helpers
|
||||
/// and asserted nothing: the calls (same literals) now run against a local
|
||||
/// DebuggingRecorder and every metric name the helpers own must actually
|
||||
/// be emitted (rustfs/backlog#1836 PR3).
|
||||
#[test]
|
||||
fn test_record_deadlock_detected() {
|
||||
record_deadlock_detected(3);
|
||||
record_deadlock_detected(5);
|
||||
}
|
||||
fn record_helpers_emit_their_metrics() {
|
||||
let recorder = metrics_util::debugging::DebuggingRecorder::new();
|
||||
let snapshotter = recorder.snapshotter();
|
||||
metrics::with_local_recorder(&recorder, || {
|
||||
record_deadlock_detected(3);
|
||||
record_deadlock_detected(5);
|
||||
record_long_held_lock(1, Duration::from_secs(30));
|
||||
record_long_held_lock(2, Duration::from_secs(60));
|
||||
record_lock_acquisition("mutex");
|
||||
record_lock_acquisition("rwlock");
|
||||
record_lock_release("mutex", Duration::from_millis(10));
|
||||
record_lock_release("rwlock", Duration::from_millis(5));
|
||||
record_lock_contention("mutex");
|
||||
record_lock_contention("rwlock");
|
||||
record_wait_edge_added();
|
||||
record_wait_edge_removed();
|
||||
});
|
||||
|
||||
#[test]
|
||||
fn test_record_long_held_lock() {
|
||||
record_long_held_lock(1, Duration::from_secs(30));
|
||||
record_long_held_lock(2, Duration::from_secs(60));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_record_lock_acquisition() {
|
||||
record_lock_acquisition("mutex");
|
||||
record_lock_acquisition("rwlock");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_record_lock_release() {
|
||||
record_lock_release("mutex", Duration::from_millis(10));
|
||||
record_lock_release("rwlock", Duration::from_millis(5));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_record_lock_contention() {
|
||||
record_lock_contention("mutex");
|
||||
record_lock_contention("rwlock");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_record_wait_edge() {
|
||||
record_wait_edge_added();
|
||||
record_wait_edge_removed();
|
||||
let emitted: std::collections::HashSet<String> = snapshotter
|
||||
.snapshot()
|
||||
.into_vec()
|
||||
.into_iter()
|
||||
.map(|(composite, _, _, _)| composite.key().name().to_string())
|
||||
.collect();
|
||||
for expected in [
|
||||
"rustfs_deadlock_detected_total",
|
||||
"rustfs_deadlock_cycle_length",
|
||||
"rustfs_deadlock_long_held",
|
||||
"rustfs_deadlock_hold_time_secs",
|
||||
"rustfs_lock_acquisitions",
|
||||
"rustfs_lock_releases",
|
||||
"rustfs_lock_hold_time_secs",
|
||||
"rustfs_lock_contentions",
|
||||
"rustfs_deadlock_wait_edges_added",
|
||||
"rustfs_deadlock_wait_edges_removed",
|
||||
] {
|
||||
assert!(emitted.contains(expected), "{expected} must be emitted by its record helper");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,46 +169,58 @@ impl IoSchedulerStats {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// Replaces the per-helper smoke tests that called the record_* helpers
|
||||
/// and asserted nothing: the calls (same literals) now run against a local
|
||||
/// DebuggingRecorder and every metric name the helpers own must actually
|
||||
/// be emitted (rustfs/backlog#1836 PR3).
|
||||
#[test]
|
||||
fn test_record_io_scheduler_decision() {
|
||||
record_io_scheduler_decision(128 * 1024, "low", "sequential");
|
||||
record_io_scheduler_decision(64 * 1024, "high", "random");
|
||||
}
|
||||
fn record_helpers_emit_their_metrics() {
|
||||
let recorder = metrics_util::debugging::DebuggingRecorder::new();
|
||||
let snapshotter = recorder.snapshotter();
|
||||
metrics::with_local_recorder(&recorder, || {
|
||||
record_io_scheduler_decision(128 * 1024, "low", "sequential");
|
||||
record_io_scheduler_decision(64 * 1024, "high", "random");
|
||||
record_io_priority_decision("high", 1024);
|
||||
record_io_priority_decision("normal", 1024 * 1024);
|
||||
record_io_priority_decision("low", 10 * 1024 * 1024);
|
||||
record_load_level_change("low", "medium");
|
||||
record_load_level_change("medium", "high");
|
||||
record_bandwidth_observation(100 * 1024 * 1024);
|
||||
record_bandwidth_observation(500 * 1024 * 1024);
|
||||
record_buffer_size_adjustment(128 * 1024, 64 * 1024, "concurrency");
|
||||
record_buffer_size_adjustment(128 * 1024, 256 * 1024, "sequential");
|
||||
record_queue_operation("enqueue", "high", 10);
|
||||
record_queue_operation("dequeue", "high", 9);
|
||||
record_starvation_event("low");
|
||||
});
|
||||
|
||||
#[test]
|
||||
fn test_record_io_priority_decision() {
|
||||
record_io_priority_decision("high", 1024);
|
||||
record_io_priority_decision("normal", 1024 * 1024);
|
||||
record_io_priority_decision("low", 10 * 1024 * 1024);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_record_load_level_change() {
|
||||
record_load_level_change("low", "medium");
|
||||
record_load_level_change("medium", "high");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_record_bandwidth_observation() {
|
||||
record_bandwidth_observation(100 * 1024 * 1024);
|
||||
record_bandwidth_observation(500 * 1024 * 1024);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_record_buffer_size_adjustment() {
|
||||
record_buffer_size_adjustment(128 * 1024, 64 * 1024, "concurrency");
|
||||
record_buffer_size_adjustment(128 * 1024, 256 * 1024, "sequential");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_record_queue_operation() {
|
||||
record_queue_operation("enqueue", "high", 10);
|
||||
record_queue_operation("dequeue", "high", 9);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_record_starvation_event() {
|
||||
record_starvation_event("low");
|
||||
let emitted: std::collections::HashSet<String> = snapshotter
|
||||
.snapshot()
|
||||
.into_vec()
|
||||
.into_iter()
|
||||
.map(|(composite, _, _, _)| composite.key().name().to_string())
|
||||
.collect();
|
||||
for expected in [
|
||||
"rustfs_io_scheduler_decisions",
|
||||
"rustfs_io_scheduler_buffer_size",
|
||||
"rustfs_io_scheduler_load",
|
||||
"rustfs_io_scheduler_strategy",
|
||||
"rustfs_io_scheduler_buffer_size_histogram",
|
||||
"rustfs_io_priority_decisions",
|
||||
"rustfs_io_priority_by_level",
|
||||
"rustfs_io_priority_request_size",
|
||||
"rustfs_io_load_changes",
|
||||
"rustfs_io_bandwidth_bps",
|
||||
"rustfs_io_bandwidth_histogram",
|
||||
"rustfs_io_buffer_adjustments",
|
||||
"rustfs_io_buffer_original",
|
||||
"rustfs_io_buffer_adjusted",
|
||||
"rustfs_io_queue_operations",
|
||||
"rustfs_io_queue_size",
|
||||
"rustfs_io_starvation_events",
|
||||
] {
|
||||
assert!(emitted.contains(expected), "{expected} must be emitted by its record helper");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -163,6 +163,46 @@ impl LockMetricsSummary {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// Replaces the per-helper smoke tests that called the record_* helpers
|
||||
/// and asserted nothing: the calls (same literals) now run against a local
|
||||
/// DebuggingRecorder and every metric name the helpers own must actually
|
||||
/// be emitted (rustfs/backlog#1836 PR3).
|
||||
#[test]
|
||||
fn record_helpers_emit_their_metrics() {
|
||||
let recorder = metrics_util::debugging::DebuggingRecorder::new();
|
||||
let snapshotter = recorder.snapshotter();
|
||||
metrics::with_local_recorder(&recorder, || {
|
||||
record_lock_optimization_enabled(true);
|
||||
record_lock_optimization_enabled(false);
|
||||
record_spin_attempt(true);
|
||||
record_spin_attempt(false);
|
||||
record_spin_count_change(100);
|
||||
record_spin_count_change(200);
|
||||
record_lock_hold_time(Duration::from_millis(10));
|
||||
record_lock_hold_time(Duration::from_millis(100));
|
||||
record_early_release();
|
||||
record_contention_event();
|
||||
});
|
||||
|
||||
let emitted: std::collections::HashSet<String> = snapshotter
|
||||
.snapshot()
|
||||
.into_vec()
|
||||
.into_iter()
|
||||
.map(|(composite, _, _, _)| composite.key().name().to_string())
|
||||
.collect();
|
||||
for expected in [
|
||||
"rustfs_lock_optimization_enabled",
|
||||
"rustfs_lock_spin_successes",
|
||||
"rustfs_lock_spin_failures",
|
||||
"rustfs_lock_spin_count",
|
||||
"rustfs_lock_hold_time_secs",
|
||||
"rustfs_lock_early_releases",
|
||||
"rustfs_lock_contentions",
|
||||
] {
|
||||
assert!(emitted.contains(expected), "{expected} must be emitted by its record helper");
|
||||
}
|
||||
}
|
||||
use metrics::{Counter, CounterFn, Gauge, GaugeFn, Histogram, HistogramFn, Key, KeyName, Metadata, SharedString, Unit};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
@@ -255,40 +295,6 @@ mod tests {
|
||||
fn record(&self, _value: f64) {}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_record_lock_optimization_enabled() {
|
||||
record_lock_optimization_enabled(true);
|
||||
record_lock_optimization_enabled(false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_record_spin_attempt() {
|
||||
record_spin_attempt(true);
|
||||
record_spin_attempt(false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_record_spin_count_change() {
|
||||
record_spin_count_change(100);
|
||||
record_spin_count_change(200);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_record_lock_hold_time() {
|
||||
record_lock_hold_time(Duration::from_millis(10));
|
||||
record_lock_hold_time(Duration::from_millis(100));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_record_early_release() {
|
||||
record_early_release();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_record_contention_event() {
|
||||
record_contention_event();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_record_object_lock_diag_enabled() {
|
||||
let recorder = SeenMetricsRecorder::default();
|
||||
|
||||
@@ -114,39 +114,46 @@ impl TimeoutMetricsSummary {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// Replaces the per-helper smoke tests that called the record_* helpers
|
||||
/// and asserted nothing: the calls (same literals) now run against a local
|
||||
/// DebuggingRecorder and every metric name the helpers own must actually
|
||||
/// be emitted (rustfs/backlog#1836 PR3).
|
||||
#[test]
|
||||
fn test_record_timeout_event() {
|
||||
record_timeout_event("get_object");
|
||||
record_timeout_event("put_object");
|
||||
}
|
||||
fn record_helpers_emit_their_metrics() {
|
||||
let recorder = metrics_util::debugging::DebuggingRecorder::new();
|
||||
let snapshotter = recorder.snapshotter();
|
||||
metrics::with_local_recorder(&recorder, || {
|
||||
record_timeout_event("get_object");
|
||||
record_timeout_event("put_object");
|
||||
record_operation_duration("get_object", Duration::from_millis(100));
|
||||
record_operation_duration("put_object", Duration::from_millis(500));
|
||||
record_dynamic_timeout(1024 * 1024, Duration::from_secs(10));
|
||||
record_dynamic_timeout(100 * 1024 * 1024, Duration::from_secs(30));
|
||||
record_operation_progress("get_object", 50.0);
|
||||
record_operation_progress("get_object", 100.0);
|
||||
record_stalled_operation("get_object");
|
||||
record_operation_completion("get_object", true);
|
||||
record_operation_completion("get_object", false);
|
||||
});
|
||||
|
||||
#[test]
|
||||
fn test_record_operation_duration() {
|
||||
record_operation_duration("get_object", Duration::from_millis(100));
|
||||
record_operation_duration("put_object", Duration::from_millis(500));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_record_dynamic_timeout() {
|
||||
record_dynamic_timeout(1024 * 1024, Duration::from_secs(10));
|
||||
record_dynamic_timeout(100 * 1024 * 1024, Duration::from_secs(30));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_record_operation_progress() {
|
||||
record_operation_progress("get_object", 50.0);
|
||||
record_operation_progress("get_object", 100.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_record_stalled_operation() {
|
||||
record_stalled_operation("get_object");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_record_operation_completion() {
|
||||
record_operation_completion("get_object", true);
|
||||
record_operation_completion("get_object", false);
|
||||
let emitted: std::collections::HashSet<String> = snapshotter
|
||||
.snapshot()
|
||||
.into_vec()
|
||||
.into_iter()
|
||||
.map(|(composite, _, _, _)| composite.key().name().to_string())
|
||||
.collect();
|
||||
for expected in [
|
||||
"rustfs_io_timeout_events_total",
|
||||
"rustfs_io_operation_duration_seconds",
|
||||
"rustfs_timeout_dynamic_size",
|
||||
"rustfs_timeout_dynamic_secs",
|
||||
"rustfs_timeout_dynamic_size_histogram",
|
||||
"rustfs_operation_progress",
|
||||
"rustfs_operation_stalled",
|
||||
"rustfs_operation_completions",
|
||||
] {
|
||||
assert!(emitted.contains(expected), "{expected} must be emitted by its record helper");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user