Skip to content

Commit d88dddb

Browse files
committed
[core][autoscaler] make cluster constraints in the autoscaler status report clear
Signed-off-by: Rueian <[email protected]>
1 parent d76f8db commit d88dddb

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

python/ray/autoscaler/_private/util.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,14 @@ def get_constraint_report(request_demand: List[DictCount]):
734734
Returns:
735735
String containing the formatted constraints report, either listing each constraint
736736
and count or indicating no constraints exist.
737+
738+
Example:
739+
>>> request_demand = [
740+
... ({"CPU": 4}, 2),
741+
... ({"GPU": 1}, 1)
742+
... ]
743+
>>> get_constraint_report(request_demand)
744+
" {'CPU': 4}: 2 from request_resources()\\n {'GPU': 1}: 1 from request_resources()"
737745
"""
738746
constraint_lines = []
739747
for bundle, count in request_demand:

python/ray/autoscaler/v2/utils.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,9 @@ def format(cls, data: ClusterStatus, verbose: bool = False) -> str:
319319
pending_report = cls._pending_node_report(data)
320320
failure_report = cls._failed_node_report(data, verbose)
321321
cluster_usage_report = cls._cluster_usage_report(data, verbose)
322-
constraints_report = cls._constraint_report(data)
322+
constraints_report = cls._constraint_report(
323+
data.resource_demands.cluster_constraint_demand
324+
)
323325
demand_report = cls._demand_report(data)
324326
node_usage_report = (
325327
""
@@ -543,7 +545,9 @@ def _pending_node_report(data: ClusterStatus) -> str:
543545
return " (no pending nodes)"
544546

545547
@staticmethod
546-
def _constraint_report(data: ClusterStatus) -> str:
548+
def _constraint_report(
549+
cluster_constraint_demand: List[ClusterConstraintDemand],
550+
) -> str:
547551
"""Returns a formatted string describing the resource constraints from request_resources().
548552
549553
Args:
@@ -552,11 +556,21 @@ def _constraint_report(data: ClusterStatus) -> str:
552556
Returns:
553557
String containing the formatted constraints report, either listing each constraint
554558
and count or indicating no constraints exist.
559+
560+
Example:
561+
>>> cluster_constraint_demand = [
562+
... ClusterConstraintDemand(bundles_by_count=[
563+
... ResourceRequestByCount(bundle={"CPU": 4}, count=2),
564+
... ResourceRequestByCount(bundle={"GPU": 1}, count=1)
565+
... ])
566+
... ]
567+
>>> ClusterStatusFormatter._constraint_report(cluster_constraint_demand)
568+
" {'CPU': 4}: 2 from request_resources()\\n {'GPU': 1}: 1 from request_resources()"
555569
"""
556570
constraint_lines = []
557571
request_demand = [
558572
(bc.bundle, bc.count)
559-
for constraint_demand in data.resource_demands.cluster_constraint_demand
573+
for constraint_demand in cluster_constraint_demand
560574
for bc in constraint_demand.bundles_by_count
561575
]
562576
for bundle, count in request_demand:

0 commit comments

Comments
 (0)