code: def test_metrics_prometheus_mode():
      """
      Validates metrics prometheus mode
      """
      # Torchserve cleanup
      test_utils.stop_torchserve()
      test_utils.delete_all_snapshots()
      # Remove existing logs if any
      for f in glob.glob("logs/*.log"):
          os.remove(f)
  
      config_file = os.path.join(
          test_utils.ROOT_DIR, "config.properties"
      )
      with open(config_file, "w") as f:
          f.write("enable_envvars_config=true")
  
      os.environ["TS_METRICS_MODE"] = "prometheus"
      os.environ["TS_METRICS_CONFIG"] = os.path.join(
          test_utils.REPO_ROOT,
          "examples",
          "custom_metrics",
          "metrics.yaml",
      )
  
      try:
          test_utils.start_torchserve(
              model_store=test_utils.MODEL_STORE,
              snapshot_file=config_file,
              no_config_snapshots=True,
              gen_mar=False,
          )
          register_model_and_make_inference_request()
          validate_metrics_log(
              "ts_metrics.log",
              LEGACY_FRONTEND_PROMETHEUS_METRICS,
              False,
          )
          validate_metrics_log(
              "ts_metrics.log", FRONTEND_METRICS, False
          )
          validate_metrics_log("ts_metrics.log", SYSTEM_METRICS, False)
          validate_metrics_log(
              "model_metrics.log", BACKEND_METRICS, False
          )
          validate_metrics_log(
              "model_metrics.log", AUTO_DETECT_BACKEND_METRICS, False
          )
  
          response = requests.get("http://localhost:8082/metrics")
          prometheus_metrics = response.text
          for metric_name in LEGACY_FRONTEND_PROMETHEUS_METRICS:
              assert metric_name in prometheus_metrics
          for metric_name in FRONTEND_METRICS:
              assert metric_name in prometheus_metrics
          for metric_name in SYSTEM_METRICS:
              assert metric_name in prometheus_metrics
          for metric_name in BACKEND_METRICS:
              assert metric_name in prometheus_metrics
          for metric_name in AUTO_DETECT_BACKEND_METRICS:
              assert metric_name not in prometheus_metrics
  
          prometheus_metric_patterns = [
              r"TYPE Requests2XX counter",
              r'Requests2XX\{Level="Host",Hostname=".+",\} \d+\.\d+',
              r"TYPE ts_inference_requests_total counter",
              r'ts_inference_requests_total\{model_name="mnist_custom_metrics",model_version="default",hostname=".+",\} \d+\.\d+',
              r"TYPE ts_inference_latency_microseconds counter",
              r'ts_inference_latency_microseconds\{model_name="mnist_custom_metrics",model_version="default",hostname=".+",\} \d+\.\d+',
              r"TYPE ts_queue_latency_microseconds counter",
              r'ts_queue_latency_microseconds\{model_name="mnist_custom_metrics",model_version="default",hostname=".+",\} \d+\.\d+',
              r"TYPE QueueTime gauge",
              r'QueueTime\{Level="Host",Hostname=".+",\} \d+\.\d+',
              r"TYPE WorkerThreadTime gauge",
              r'WorkerThreadTime\{Level="Host",Hostname=".+",\} \d+\.\d+',
              r"TYPE WorkerLoadTime gauge",
              r'WorkerLoadTime\{WorkerName=".+",Level="Host",Hostname=".+",\} \d+\.\d+',
              r"TYPE CPUUtilization gauge",
              r'CPUUtilization\{Level="Host",Hostname=".+",\} \d+\.\d+',
              r"TYPE MemoryUsed gauge",
              r'MemoryUsed\{Level="Host",Hostname=".+",\} \d+\.\d+',
              r"TYPE MemoryAvailable gauge",
              r'MemoryAvailable\{Level="Host",Hostname=".+",\} \d+\.\d+',
              r"TYPE MemoryUtilization gauge",
              r'MemoryUtilization\{Level="Host",Hostname=".+",\} \d+\.\d+',
              r"TYPE DiskUsage gauge",
              r'DiskUsage\{Level="Host",Hostname=".+",\} \d+\.\d+',
              r"TYPE DiskUtilization gauge",
              r'DiskUtilization\{Level="Host",Hostname=".+",\} \d+\.\d+',
              r"TYPE DiskAvailable gauge",
              r'DiskAvailable\{Level="Host",Hostname=".+",\} \d+\.\d+',
              r"TYPE HandlerTime gauge",
              r'HandlerTime\{ModelName="mnist_custom_metrics",Level="Model",Hostname=".+",\} \d+\.\d+',
              r"TYPE PredictionTime gauge",
              r'PredictionTime\{ModelName="mnist_custom_metrics",Level="Model",Hostname=".+",\} \d+\.\d+',
              r"TYPE InferenceRequestCount counter",
              r'InferenceRequestCount\{Hostname=".+",\} \d+\.\d+',
              r"TYPE InitializeCallCount counter",
              r'InitializeCallCount\{ModelName="mnist_custom_metrics",Level="Model",Hostname=".+",\} \d+\.\d+',
              r"TYPE PreprocessCallCount counter",
              r'PreprocessCallCount\{ModelName="mnist_custom_metrics",Hostname=".+",\} \d+\.\d+',
              r"TYPE PostprocessCallCount counter",
              r'PostprocessCallCount\{ModelName="mnist_custom_metrics",Level="Model",Hostname=".+",\} \d+\.\d+',
              r"TYPE RequestBatchSize gauge",
              r'RequestBatchSize\{ModelName="mnist_custom_metrics",Hostname=".+",\} \d+\.\d+',
              r"TYPE SizeOfImage gauge",
              r'SizeOfImage\{ModelName="mnist_custom_metrics",Level="Model",Hostname=".+",\} \d+\.\d+',
          ]
  
          for pattern in prometheus_metric_patterns:
              matches = re.findall(pattern, prometheus_metrics)
              assert len(matches) == 1, "pattern not found: " + pattern
  
      finally:
          test_utils.stop_torchserve()
          test_utils.delete_all_snapshots()
          del os.environ["TS_METRICS_MODE"]
          del os.environ["TS_METRICS_CONFIG"]
          os.remove(config_file)
  
imports: import glob
  import os
  import platform
  import re
  import shutil
  import subprocess
  import time
  from os import path
  import requests
  import test_utils
label_desc: Use image node_id 24 for calling a global function with example usage: test_metrics_prometheus_mode() without return types