@@ -56,6 +56,9 @@ class EndpointInfo:
5656 # Model label
5757 model_label : str
5858
59+ # Endpoint's sleep status
60+ sleep : bool
61+
5962 # Pod name
6063 pod_name : Optional [str ] = None
6164
@@ -260,6 +263,7 @@ def get_endpoint_info(self) -> List[EndpointInfo]:
260263 url = url ,
261264 model_names = [model ], # Convert single model to list
262265 Id = self .engines_id [i ],
266+ sleep = False ,
263267 added_timestamp = self .added_timestamp ,
264268 model_label = model_label ,
265269 model_info = self ._get_model_info (model ),
@@ -340,6 +344,33 @@ def _check_pod_ready(container_statuses):
340344 ready_count = sum (1 for status in container_statuses if status .ready )
341345 return ready_count == len (container_statuses )
342346
347+ def _get_engine_sleep_status (self , pod_ip ) -> Optional [bool ]:
348+ """
349+ Get the engine sleeping status by querying the engine's
350+ '/is_sleeping' endpoint.
351+
352+ Args:
353+ pod_ip: the IP address of the pod running the engine
354+
355+ Returns:
356+ the sleep status of the target engine
357+ """
358+ url = f"http://{ pod_ip } :{ self .port } /is_sleeping"
359+ sleep = False
360+ try :
361+ headers = None
362+ if VLLM_API_KEY := os .getenv ("VLLM_API_KEY" ):
363+ logger .info (f"Using vllm server authentication" )
364+ headers = {"Authorization" : f"Bearer { VLLM_API_KEY } " }
365+ response = requests .get (url , headers = headers )
366+ response .raise_for_status ()
367+ sleep = response .json ()["is_sleeping" ]
368+ except Exception as e :
369+ logger .warning (
370+ f"Failed to get the sleep status for engine at { url } - sleep status is set to `False`: { e } "
371+ )
372+ return sleep
373+
343374 def _get_model_names (self , pod_ip ) -> List [str ]:
344375 """
345376 Get the model names of the serving engine pod by querying the pod's
@@ -478,6 +509,7 @@ def _add_engine(
478509 added_timestamp = int (time .time ()),
479510 Id = str (uuid .uuid5 (uuid .NAMESPACE_DNS , engine_name )),
480511 model_label = model_label ,
512+ sleep = self ._get_engine_sleep_status (engine_ip ),
481513 pod_name = engine_name ,
482514 namespace = self .namespace ,
483515 )
0 commit comments