@@ -49,6 +49,9 @@ class EndpointInfo:
4949 # Model label
5050 model_label : str
5151
52+ # Endpoint's sleep status
53+ sleep : bool
54+
5255
5356class ServiceDiscovery (metaclass = abc .ABCMeta ):
5457 @abc .abstractmethod
@@ -103,7 +106,7 @@ def get_endpoint_info(self) -> List[EndpointInfo]:
103106 """
104107
105108 endpoint_infos = [
106- EndpointInfo (url , model , self .added_timestamp , model_label )
109+ EndpointInfo (url , model , self .added_timestamp , model_label , False )
107110 for url , model , model_label in zip (
108111 self .urls , self .models , self .model_labels
109112 )
@@ -157,6 +160,33 @@ def _check_pod_ready(container_statuses):
157160 ready_count = sum (1 for status in container_statuses if status .ready )
158161 return ready_count == len (container_statuses )
159162
163+ def _get_engine_sleep_status (self , pod_ip ) -> Optional [bool ]:
164+ """
165+ Get the engine sleeping status by querying the engine's
166+ '/is_sleeping' endpoint.
167+
168+ Args:
169+ pod_ip: the IP address of the pod running the engine
170+
171+ Returns:
172+ the sleep status of the engine
173+ """
174+ url = f"http://{ pod_ip } :{ self .port } /is_sleeping"
175+ sleep = False
176+ try :
177+ headers = None
178+ if VLLM_API_KEY := os .getenv ("VLLM_API_KEY" ):
179+ logger .info (f"Using vllm server authentication" )
180+ headers = {"Authorization" : f"Bearer { VLLM_API_KEY } " }
181+ response = requests .get (url , headers = headers )
182+ response .raise_for_status ()
183+ sleep = response .json ()["is_sleeping" ]
184+ except Exception as e :
185+ logger .error (f"Failed to get the sleep status for engine at { url } : { e } " )
186+ return None
187+
188+ return sleep
189+
160190 def _get_model_name (self , pod_ip ) -> Optional [str ]:
161191 """
162192 Get the model name of the serving engine pod by querying the pod's
@@ -238,12 +268,14 @@ def _add_engine(
238268 f"Discovered new serving engine { engine_name } at "
239269 f"{ engine_ip } , running model: { model_name } "
240270 )
271+
241272 with self .available_engines_lock :
242273 self .available_engines [engine_name ] = EndpointInfo (
243274 url = f"http://{ engine_ip } :{ self .port } " ,
244275 model_name = model_name ,
245276 added_timestamp = int (time .time ()),
246277 model_label = model_label ,
278+ sleep = self ._get_engine_sleep_status (engine_ip ),
247279 )
248280
249281 def _delete_engine (self , engine_name : str ):
0 commit comments