code: def test_filter_event_by_level(monkeypatch):
      def gen_event(level: str):
          return event_pb2.Event(
              source_type=event_pb2.Event.AUTOSCALER,
              severity=event_pb2.Event.Severity.Value(level),
              message=level,
          )
  
      trace = gen_event("TRACE")
      debug = gen_event("DEBUG")
      info = gen_event("INFO")
      warning = gen_event("WARNING")
      error = gen_event("ERROR")
      fatal = gen_event("FATAL")
  
      def assert_events_filtered(events, expected, filter_level):
          filtered = [
              e
              for e in events
              if filter_event_by_level(e, filter_level)
          ]
          print(filtered)
          assert len(filtered) == len(expected)
          assert {e.message for e in filtered} == {
              e.message for e in expected
          }
  
      events = [trace, debug, info, warning, error, fatal]
      assert_events_filtered(events, [], "TRACE")
      assert_events_filtered(events, [trace], "DEBUG")
      assert_events_filtered(events, [trace, debug], "INFO")
      assert_events_filtered(events, [trace, debug, info], "WARNING")
      assert_events_filtered(
          events, [trace, debug, info, warning], "ERROR"
      )
      assert_events_filtered(
          events, [trace, debug, info, warning, error], "FATAL"
      )
  
imports: import os
  import sys
  import time
  import json
  import copy
  import logging
  import requests
  import asyncio
  import random
  import tempfile
  import socket
  from pprint import pprint
  from datetime import datetime
  import pytest
  import numpy
  import ray
  from ray.util.state import list_cluster_events
  from ray._private.utils import binary_to_hex
  from ray.cluster_utils import AutoscalingCluster
  from ray._private.event.event_logger import filter_event_by_level, get_event_logger
  from ray.dashboard.tests.conftest import *
  from ray.dashboard.modules.event import event_consts
  from ray.core.generated import event_pb2
  from ray._private.test_utils import format_web_url, wait_until_server_available, wait_for_condition
  from ray.dashboard.modules.event.event_utils import monitor_events
  from ray.job_submission import JobSubmissionClient
label_desc: Use image node_id 7 for calling a global function with example usage: test_filter_event_by_level(monkeypatch) and returns: event_pb2