code: def aggregate_all_metrics(
      metrics_from_all_nodes: Dict[str, List[Union[float, int]]]
  ):
      num_nodes = len(metrics_from_all_nodes["per_nodel_tps"])
      return {
          # Per thread metrics
          "per_thread_latency_avg_ms": round(
              sum(metrics_from_all_nodes["per_thread_latency_avg_ms"])
              / num_nodes,
              2,
          ),
          "per_thread_latency_max_ms": max(
              metrics_from_all_nodes["per_thread_latency_max_ms"]
          ),
          "per_thread_avg_tps": round(
              sum(metrics_from_all_nodes["per_thread_tps"]) / num_nodes,
              2,
          ),
          "per_thread_max_tps": max(
              metrics_from_all_nodes["per_thread_max_tps"]
          ),
          # Per wrk node metrics
          "per_node_avg_tps": round(
              sum(metrics_from_all_nodes["per_nodel_tps"]) / num_nodes,
              2,
          ),
          "per_node_avg_transfer_per_sec_KB": round(
              sum(
                  metrics_from_all_nodes["per_node_transfer_per_sec_KB"]
              )
              / num_nodes,
              2,
          ),
          # Cluster metrics
          "cluster_total_thoughput": sum(
              metrics_from_all_nodes["per_node_total_thoughput"]
          ),
          "cluster_total_transfer_KB": sum(
              metrics_from_all_nodes["per_node_total_transfer_KB"]
          ),
          "cluster_total_timeout_requests": sum(
              metrics_from_all_nodes["per_node_total_timeout_requests"]
          ),
          "cluster_max_P50_latency_ms": max(
              metrics_from_all_nodes["P50_latency_ms"]
          ),
          "cluster_max_P75_latency_ms": max(
              metrics_from_all_nodes["P75_latency_ms"]
          ),
          "cluster_max_P90_latency_ms": max(
              metrics_from_all_nodes["P90_latency_ms"]
          ),
          "cluster_max_P99_latency_ms": max(
              metrics_from_all_nodes["P99_latency_ms"]
          ),
      }
  
file_path: ray/release/serve_tests/workloads/serve_test_utils.py
imports: import json
  import logging
  import os
  import random
  import ray
  import re
  import subprocess
  from collections import defaultdict
  from serve_test_cluster_utils import NUM_CPU_PER_NODE
  from subprocess import PIPE
  from typing import Dict, List, Union
label_desc: Use image node_id 7 for calling a global function with example usage: aggregate_all_metrics(metrics_from_all_nodes) and returns: dict