Testing
This commit is contained in:
parent
5e8a0ce108
commit
859df2dec1
@ -114,7 +114,7 @@ impl ServiceCollector {
|
||||
sandbox_limit: None, // TODO: Implement sandbox limit detection
|
||||
disk_used_gb,
|
||||
description,
|
||||
sub_service: false,
|
||||
sub_service: None,
|
||||
})
|
||||
}
|
||||
|
||||
@ -834,7 +834,7 @@ impl Collector for ServiceCollector {
|
||||
sandbox_limit: None,
|
||||
disk_used_gb: 0.0,
|
||||
description: None,
|
||||
sub_service: true,
|
||||
sub_service: Some("nginx".to_string()),
|
||||
});
|
||||
healthy += 1;
|
||||
}
|
||||
@ -855,7 +855,7 @@ impl Collector for ServiceCollector {
|
||||
sandbox_limit: None,
|
||||
disk_used_gb: 0.0,
|
||||
description: None,
|
||||
sub_service: false,
|
||||
sub_service: None,
|
||||
});
|
||||
tracing::warn!("Failed to collect metrics for service {}: {}", service, e);
|
||||
}
|
||||
@ -915,7 +915,7 @@ struct ServiceData {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
description: Option<Vec<String>>,
|
||||
#[serde(default)]
|
||||
sub_service: bool,
|
||||
sub_service: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
|
||||
@ -117,7 +117,7 @@ pub struct ServiceInfo {
|
||||
#[serde(default)]
|
||||
pub description: Option<Vec<String>>,
|
||||
#[serde(default)]
|
||||
pub sub_service: bool,
|
||||
pub sub_service: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
|
||||
@ -69,42 +69,25 @@ fn render_metrics(
|
||||
return;
|
||||
}
|
||||
|
||||
// Sort services but preserve nginx + sites grouping
|
||||
let mut services = Vec::new();
|
||||
let mut regular_services = Vec::new();
|
||||
let mut nginx_group = Vec::new();
|
||||
let mut in_nginx_group = false;
|
||||
|
||||
for svc in metrics.services.iter() {
|
||||
if svc.name == "nginx" {
|
||||
// Start nginx group
|
||||
in_nginx_group = true;
|
||||
nginx_group.push(svc.clone());
|
||||
} else if in_nginx_group && svc.sub_service {
|
||||
// Add nginx site to group
|
||||
nginx_group.push(svc.clone());
|
||||
} else {
|
||||
// End nginx group if we were in one
|
||||
if in_nginx_group {
|
||||
in_nginx_group = false;
|
||||
services.append(&mut nginx_group);
|
||||
let mut services = metrics.services.clone();
|
||||
services.sort_by(|a, b| {
|
||||
// First, determine the primary service name for grouping
|
||||
let primary_a = a.sub_service.as_ref().unwrap_or(&a.name);
|
||||
let primary_b = b.sub_service.as_ref().unwrap_or(&b.name);
|
||||
|
||||
// Sort by primary service name first
|
||||
match primary_a.cmp(primary_b) {
|
||||
std::cmp::Ordering::Equal => {
|
||||
// Same primary service, put parent service first, then sub-services alphabetically
|
||||
match (a.sub_service.as_ref(), b.sub_service.as_ref()) {
|
||||
(None, Some(_)) => std::cmp::Ordering::Less, // Parent comes before sub-services
|
||||
(Some(_), None) => std::cmp::Ordering::Greater, // Sub-services come after parent
|
||||
_ => a.name.cmp(&b.name), // Both same type, sort by name
|
||||
}
|
||||
}
|
||||
regular_services.push(svc.clone());
|
||||
other => other, // Different primary services, sort alphabetically
|
||||
}
|
||||
}
|
||||
|
||||
// Add any remaining nginx group
|
||||
if !nginx_group.is_empty() {
|
||||
services.append(&mut nginx_group);
|
||||
}
|
||||
|
||||
// Sort regular services and add them
|
||||
regular_services.sort_by(|a, b| {
|
||||
status_weight(&a.status)
|
||||
.cmp(&status_weight(&b.status))
|
||||
.then_with(|| a.name.cmp(&b.name))
|
||||
});
|
||||
services.append(&mut regular_services);
|
||||
|
||||
for svc in services {
|
||||
let status_level = match svc.status {
|
||||
@ -121,7 +104,7 @@ fn render_metrics(
|
||||
vec![]
|
||||
};
|
||||
|
||||
if svc.sub_service {
|
||||
if svc.sub_service.is_some() {
|
||||
// Sub-services only show name and status, no memory/CPU/disk data
|
||||
data.add_row(
|
||||
Some(WidgetStatus::new(status_level)),
|
||||
@ -151,14 +134,6 @@ fn render_metrics(
|
||||
render_widget_data(frame, area, data);
|
||||
}
|
||||
|
||||
fn status_weight(status: &ServiceStatus) -> i32 {
|
||||
match status {
|
||||
ServiceStatus::Stopped => 0,
|
||||
ServiceStatus::Degraded => 1,
|
||||
ServiceStatus::Restarting => 2,
|
||||
ServiceStatus::Running => 3,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn format_memory_value(used: f32, quota: f32) -> String {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user