From bed01ed3dd52ecb5c1dcaa74bf8b86fd1abbfeb8 Mon Sep 17 00:00:00 2001 From: ekneg54 Date: Mon, 26 Aug 2024 19:23:08 +0200 Subject: [PATCH] add option to bypass rule tree --- logprep/abc/processor.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/logprep/abc/processor.py b/logprep/abc/processor.py index 8ca609538..a3673d3e3 100644 --- a/logprep/abc/processor.py +++ b/logprep/abc/processor.py @@ -1,6 +1,7 @@ """Abstract module for processors""" import logging +import os from abc import abstractmethod from pathlib import Path from typing import TYPE_CHECKING, List, Optional @@ -109,6 +110,7 @@ class Config(Component.Config): "_specific_tree", "_generic_tree", "result", + "_bypass_rule_tree", ] rule_class: "Rule" @@ -117,6 +119,7 @@ class Config(Component.Config): _specific_tree: RuleTree _generic_tree: RuleTree _strategy = None + _bypass_rule_tree: bool result: ProcessorResult def __init__(self, name: str, configuration: "Processor.Config"): @@ -137,6 +140,8 @@ def __init__(self, name: str, configuration: "Processor.Config"): ) self.has_custom_tests = False self.result = None + if os.environ.get("LOGPREP_BYPASS_RULE_TREE"): + self._bypass_rule_tree = True @property def _specific_rules(self): @@ -195,10 +200,25 @@ def process(self, event: dict) -> ProcessorResult: """ self.result = ProcessorResult(processor_name=self.name, event=event) logger.debug(f"{self.describe()} processing event {event}") + if self._bypass_rule_tree: + self._process_all_rules(event, self.rules) + return self.result self._process_rule_tree(event, self._specific_tree) self._process_rule_tree(event, self._generic_tree) return self.result + def _process_all_rules(self, event: dict, rules: List["Rule"]): + + @Metric.measure_time() + def _process_rule(rule, event): + self._apply_rules_wrapper(event, rule) + rule.metrics.number_of_processed_events += 1 + return event + + for rule in rules: + if rule.matches(event): + _process_rule(rule, event) + def _process_rule_tree(self, event: dict, tree: RuleTree): applied_rules = set()