code: def test_custom_metrics_validation(shutdown_only):
      ray.init()
      # Missing tag(s) from tag_keys.
      metric = Counter("name", tag_keys=("a", "b"))
      metric.set_default_tags({"a": "1"})
  
      metric.inc(1.0, {"b": "2"})
      metric.inc(1.0, {"a": "1", "b": "2"})
  
      with pytest.raises(ValueError):
          metric.inc(1.0)
  
      with pytest.raises(ValueError):
          metric.inc(1.0, {"a": "2"})
  
      # Extra tag not in tag_keys.
      metric = Counter("name", tag_keys=("a",))
      with pytest.raises(ValueError):
          metric.inc(1.0, {"a": "1", "b": "2"})
  
      # tag_keys must be tuple.
      with pytest.raises(TypeError):
          Counter("name", tag_keys="a")
      # tag_keys must be strs.
      with pytest.raises(TypeError):
          Counter("name", tag_keys=(1,))
  
      metric = Counter("name", tag_keys=("a",))
      # Set default tag that isn't in tag_keys.
      with pytest.raises(ValueError):
          metric.set_default_tags({"a": "1", "c": "2"})
      # Default tag value must be str.
      with pytest.raises(TypeError):
          metric.set_default_tags({"a": 1})
      # Tag value must be str.
      with pytest.raises(TypeError):
          metric.inc(1.0, {"a": 1})
  
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 14 for calling a global function with example usage: test_custom_metrics_validation(shutdown_only) without return types