<commit_before>require 'thread'
require 'concurrent/atomic/event'
require 'util/duplicate_blocker'

class ManageIQ::Providers::BaseManager::EventCatcher::Runner < ::MiqWorker::Runner
  class EventCatcherHandledException < StandardError
  end

  include DuplicateBlocker

  OPTIONS_PARSER_SETTINGS = ::MiqWorker::Runner::OPTIONS_PARSER_SETTINGS + [
    [:ems_id, 'EMS Instance ID', String],
  ]

  def after_initialize
    @ems = ExtManagementSystem.find(@cfg[:ems_id])
    do_exit("Unable to find instance for EMS ID [#{@cfg[:ems_id]}].", 1) if @ems.nil?
    do_exit("EMS ID [#{@cfg[:ems_id]}] failed authentication check.", 1) unless @ems.authentication_check.first

    @filtered_events = @ems.blacklisted_event_names
    _log.info("#{log_prefix} Event Catcher skipping the following events:")
    $log.log_hashes(@filtered_events)

    configure_event_flooding_prevention if worker_settings.try(:[], :flooding_monitor_enabled)

    # Global Work Queue
    @queue = Queue.new
  end

  def configure_event_flooding_prevention
    flood_handler = self.class.dedup_handler

    flood_handler.duplicate_window    = 1.minute
    flood_handler.window_slot_width   = 6.seconds
    flood_handler.progress_threshold  = 100
    flood_handler.duplicate_threshold = worker_settings[:flooding_events_per_minute]
    flood_handler.throw_exception_when_blocked = false

    flood_handler.logger = _log
    flood_handler.descriptor    = ->(_meth, *args) { event_dedup_descriptor(args[0]) }
    flood_handler.key_generator = ->(_meth, *args) { event_dedup_key(args[0]) }

    self.class.dedup_instance_method(:queue_event)

    _log.info("Event flood_handler settings:")<commit_msg>Fix event_catcher blacklisted events logging<commit_after>require 'thread'
require 'concurrent/atomic/event'
require 'util/duplicate_blocker'

class ManageIQ::Providers::BaseManager::EventCatcher::Runner < ::MiqWorker::Runner
  class EventCatcherHandledException < StandardError
  end

  include DuplicateBlocker

  OPTIONS_PARSER_SETTINGS = ::MiqWorker::Runner::OPTIONS_PARSER_SETTINGS + [
    [:ems_id, 'EMS Instance ID', String],
  ]

  def after_initialize
    @ems = ExtManagementSystem.find(@cfg[:ems_id])
    do_exit("Unable to find instance for EMS ID [#{@cfg[:ems_id]}].", 1) if @ems.nil?
    do_exit("EMS ID [#{@cfg[:ems_id]}] failed authentication check.", 1) unless @ems.authentication_check.first

    @filtered_events = @ems.blacklisted_event_names
    _log.info("#{log_prefix} Event Catcher skipping the following events:\n#{@filtered_events.to_a.join("\n")}")

    configure_event_flooding_prevention if worker_settings.try(:[], :flooding_monitor_enabled)

    # Global Work Queue
    @queue = Queue.new
  end

  def configure_event_flooding_prevention
    flood_handler = self.class.dedup_handler

    flood_handler.duplicate_window    = 1.minute
    flood_handler.window_slot_width   = 6.seconds
    flood_handler.progress_threshold  = 100
    flood_handler.duplicate_threshold = worker_settings[:flooding_events_per_minute]
    flood_handler.throw_exception_when_blocked = false

    flood_handler.logger = _log
    flood_handler.descriptor    = ->(_meth, *args) { event_dedup_descriptor(args[0]) }
    flood_handler.key_generator = ->(_meth, *args) { event_dedup_key(args[0]) }

    self.class.dedup_instance_method(:queue_event)

    _log.info("Event flood_handler settings:")
{'fraction_non_alphanumeric': 0.10790725326991676, 'fraction_numerical': 0.00535077288941736, 'mean_word_length': 5.2430426716141, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4555423', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1088, 'n_words': 190}