Esempio n. 1
0
def start_events_device(
        log_dir: Optional[Union[str, Path]] = None,
        _registry: Optional[EventsProcessesRegistry] = None) -> None:
    if _registry is None:
        if log_dir is None:
            raise RuntimeError(
                "Should provide log_dir or instance of EventsProcessesRegistry"
            )
        _registry = create_default_events_process_registry(log_dir=log_dir)

    start_events_main_device(_registry=_registry)

    time.sleep(EVENTS_DEVICE_START_DELAY)

    start_events_logger(_registry=_registry)
    start_grafana_pipeline(_registry=_registry)
    start_events_analyzer(_registry=_registry)

    time.sleep(EVENTS_SUBSCRIBERS_START_DELAY)

    # Default filters.
    EventsSeverityChangerFilter(
        new_severity=Severity.WARNING,
        event_class=DatabaseLogEvent.DATABASE_ERROR,
        regex=
        r'.*workload prioritization - update_service_levels_from_distributed_data: an '
        r'error occurred while retrieving configuration').publish()
    DbEventsFilter(db_event=DatabaseLogEvent.BACKTRACE,
                   line='Rate-limit: supressed').publish()
    DbEventsFilter(db_event=DatabaseLogEvent.BACKTRACE,
                   line='Rate-limit: suppressed').publish()

    atexit.register(stop_events_device, _registry=_registry)
Esempio n. 2
0
def start_events_device(
        log_dir: Optional[Union[str, Path]] = None,
        _registry: Optional[EventsProcessesRegistry] = None) -> None:
    if _registry is None:
        if log_dir is None:
            raise RuntimeError(
                "Should provide log_dir or instance of EventsProcessesRegistry"
            )
        _registry = create_default_events_process_registry(log_dir=log_dir)

    start_events_main_device(_registry=_registry)

    time.sleep(EVENTS_DEVICE_START_DELAY)

    start_events_logger(_registry=_registry)
    start_grafana_pipeline(_registry=_registry)
    start_events_analyzer(_registry=_registry)

    time.sleep(EVENTS_SUBSCRIBERS_START_DELAY)

    # Default filters.
    DbEventsFilter(db_event=DatabaseLogEvent.BACKTRACE,
                   line='Rate-limit: supressed').publish()
    DbEventsFilter(db_event=DatabaseLogEvent.BACKTRACE,
                   line='Rate-limit: suppressed').publish()

    atexit.register(stop_events_device, _registry=_registry)
 def test_start_get_events_main_device(self):
     self.assertIsNone(
         get_events_main_device(_registry=self.events_processes_registry))
     start_events_main_device(_registry=self.events_processes_registry)
     events_device = get_events_main_device(
         _registry=self.events_processes_registry)
     try:
         self.assertIsInstance(events_device, EventsDevice)
         self.assertEqual(events_device.events_counter, 0)
         self.assertTrue(events_device.is_alive())
         self.assertTrue(events_device.subscribe_address)
     finally:
         events_device.stop(timeout=1)
    def setup_events_processes(cls, events_device: bool,
                               events_main_device: bool,
                               registry_patcher: bool):
        """Setup own copy of Events Device machinery."""

        cls.temp_dir = tempfile.mkdtemp()
        cls.events_processes_registry = EventsProcessesRegistry(
            log_dir=cls.temp_dir)
        if registry_patcher:
            cls.events_processes_registry_patcher = \
                unittest.mock.patch("sdcm.sct_events.base.SctEvent._events_processes_registry",
                                    cls.events_processes_registry)
            cls.events_processes_registry_patcher.start()
        if events_device:
            start_events_device(_registry=cls.events_processes_registry)
        elif events_main_device:
            start_events_main_device(_registry=cls.events_processes_registry)
            time.sleep(EVENTS_DEVICE_START_DELAY)
        cls.events_main_device = get_events_main_device(
            _registry=cls.events_processes_registry)