code: def check_logs(
      log_regex: Any,
      log_fn: Callable[..., Iterable[Log]],
      log_fields_fn: Callable[..., Iterable[LogFields]],
  ) -> None:
      # This is also testing that follow terminates. If we timeout here, that's it.
      for log in log_fn(follow=True):
          if log_regex.match(log.message):
              break
      else:
          raise ValueError("ran out of logs without a match")
  
      # Just make sure these calls 200 and return some logs.
      assert any(log_fn(tail=10)), "tail returned no logs"
      assert any(log_fn(head=10)), "head returned no logs"
  
      # Task log fields should work, follow or no follow.
      assert any(
          log_fields_fn(follow=True)
      ), "log fields returned nothing"
      fields_list = list(log_fields_fn())
      assert any(fields_list), "no task log fields were returned"
  
      # Convert fields to log_fn filters and check all are valid.
      fields = fields_list[0].to_json()
      assert any(fields.values()), "no filter values were returned"
  
      for k, v in fields.items():
          if not any(v):
              continue
  
          # Make sure each filter returns some logs (it should or else it shouldn't be a filter).
          assert any(
              log_fn(
                  **{
                      to_snake_case(k): v[0],
                  },
              )
          ), "good filter returned no logs"
  
      # Changed -1 to represent no-rank filter.
      assert any(
          log_fn(rank_ids=[-1])
      ), "-1 rank returns logs with no rank"
  
      # Check other negative ranks are nonsense.
      assert not any(log_fn(rank_ids=[-2])), "bad filter returned logs"
  
file_path: determined/e2e_tests/tests/cluster/test_logging.py
imports: import functools
  import re
  import sys
  import threading
  from typing import Any, Callable, Dict, Iterable, Optional, Union
  import pytest
  from determined.common import api
  from determined.common.api import authentication, bindings, certs
  from tests import config
  from tests import experiment
label_desc: Use image node_id 3 for calling a global function with example usage: check_logs(log_regex, log_fn, log_fields_fn) without return types