-
-
Notifications
You must be signed in to change notification settings - Fork 18.9k
[Bugfix][Metrics] Fix RayPrometheusMetric.labels() returning shared labeled child #40840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
6dbe47b
72d3676
741a7ed
aac13e6
b2d058b
b49aed7
6dcbc2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,6 @@ | ||||||||||||
| # SPDX-License-Identifier: Apache-2.0 | ||||||||||||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||||||||||||
| import copy | ||||||||||||
| import time | ||||||||||||
|
|
||||||||||||
| from vllm.distributed.kv_transfer.kv_connector.v1.metrics import KVConnectorProm | ||||||||||||
|
|
@@ -28,6 +29,8 @@ def _get_replica_id() -> str | None: | |||||||||||
|
|
||||||||||||
|
|
||||||||||||
| class RayPrometheusMetric: | ||||||||||||
| _tags: dict[str, str] | None = None | ||||||||||||
|
|
||||||||||||
| def __init__(self): | ||||||||||||
| if ray_metrics is None: | ||||||||||||
| raise ImportError("RayPrometheusMetric requires Ray to be installed.") | ||||||||||||
|
|
@@ -39,7 +42,7 @@ def _get_tag_keys(labelnames: list[str] | None) -> tuple[str, ...]: | |||||||||||
| labels.append("ReplicaId") | ||||||||||||
| return tuple(labels) | ||||||||||||
|
|
||||||||||||
| def labels(self, *labels, **labelskwargs): | ||||||||||||
| def _build_tags(self, *labels, **labelskwargs) -> dict[str, str]: | ||||||||||||
| if labels: | ||||||||||||
| # -1 because ReplicaId was added automatically | ||||||||||||
| expected = len(self.metric._tag_keys) - 1 | ||||||||||||
|
|
@@ -52,12 +55,12 @@ def labels(self, *labels, **labelskwargs): | |||||||||||
|
|
||||||||||||
| labelskwargs["ReplicaId"] = _get_replica_id() or "" | ||||||||||||
|
|
||||||||||||
| if labelskwargs: | ||||||||||||
| for k, v in labelskwargs.items(): | ||||||||||||
| if not isinstance(v, str): | ||||||||||||
| labelskwargs[k] = str(v) | ||||||||||||
| self.metric.set_default_tags(labelskwargs) | ||||||||||||
| return self | ||||||||||||
| return {k: v if isinstance(v, str) else str(v) for k, v in labelskwargs.items()} | ||||||||||||
|
|
||||||||||||
| def labels(self, *labels, **labelskwargs) -> "RayPrometheusMetric": | ||||||||||||
| clone = copy.copy(self) | ||||||||||||
| clone._tags = self._build_tags(*labels, **labelskwargs) | ||||||||||||
| return clone | ||||||||||||
|
|
||||||||||||
| @staticmethod | ||||||||||||
| def _get_sanitized_opentelemetry_name(name: str) -> str: | ||||||||||||
|
|
@@ -101,11 +104,13 @@ def __init__( | |||||||||||
| ) | ||||||||||||
|
|
||||||||||||
| def set(self, value: int | float): | ||||||||||||
| return self.metric.set(value) | ||||||||||||
| if self._tags is None: | ||||||||||||
| return self.metric.set(value) | ||||||||||||
| return self.metric.set(value, tags=self._tags) | ||||||||||||
|
eicherseiji marked this conversation as resolved.
Outdated
|
||||||||||||
|
|
||||||||||||
| def set_to_current_time(self): | ||||||||||||
| # ray metrics doesn't have set_to_current time, https://docs.ray.io/en/latest/_modules/ray/util/metrics.html | ||||||||||||
| return self.metric.set(time.time()) | ||||||||||||
| return self.set(time.time()) | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| class RayCounterWrapper(RayPrometheusMetric): | ||||||||||||
|
|
@@ -129,7 +134,9 @@ def __init__( | |||||||||||
| def inc(self, value: int | float = 1.0): | ||||||||||||
| if value == 0: | ||||||||||||
| return | ||||||||||||
| return self.metric.inc(value) | ||||||||||||
| if self._tags is None: | ||||||||||||
| return self.metric.inc(value) | ||||||||||||
| return self.metric.inc(value, tags=self._tags) | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #40840 (comment) |
||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| class RayHistogramWrapper(RayPrometheusMetric): | ||||||||||||
|
|
@@ -155,7 +162,9 @@ def __init__( | |||||||||||
| ) | ||||||||||||
|
|
||||||||||||
| def observe(self, value: int | float): | ||||||||||||
| return self.metric.observe(value) | ||||||||||||
| if self._tags is None: | ||||||||||||
| return self.metric.observe(value) | ||||||||||||
| return self.metric.observe(value, tags=self._tags) | ||||||||||||
|
eicherseiji marked this conversation as resolved.
Outdated
|
||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| class RaySpecDecodingProm(SpecDecodingProm): | ||||||||||||
|
|
||||||||||||
Uh oh!
There was an error while loading. Please reload this page.