def test_redeploy_start_time(serve_instance): """Check that redeploying a deployment doesn't reset its start time.""" controller = serve.context._global_client._controller @serve.deployment def test(_): return "1" serve.run(test.bind()) deployment_route = DeploymentRoute.FromString( ray.get(controller.get_deployment_info.remote("test"))) deployment_info_1 = DeploymentInfo.from_proto( deployment_route.deployment_info) start_time_ms_1 = deployment_info_1.start_time_ms time.sleep(0.1) @serve.deployment def test(_): return "2" serve.run(test.bind()) deployment_route = DeploymentRoute.FromString( ray.get(controller.get_deployment_info.remote("test"))) deployment_info_2 = DeploymentInfo.from_proto( deployment_route.deployment_info) start_time_ms_2 = deployment_info_2.start_time_ms assert start_time_ms_1 == start_time_ms_2
def list_deployments(self, include_deleted: Optional[bool] = False) -> bytes: """Gets the current information about all deployments. Args: include_deleted(bool): Whether to include information about deployments that have been deleted. Returns: DeploymentRouteList's protobuf serialized bytes """ from ray.serve.generated.serve_pb2 import DeploymentRouteList, DeploymentRoute deployment_route_list = DeploymentRouteList() for deployment_name, ( deployment_info, route_prefix, ) in self.list_deployments_internal( include_deleted=include_deleted).items(): deployment_info_proto = deployment_info.to_proto() deployment_info_proto.name = deployment_name deployment_route_list.deployment_routes.append( DeploymentRoute(deployment_info=deployment_info_proto, route=route_prefix)) return deployment_route_list.SerializeToString()
def get_deployment_info(self, name: str) -> Tuple[DeploymentInfo, str]: deployment_route = DeploymentRoute.FromString( ray.get(self._controller.get_deployment_info.remote(name))) return ( DeploymentInfo.from_proto(deployment_route.deployment_info), deployment_route.route if deployment_route.route != "" else None, )
def get_deployment_info(self, name: str) -> bytes: """Get the current information about a deployment. Args: name(str): the name of the deployment. Returns: DeploymentRoute's protobuf serialized bytes Raises: KeyError if the deployment doesn't exist. """ deployment_info = self.deployment_state_manager.get_deployment(name) if deployment_info is None: raise KeyError(f"Deployment {name} does not exist.") route = self.endpoint_state.get_endpoint_route(name) from ray.serve.generated.serve_pb2 import DeploymentRoute deployment_route = DeploymentRoute( deployment_info=deployment_info.to_proto(), route=route) return deployment_route.SerializeToString()
def __init__( self, controller_handle: ActorHandle, deployment_name: EndpointTag, handle_options: Optional[HandleOptions] = None, *, _router: Optional[Router] = None, _internal_pickled_http_request: bool = False, ): self.controller_handle = controller_handle self.deployment_name = deployment_name self.handle_options = handle_options or HandleOptions() self.handle_tag = f"{self.deployment_name}#{get_random_letters()}" self._pickled_http_request = _internal_pickled_http_request self.request_counter = metrics.Counter( "serve_handle_request_counter", description=("The number of handle.remote() calls that have been " "made on this handle."), tag_keys=("handle", "deployment"), ) self.request_counter.set_default_tags({ "handle": self.handle_tag, "deployment": self.deployment_name }) self.router: Router = _router or self._make_router() deployment_route = DeploymentRoute.FromString( ray.get( self.controller_handle.get_deployment_info.remote( self.deployment_name))) deployment_info = DeploymentInfo.from_proto( deployment_route.deployment_info) self._stop_event: Optional[threading.Event] = None self._pusher: Optional[threading.Thread] = None remote_func = self.controller_handle.record_handle_metrics.remote if deployment_info.deployment_config.autoscaling_config: self._stop_event = threading.Event() self._pusher = start_metrics_pusher( interval_s=HANDLE_METRIC_PUSH_INTERVAL_S, collection_callback=self._collect_handle_queue_metrics, metrics_process_func=remote_func, stop_event=self._stop_event, )