code: def test_proxy_metrics_internal_error(serve_start_shutdown):
      # NOTE: These metrics should be documented at
      # https://docs.ray.io/en/latest/serve/monitoring.html#metrics
      # Any updates here should be reflected there too.
      expected_metrics = [
          "serve_num_http_requests",
          "serve_num_grpc_requests",
          "serve_num_http_error_requests",
          "serve_num_grpc_error_requests",
          "serve_num_deployment_http_error_requests",
          "serve_http_request_latency_ms",
          "serve_num_deployment_grpc_error_requests",
          "serve_grpc_request_latency_ms",
      ]
  
      def verify_metrics(_expected_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
          for metric in _expected_metrics:
              if do_assert:
                  assert metric in resp
              if metric not in resp:
                  return False
          return True
  
      @serve.deployment(name="A")
      class A:
          async def __init__(self):
              pass
  
          async def __call__(self, *args):
              # Trigger RayActorError
              os._exit(0)
  
      app_name = "app"
      serve.run(A.bind(), name=app_name)
      requests.get("http://127.0.0.1:8000/A/")
      requests.get("http://127.0.0.1:8000/A/")
      channel = grpc.insecure_channel("localhost:9000")
      with pytest.raises(grpc.RpcError):
          ping_grpc_call_method(channel=channel, app_name=app_name)
  
      # Ensure all expected metrics are present.
      try:
          wait_for_condition(
              verify_metrics,
              retry_interval_ms=1000,
              timeout=10,
              expected_metrics=expected_metrics,
          )
      except RuntimeError:
          verify_metrics(expected_metrics, True)
  
      def verify_error_count(do_assert=False):
          resp = requests.get("http://127.0.0.1:9999").text
          resp = resp.split("\n")
          for metrics in resp:
              if "# HELP" in metrics or "# TYPE" in metrics:
                  continue
              if "serve_num_http_error_requests" in metrics:
                  # route "/A/" should have error count 2
                  if do_assert:
                      assert "2.0" in metrics
                  if "2.0" not in metrics:
                      return False
              elif (
                  "serve_num_deployment_http_error_requests" in metrics
              ):
                  # deployment A should have error count 2
                  if do_assert:
                      assert (
                          'deployment="A"' in metrics
                          and "2.0" in metrics
                      )
                  if (
                      'deployment="A"' not in metrics
                      or "2.0" not in metrics
                  ):
                      return False
              elif "serve_num_grpc_error_requests" in metrics:
                  # gRPC pinged "A" once
                  if do_assert:
                      assert "1.0" in metrics
                  if "1.0" not in metrics:
                      return False
              elif (
                  "serve_num_deployment_grpc_error_requests" in metrics
              ):
                  # gRPC pinged "A" once
                  if do_assert:
                      assert (
                          'deployment="A"' in metrics
                          and "1.0" in metrics
                      )
                  if (
                      'deployment="A"' not in metrics
                      or "1.0" not in metrics
                  ):
                      return False
          return True
  
      # There is a latency in updating the counter
      try:
          wait_for_condition(
              verify_error_count, retry_interval_ms=1000, timeout=10
          )
      except RuntimeError:
          verify_error_count(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 5 for calling a global function with example usage: test_proxy_metrics_internal_error(serve_start_shutdown) and returns: True, True, False, False, False, False, False, False