Skip to content

Commit 3ff78fe

Browse files
committed
[V1][Metrics] Fix "Duplicated timeseries" error in test_async_llm.py
Fixes: ValueError: Duplicated timeseries in CollectorRegistry: {'vllm:num_requests_running'} Same solution as in v0 - in case there are multiple engine instances in the same process (only in tests?), just de-register the metrics before registering them. Signed-off-by: Mark McLoughlin <markmc@redhat.com>
1 parent 3a5426a commit 3ff78fe

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

vllm/v1/metrics/loggers.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def __init__(self, labels: Dict[str, str]):
4949
labelnames = self.labels.keys()
5050
labelvalues = self.labels.values()
5151

52+
self._unregister_vllm_metrics()
53+
5254
self.gauge_scheduler_running = prometheus_client.Gauge(
5355
name="vllm:num_requests_running",
5456
documentation="Number of requests in model execution batches.",
@@ -63,3 +65,10 @@ def log(self, scheduler_stats: SchedulerStats):
6365
"""Log to prometheus."""
6466
self.gauge_scheduler_running.set(scheduler_stats.num_running_reqs)
6567
self.gauge_scheduler_waiting.set(scheduler_stats.num_waiting_reqs)
68+
69+
@staticmethod
70+
def _unregister_vllm_metrics():
71+
# Unregister any existing vLLM collectors (for CI/CD
72+
for collector in list(prometheus_client.REGISTRY._collector_to_names):
73+
if hasattr(collector, "_name") and "vllm" in collector._name:
74+
prometheus_client.REGISTRY.unregister(collector)

0 commit comments

Comments
 (0)