code: def test_metrics_export_node_metrics(shutdown_only):
      # Verify node metrics are available.
      addr = ray.init()
      dashboard_export_addr = "{}:{}".format(
          addr["raylet_ip_address"], DASHBOARD_METRIC_PORT
      )
  
      def verify_node_metrics():
          avail_metrics = raw_metrics(addr)
  
          components = set()
          for metric in _NODE_COMPONENT_METRICS:
              samples = avail_metrics[metric]
              for sample in samples:
                  components.add(sample.labels["Component"])
          assert components == {"raylet", "agent", "ray::IDLE"}
  
          avail_metrics = set(avail_metrics)
  
          for node_metric in _NODE_METRICS:
              assert node_metric in avail_metrics
          for node_metric in _NODE_COMPONENT_METRICS:
              assert node_metric in avail_metrics
          return True
  
      def verify_dashboard_metrics():
          avail_metrics = fetch_prometheus_metrics(
              [dashboard_export_addr]
          )
          # Run list nodes to trigger dashboard API.
          list_nodes()
  
          # Verify metrics exist.
          avail_metrics = avail_metrics
          for metric in _DASHBOARD_METRICS:
              # Metric name should appear with some suffix (_count, _total,
              # etc...) in the list of all names
              assert len(avail_metrics[metric]) > 0
  
              samples = avail_metrics[metric]
              for sample in samples:
                  assert sample.labels["Component"] == "dashboard"
  
          return True
  
      wait_for_condition(verify_node_metrics)
      wait_for_condition(verify_dashboard_metrics)
  
imports: import signal
  import json
  import os
  import pathlib
  import sys
  import requests
  from pprint import pformat
  from unittest.mock import MagicMock
  import numpy
  import pytest
  import ray
  from ray.util.state import list_nodes
  from ray._private.metrics_agent import PrometheusServiceDiscoveryWriter
  from ray._private.ray_constants import PROMETHEUS_SERVICE_DISCOVERY_FILE
  from ray._private.test_utils import SignalActor, fetch_prometheus, fetch_prometheus_metrics, get_log_batch, wait_for_condition, raw_metrics
  from ray.autoscaler._private.constants import AUTOSCALER_METRIC_PORT
  from ray.dashboard.consts import DASHBOARD_METRIC_PORT
  from ray.util.metrics import Counter, Gauge, Histogram
label_desc: Use image node_id 3 for calling a global function with example usage: test_metrics_export_node_metrics(shutdown_only) and returns: True, True