code: def _extract_metrics(metrics, path: str):
      if isinstance(metrics, (int, float, str)):
          return metrics
  
      if not isinstance(metrics, dict):
          return None
  
      ret = {}
      for key, val in metrics.items():
          m = _extract_metrics(val, path)
          if m not in (None, {}):
              ret[key] = m
          else:
              logger.debug(
                  "Could not parse %r metric from %r due to its unsupported type: %r",
                  key,
                  path,
                  type(val).__name__,
              )
  
      return ret
  
imports: import os
  from itertools import chain
  from typing import TYPE_CHECKING, Any, Dict, Iterable, Iterator, List, Optional, Tuple, TypedDict, Union
  from funcy import ldistinct
  from scmrepo.exceptions import SCMError
  from dvc.log import logger
  from dvc.scm import NoSCMError
  from dvc.utils import as_posix, expand_paths
  from dvc.utils.collections import ensure_list
  from dvc.utils.serialize import load_path
label_desc: Use image node_id 2 for calling a global function with example usage: _extract_metrics(metrics, path) and returns: ret, metrics, None