Skip to content

Commit edda095

Browse files
committed
refactor: make register_prometheus_metrics idempotent
1 parent 5e41a2d commit edda095

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

lib/llm/src/kv_router/publisher.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -582,18 +582,17 @@ impl WorkerMetricsPublisher {
582582

583583
/// Register KvStats Prometheus metrics with the component's registry
584584
pub fn register_prometheus_metrics(&self, component: &Component) -> Result<()> {
585-
// Create new KvStatsPrometheusGauges with registered metrics
586-
let new_gauges = Arc::new(KvStatsPrometheusGauges::new(component)?);
587-
588-
// Use write lock only for initialization (happens once)
589-
if let Ok(mut gauges) = self.prometheus_gauges.write() {
590-
*gauges = Some(new_gauges);
591-
Ok(())
592-
} else {
593-
Err(anyhow::anyhow!(
594-
"Failed to acquire write lock on prometheus_gauges"
595-
))
585+
let mut gauges = self
586+
.prometheus_gauges
587+
.write()
588+
.map_err(|_| anyhow::anyhow!("Failed to acquire write lock on prometheus_gauges"))?;
589+
590+
// Only initialize if not already done
591+
if gauges.is_none() {
592+
*gauges = Some(Arc::new(KvStatsPrometheusGauges::new(component)?));
596593
}
594+
595+
Ok(())
597596
}
598597

599598
pub async fn create_endpoint(

0 commit comments

Comments
 (0)