[router] add metrics for worker and policy (#8971)

Signed-off-by: Tony Lu <tonyluj@gmail.com>
This commit is contained in:
Tony Lu
2025-08-09 04:41:40 +08:00
committed by GitHub
parent 91e2f902db
commit 36bfddecb9
5 changed files with 13 additions and 0 deletions

View File

@@ -2,6 +2,7 @@
use super::{get_healthy_worker_indices, LoadBalancingPolicy};
use crate::core::Worker;
use crate::metrics::RouterMetrics;
use std::sync::atomic::{AtomicUsize, Ordering};
/// Round-robin selection policy
@@ -35,7 +36,10 @@ impl LoadBalancingPolicy for RoundRobinPolicy {
// Get and increment counter atomically
let count = self.counter.fetch_add(1, Ordering::Relaxed);
let selected_idx = count % healthy_indices.len();
let worker = workers[healthy_indices[selected_idx]].url();
RouterMetrics::record_processed_request(worker);
RouterMetrics::record_policy_decision(self.name(), worker);
Some(healthy_indices[selected_idx])
}