Fix router keep nonzero metrics after worker is deleted (#14819)

This commit is contained in:
fzyzcjy
2025-12-10 22:29:30 +08:00
committed by GitHub
parent 5eccaf7737
commit 6634f67bd5
2 changed files with 11 additions and 1 deletions

View File

@@ -8,6 +8,7 @@ use dashmap::DashMap;
use uuid::Uuid;
use crate::core::{ConnectionMode, RuntimeType, Worker, WorkerType};
use crate::observability::metrics::RouterMetrics;
/// Unique identifier for a worker
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
@@ -138,8 +139,8 @@ impl WorkerRegistry {
conn_workers.retain(|id| id != worker_id);
}
// TODO we may even remove it from Prometheus exports
worker.set_healthy(false);
RouterMetrics::remove_worker_metrics(worker.url());
Some(worker)
} else {

View File

@@ -536,6 +536,15 @@ impl RouterMetrics {
.increment(1);
}
// TODO delete the metrics (instead of setting them to zero)
pub fn remove_worker_metrics(worker_url: &str) {
gauge!("sgl_router_cb_state","worker" => worker_url.to_string()).set(0.0);
gauge!("sgl_router_worker_health","worker" => worker_url.to_string()).set(0.0);
gauge!("sgl_router_worker_load","worker" => worker_url.to_string()).set(0.0);
gauge!("sgl_router_running_requests","worker" => worker_url.to_string()).set(0.0);
gauge!("sgl_router_tree_size","worker" => worker_url.to_string()).set(0.0);
}
pub fn set_job_queue_depth(depth: usize) {
gauge!("sgl_router_job_queue_depth").set(depth as f64);
}