code: def test_serve_metrics_for_successful_connection(
      serve_start_shutdown,
  ):
      @serve.deployment(name="metrics")
      async def f(request):
          return "hello"
  
      app_name = "app1"
      handle = serve.run(target=f.bind(), name=app_name)
  
      # send 10 concurrent requests
      url = "http://127.0.0.1:8000/metrics"
      ray.get([block_until_http_ready.remote(url) for _ in range(10)])
      [handle.remote(url) for _ in range(10)]
  
      # Ping gPRC proxy
      channel = grpc.insecure_channel("localhost:9000")
      wait_for_condition(
          ping_grpc_list_applications,
          channel=channel,
          app_names=[app_name],
      )
  
      def verify_metrics(do_assert=False):
          try:
              resp = requests.get("http://127.0.0.1:9999").text
          # Requests will fail if we are crashing the controller
          except requests.ConnectionError:
              return False
  
          # NOTE: These metrics should be documented at
          # https://docs.ray.io/en/latest/serve/monitoring.html#metrics
          # Any updates to here should be reflected there too.
          expected_metrics = [
              # counter
              "serve_num_router_requests",
              "serve_num_http_requests",
              "serve_num_grpc_requests",
              "serve_deployment_queued_queries",
              "serve_deployment_request_counter",
              "serve_deployment_replica_starts",
              # histogram
              "serve_deployment_processing_latency_ms_bucket",
              "serve_deployment_processing_latency_ms_count",
              "serve_deployment_processing_latency_ms_sum",
              "serve_deployment_processing_latency_ms",
              # gauge
              "serve_replica_processing_queries",
              "serve_deployment_replica_healthy",
              # handle
              "serve_handle_request_counter",
          ]
  
          for metric in expected_metrics:
              # For the final error round
              if do_assert:
                  assert metric in resp
              # For the wait_for_condition
              else:
                  if metric not in resp:
                      return False
          return True
  
      try:
          wait_for_condition(verify_metrics, retry_interval_ms=500)
      except RuntimeError:
          verify_metrics(do_assert=True)
  
imports: import os
  import sys
  from typing import DefaultDict, Dict, List, Optional
  import grpc
  import pytest
  import requests
  from fastapi import FastAPI
  import ray
  import ray.util.state
  from ray import serve
  from ray._private.test_utils import SignalActor, wait_for_condition
  from ray.serve._private.constants import DEFAULT_LATENCY_BUCKET_MS
  from ray.serve._private.long_poll import LongPollHost, UpdatedObject
  from ray.serve._private.test_utils import ping_fruit_stand, ping_grpc_call_method, ping_grpc_list_applications
  from ray.serve._private.utils import block_until_http_ready
  from ray.serve.config import gRPCOptions
  from ray.serve.handle import DeploymentHandle
  from ray.serve.metrics import Counter, Gauge, Histogram
  from ray.serve.tests.test_config_files.grpc_deployment import g, g2
label_desc: Use image node_id 2 for calling a global function with example usage: test_serve_metrics_for_successful_connection(serve_start_shutdown) and returns: str, True, False, False