Repository: ray-project/ray
File: python/ray/serve/_private/controller.py (Python)

Code before:
    def get_root_url(self):
        """Return the root url for the serve instance."""
        if self.proxy_state_manager is None:
            return None
        http_config = self.get_http_config()
        if http_config.root_url == "":
            # HTTP is disabled
            if http_config.host is None:
                return ""
            return (
                f"http://{build_address(http_config.host, http_config.port)}"
                f"{http_config.root_path}"
            )
        return http_config.root_url

    def config_checkpoint_deleted(self) -> bool:
        """Returns whether the config checkpoint has been deleted.

        Get the config checkpoint from the kv store. If it is None, then it has been
        deleted.
        """
        return self.kv_store.get(CONFIG_CHECKPOINT_KEY) is None

    def _kill_actors_in_serve_subnamespaces(self) -> None:
        """Kill all actors in namespaces that start with 'serve::'."""
        from ray.util.state import list_actors

        try:
            gcs_address = ray.get_runtime_context().gcs_address
            actors = list_actors(
                address=gcs_address,
                filters=[("state", "=", "ALIVE")],
                limit=10000,
            )
        except Exception:
            logger.debug(
                "Failed to list actors for sub-namespace cleanup, skipping.",
                exc_info=True,
            )
            return

        for actor in actors:
            name, namespace = actor.get("name"), actor.get("ray_namespace")
            if name and namespace and namespace.startswith(f"{SERVE_NAMESPACE}::"):
                try:
                    ray.kill(ray.get_actor(name, namespace=namespace), no_restart=True)
                except Exception:
                    # Actor may have already died or be unreachable
                    pass

    def shutdown(self):

Review comment (suggestion):
```suggestion
        from ray.util.state import list_actors
        # Lazy import required. Since `list_actors` is client code, importing at the top level 
        # will tell poison the linter to think that internal Serve APIs need to be publicly documented
```

Code after:

    def _all_running_replicas(self) -> Dict[DeploymentID, List[RunningReplicaInfo]]:
        """Used for testing.

        Returned dictionary maps deployment names to replica infos.
        """

        return self.deployment_state_manager.get_running_replica_infos()

    def get_actor_details(self) -> ServeActorDetails:
        """Returns the actor details for this controller.

        Currently used for test only.
        """
        return self._actor_details

    def get_health_metrics(self) -> Dict[str, Any]:
        """Returns comprehensive health metrics for the controller.

        This method provides detailed performance metrics to help diagnose
        controller health issues, especially as cluster size increases.

        Returns:
            Dictionary containing health metrics including:
            - Control loop performance (iteration speed, durations)
            - Event loop health (task count, scheduling delay)
            - Component update latencies
            - Autoscaling metrics latency (handle/replica)
            - Memory usage
        """
        try:
            return self._health_metrics_tracker.collect_metrics().dict()
        except Exception:
            logger.exception("Exception collecting controller health metrics.")
            raise

    def get_proxy_details(self, node_id: str) -> Optional[ProxyDetails]:
        """Returns the proxy details for the proxy on the given node.

        Currently used for test only. Will return None if the proxy doesn't exist on
        the given node.
        """
        if self.proxy_state_manager is None:
            return None

        return self.proxy_state_manager.get_proxy_details().get(node_id)

    def get_deployment_timestamps(self, app_name: str) -> float:
        """Returns the deployment timestamp for the given app.

        Currently used for test only.