コード例 #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)
コード例 #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)
コード例 #3
0
    def test_grafana(self):
        start_grafana_pipeline(_registry=self.events_processes_registry)
        grafana_annotator = get_events_process(EVENTS_GRAFANA_ANNOTATOR_ID, _registry=self.events_processes_registry)
        grafana_aggregator = get_events_process(EVENTS_GRAFANA_AGGREGATOR_ID, _registry=self.events_processes_registry)
        grafana_postman = get_grafana_postman(_registry=self.events_processes_registry)

        time.sleep(EVENTS_SUBSCRIBERS_START_DELAY)

        try:
            self.assertIsInstance(grafana_annotator, GrafanaAnnotator)
            self.assertTrue(grafana_annotator.is_alive())
            self.assertEqual(grafana_annotator._registry, self.events_main_device._registry)
            self.assertEqual(grafana_annotator._registry, self.events_processes_registry)

            self.assertIsInstance(grafana_aggregator, GrafanaEventAggregator)
            self.assertTrue(grafana_aggregator.is_alive())
            self.assertEqual(grafana_aggregator._registry, self.events_main_device._registry)
            self.assertEqual(grafana_aggregator._registry, self.events_processes_registry)

            self.assertIsInstance(grafana_postman, GrafanaEventPostman)
            self.assertTrue(grafana_postman.is_alive())
            self.assertEqual(grafana_postman._registry, self.events_main_device._registry)
            self.assertEqual(grafana_postman._registry, self.events_processes_registry)

            grafana_aggregator.time_window = 1

            set_grafana_url("http://localhost", _registry=self.events_processes_registry)

            with unittest.mock.patch("requests.post") as mock:
                for runs in range(1, 4):
                    with self.wait_for_n_events(grafana_annotator, count=10, timeout=1):
                        for _ in range(10):
                            self.events_main_device.publish_event(
                                ClusterHealthValidatorEvent.NodeStatus(severity=Severity.NORMAL))
                    time.sleep(1)

                self.assertEqual(mock.call_count, runs * 5)
                self.assertEqual(
                    mock.call_args.kwargs["json"]["tags"],
                    ["ClusterHealthValidatorEvent", "NORMAL", "events", "NodeStatus"],
                )

            self.assertEqual(self.events_main_device.events_counter, grafana_annotator.events_counter)
            self.assertEqual(grafana_annotator.events_counter, grafana_aggregator.events_counter)
            self.assertLessEqual(grafana_postman.events_counter, grafana_aggregator.events_counter)
        finally:
            grafana_annotator.stop(timeout=1)
            grafana_aggregator.stop(timeout=1)
            grafana_postman.stop(timeout=1)