code: def assert_metrics(s: Scheduler, *keys: tuple[str, ...]) -> None:
      metrics = dict(s.cumulative_worker_metrics)
      span = s.extensions["spans"].spans_search_by_name["default",][0]
      span_metrics = dict(span.cumulative_worker_metrics)
  
      for key in keys:
          value = metrics.pop(key)
          assert span_metrics.pop(key) == pytest.approx(value)
          if key[0] == "execute":
              key2 = (
                  "p2p",
                  "foreground",
                  key[2].replace("p2p-", ""),
                  key[3],
              )
              assert metrics.pop(key2) == pytest.approx(value)
              assert span_metrics.pop(key2) == pytest.approx(value)
  
      # Check that the test doesn't omit any metrics
      assert [key for key in metrics if key[0] == "p2p"] == []
      assert [key for key in span_metrics if key[0] == "p2p"] == []
  
imports: from __future__ import annotations
  import pytest
  import dask.datasets
  from distributed import Scheduler
  from distributed.utils_test import gen_cluster
label_desc: Use image node_id 1 for calling a global function with example usage: assert_metrics(s) without return types