Skip to content

Commit

Permalink
[Core] Remove deprecated Metric methods (ray-project#43202)
Browse files Browse the repository at this point in the history
Those methods have been deprecated for 3 years and they are DeveloperAPI so it's safe to remove them.

Signed-off-by: Jiajun Yao <[email protected]>
  • Loading branch information
jjyao authored Feb 15, 2024
1 parent 13551b6 commit ef6c63e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 56 deletions.
6 changes: 3 additions & 3 deletions python/ray/tests/test_metrics_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ def test_basic_custom_metrics(metric_mock):
# -- Gauge --
gauge = Gauge("gauge", description="gauge")
gauge._metric = metric_mock
gauge.record(4)
gauge.set(4)
metric_mock.record.assert_called_with(4, tags={})

# -- Histogram
Expand Down Expand Up @@ -758,12 +758,12 @@ def test_custom_metrics_with_extra_tags(metric_mock):
gauge._metric = metric_mock

# Record with base tags
gauge.record(4, tags=base_tags)
gauge.set(4, tags=base_tags)
metric_mock.record.assert_called_with(4, tags=base_tags)
metric_mock.reset_mock()

# Record with extra tags
gauge.record(4, tags=extra_tags)
gauge.set(4, tags=extra_tags)
metric_mock.record.assert_called_with(4, tags=extra_tags)
metric_mock.reset_mock()

Expand Down
57 changes: 4 additions & 53 deletions python/ray/util/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,10 @@ def set_default_tags(self, default_tags: Dict[str, str]):
self._default_tags = default_tags
return self

def record(
def _record(
self,
value: Union[int, float],
tags: Optional[Dict[str, str]] = None,
_internal=False,
) -> None:
"""Record the metric point of the metric.
Expand All @@ -91,27 +90,6 @@ def record(
value: The value to be recorded as a metric point.
"""
assert self._metric is not None
if isinstance(self._metric, CythonCount) and not _internal:
logger.warning(
"Counter.record() is deprecated in favor of "
"Counter.inc() and will be removed in a future "
"release. Please use Counter.inc() instead."
)

if isinstance(self._metric, CythonGauge) and not _internal:
logger.warning(
"Gauge.record() is deprecated in favor of "
"Gauge.set() and will be removed in a future "
"release. Please use Gauge.set() instead."
)

if isinstance(self._metric, CythonHistogram) and not _internal:
logger.warning(
"Histogram.record() is deprecated in favor of "
"Histogram.observe() and will be removed in a "
"future release. Please use Histogram.observe() "
"instead."
)

final_tags = self._get_final_tags(tags)
self._validate_tags(final_tags)
Expand Down Expand Up @@ -196,34 +174,7 @@ def inc(self, value: Union[int, float] = 1.0, tags: Dict[str, str] = None):
if value <= 0:
raise ValueError(f"value must be >0, got {value}")

self.record(value, tags=tags, _internal=True)


@DeveloperAPI
class Count(Counter):
"""The count of the number of metric points.
This corresponds to Prometheus' 'Count' metric.
This class is DEPRECATED, please use ray.util.metrics.Counter instead.
Args:
name: Name of the metric.
description: Description of the metric.
tag_keys: Tag keys of the metric.
"""

def __init__(
self,
name: str,
description: str = "",
tag_keys: Optional[Tuple[str, ...]] = None,
):
logger.warning(
"`metrics.Count` has been renamed to `metrics.Counter`. "
"`metrics.Count` will be removed in a future release."
)
super().__init__(name, description, tag_keys)
self._record(value, tags=tags)


@DeveloperAPI
Expand Down Expand Up @@ -281,7 +232,7 @@ def observe(self, value: Union[int, float], tags: Dict[str, str] = None):
if not isinstance(value, (int, float)):
raise TypeError(f"value must be int or float, got {type(value)}.")

self.record(value, tags, _internal=True)
self._record(value, tags)

def __reduce__(self):
deserializer = Histogram
Expand Down Expand Up @@ -337,7 +288,7 @@ def set(self, value: Union[int, float], tags: Dict[str, str] = None):
if not isinstance(value, (int, float)):
raise TypeError(f"value must be int or float, got {type(value)}.")

self.record(value, tags, _internal=True)
self._record(value, tags)

def __reduce__(self):
deserializer = Gauge
Expand Down

0 comments on commit ef6c63e

Please sign in to comment.