code: def test_metrics(ray_start_regular_shared):
      it = from_items([1, 2, 3, 4], num_shards=1)
      it2 = from_items([1, 2, 3, 4], num_shards=1)
  
      def f(x):
          metrics = LocalIterator.get_metrics()
          metrics.counters["foo"] += x
          return metrics.counters["foo"]
  
      it = it.gather_sync().for_each(f)
      it2 = it2.gather_sync().for_each(f)
  
      # Tests iterators have isolated contexts.
      assert it.take(4) == [1, 3, 6, 10]
      assert it2.take(4) == [1, 3, 6, 10]
  
imports: import sys
  import time
  import collections
  from collections import Counter
  import pytest
  import ray
  from ray.util.iter import from_items, from_iterators, from_range, from_actors, ParallelIteratorWorker, LocalIterator
  from ray._private.test_utils import Semaphore
label_desc: Use image node_id 3 for calling a global function with example usage: test_metrics(ray_start_regular_shared) and returns: metrics