Remove unused cache tiers system
This commit is contained in:
parent
89afd9143f
commit
d80f2ce811
2
agent/src/cache/mod.rs
vendored
2
agent/src/cache/mod.rs
vendored
@ -69,7 +69,7 @@ impl ConfigurableCache {
|
||||
let mut to_remove = Vec::new();
|
||||
|
||||
for (metric_name, cached_metric) in cache.iter() {
|
||||
let cache_interval = self.config.get_cache_interval(metric_name);
|
||||
let cache_interval = self.config.default_ttl_seconds;
|
||||
let elapsed = cached_metric.collected_at.elapsed().as_secs();
|
||||
|
||||
// Remove entries that are way past their expiration (2x interval)
|
||||
|
||||
@ -1,12 +1,4 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// Cache tier configuration
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct CacheTier {
|
||||
pub interval_seconds: u64,
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
/// Cache configuration
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
@ -17,80 +9,10 @@ pub struct CacheConfig {
|
||||
pub warming_timeout_seconds: u64,
|
||||
pub background_refresh_enabled: bool,
|
||||
pub cleanup_interval_seconds: u64,
|
||||
pub tiers: HashMap<String, CacheTier>,
|
||||
pub metric_assignments: HashMap<String, String>,
|
||||
}
|
||||
|
||||
impl Default for CacheConfig {
|
||||
fn default() -> Self {
|
||||
let mut tiers = HashMap::new();
|
||||
tiers.insert(
|
||||
"realtime".to_string(),
|
||||
CacheTier {
|
||||
interval_seconds: 2,
|
||||
description: "Memory/CPU operations - no disk I/O (CPU, memory, service CPU/RAM)"
|
||||
.to_string(),
|
||||
},
|
||||
);
|
||||
tiers.insert(
|
||||
"disk_light".to_string(),
|
||||
CacheTier {
|
||||
interval_seconds: 10,
|
||||
description: "Light disk operations - 10 seconds (service status checks)".to_string(),
|
||||
},
|
||||
);
|
||||
tiers.insert(
|
||||
"disk_medium".to_string(),
|
||||
CacheTier {
|
||||
interval_seconds: 60,
|
||||
description: "Medium disk operations - 1 minute (disk usage, service disk)"
|
||||
.to_string(),
|
||||
},
|
||||
);
|
||||
tiers.insert(
|
||||
"disk_heavy".to_string(),
|
||||
CacheTier {
|
||||
interval_seconds: 60,
|
||||
description: "Heavy disk operations - 1 minute (backup status)"
|
||||
.to_string(),
|
||||
},
|
||||
);
|
||||
tiers.insert(
|
||||
"static".to_string(),
|
||||
CacheTier {
|
||||
interval_seconds: 600,
|
||||
description: "SMART data operations - 10 minutes".to_string(),
|
||||
},
|
||||
);
|
||||
|
||||
let mut metric_assignments = HashMap::new();
|
||||
|
||||
// REALTIME (2s) - Memory/CPU operations, no disk I/O
|
||||
metric_assignments.insert("cpu_load_*".to_string(), "realtime".to_string());
|
||||
metric_assignments.insert("cpu_temperature_*".to_string(), "realtime".to_string());
|
||||
metric_assignments.insert("cpu_frequency_*".to_string(), "realtime".to_string());
|
||||
metric_assignments.insert("memory_*".to_string(), "realtime".to_string());
|
||||
metric_assignments.insert("service_*_cpu_percent".to_string(), "realtime".to_string());
|
||||
metric_assignments.insert("service_*_memory_mb".to_string(), "realtime".to_string());
|
||||
metric_assignments.insert("network_*".to_string(), "realtime".to_string());
|
||||
|
||||
// DISK_LIGHT (1min) - Light disk operations: service status checks
|
||||
metric_assignments.insert("service_*_status".to_string(), "disk_light".to_string());
|
||||
|
||||
// DISK_MEDIUM (5min) - Medium disk operations: du commands, disk usage
|
||||
metric_assignments.insert("service_*_disk_gb".to_string(), "disk_medium".to_string());
|
||||
metric_assignments.insert("disk_tmp_*".to_string(), "disk_medium".to_string());
|
||||
metric_assignments.insert("disk_*_usage_*".to_string(), "disk_medium".to_string());
|
||||
metric_assignments.insert("disk_*_size_*".to_string(), "disk_medium".to_string());
|
||||
|
||||
// DISK_HEAVY (1min) - Heavy disk operations: backup status
|
||||
metric_assignments.insert("backup_*".to_string(), "disk_heavy".to_string());
|
||||
|
||||
// STATIC (10min) - SMART data operations
|
||||
metric_assignments.insert("disk_*_temperature".to_string(), "static".to_string());
|
||||
metric_assignments.insert("disk_*_wear_percent".to_string(), "static".to_string());
|
||||
metric_assignments.insert("smart_*".to_string(), "static".to_string());
|
||||
|
||||
Self {
|
||||
enabled: true,
|
||||
default_ttl_seconds: 30,
|
||||
@ -98,94 +20,7 @@ impl Default for CacheConfig {
|
||||
warming_timeout_seconds: 3,
|
||||
background_refresh_enabled: true,
|
||||
cleanup_interval_seconds: 1800,
|
||||
tiers,
|
||||
metric_assignments,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CacheConfig {
|
||||
/// Get the cache tier for a metric name
|
||||
pub fn get_tier_for_metric(&self, metric_name: &str) -> Option<&CacheTier> {
|
||||
// Find matching pattern
|
||||
for (pattern, tier_name) in &self.metric_assignments {
|
||||
if self.matches_pattern(metric_name, pattern) {
|
||||
return self.tiers.get(tier_name);
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Check if metric name matches pattern (supports wildcards)
|
||||
fn matches_pattern(&self, metric_name: &str, pattern: &str) -> bool {
|
||||
if pattern.contains('*') {
|
||||
// Convert pattern to regex-like matching
|
||||
let pattern_parts: Vec<&str> = pattern.split('*').collect();
|
||||
|
||||
if pattern_parts.len() == 2 {
|
||||
let prefix = pattern_parts[0];
|
||||
let suffix = pattern_parts[1];
|
||||
|
||||
if suffix.is_empty() {
|
||||
// Pattern like "cpu_*" - just check prefix
|
||||
metric_name.starts_with(prefix)
|
||||
} else if prefix.is_empty() {
|
||||
// Pattern like "*_status" - just check suffix
|
||||
metric_name.ends_with(suffix)
|
||||
} else {
|
||||
// Pattern like "service_*_disk_gb" - check prefix and suffix
|
||||
metric_name.starts_with(prefix) && metric_name.ends_with(suffix)
|
||||
}
|
||||
} else {
|
||||
// More complex patterns - for now, just check if all parts are present
|
||||
pattern_parts
|
||||
.iter()
|
||||
.all(|part| part.is_empty() || metric_name.contains(part))
|
||||
}
|
||||
} else {
|
||||
metric_name == pattern
|
||||
}
|
||||
}
|
||||
|
||||
/// Get cache interval for a metric
|
||||
pub fn get_cache_interval(&self, metric_name: &str) -> u64 {
|
||||
self.get_tier_for_metric(metric_name)
|
||||
.map(|tier| tier.interval_seconds)
|
||||
.unwrap_or(self.default_ttl_seconds)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_pattern_matching() {
|
||||
let config = CacheConfig::default();
|
||||
|
||||
assert!(config.matches_pattern("cpu_load_1min", "cpu_load_*"));
|
||||
assert!(config.matches_pattern("service_nginx_disk_gb", "service_*_disk_gb"));
|
||||
assert!(!config.matches_pattern("memory_usage_percent", "cpu_load_*"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tier_assignment() {
|
||||
let config = CacheConfig::default();
|
||||
|
||||
// Realtime (2s) - CPU/Memory operations
|
||||
assert_eq!(config.get_cache_interval("cpu_load_1min"), 2);
|
||||
assert_eq!(config.get_cache_interval("memory_usage_percent"), 2);
|
||||
assert_eq!(config.get_cache_interval("service_nginx_cpu_percent"), 2);
|
||||
|
||||
// Disk light (10s) - Service status
|
||||
assert_eq!(config.get_cache_interval("service_nginx_status"), 10);
|
||||
|
||||
// Disk medium (60s) - Disk usage
|
||||
assert_eq!(config.get_cache_interval("service_nginx_disk_gb"), 60);
|
||||
assert_eq!(config.get_cache_interval("disk_tmp_usage_percent"), 60);
|
||||
|
||||
// Static (600s) - SMART data
|
||||
assert_eq!(config.get_cache_interval("disk_nvme0_temperature"), 600);
|
||||
assert_eq!(config.get_cache_interval("smart_nvme0_wear_percent"), 600);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user