diff --git a/CHANGELOG.md b/CHANGELOG.md index e1ff45409..c4a34c054 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ ### Improvements * adds ability to bypass the processing of events if there is no pipeline. This is useful for pure connector deployments. +* adds experimental feature to bypass the rule tree by setting `LOGPREP_BYPASS_RULE_TREE` environment variable ### Bugfix diff --git a/logprep/abc/processor.py b/logprep/abc/processor.py index 8ca609538..34243a479 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,8 @@ class Config(Component.Config): "_specific_tree", "_generic_tree", "result", + "_bypass_rule_tree", + "_rules", ] rule_class: "Rule" @@ -117,6 +120,8 @@ class Config(Component.Config): _specific_tree: RuleTree _generic_tree: RuleTree _strategy = None + _bypass_rule_tree: bool + _rules: tuple["Rule"] result: ProcessorResult def __init__(self, name: str, configuration: "Processor.Config"): @@ -137,6 +142,11 @@ def __init__(self, name: str, configuration: "Processor.Config"): ) self.has_custom_tests = False self.result = None + self._bypass_rule_tree = False + if os.environ.get("LOGPREP_BYPASS_RULE_TREE"): + self._bypass_rule_tree = True + self._rules = self.rules + logger.info("Bypassing rule tree for processor %s", self.name) @property def _specific_rules(self): @@ -195,10 +205,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) + 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): + + @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 self._rules: + if rule.matches(event): + _process_rule(rule, event) + def _process_rule_tree(self, event: dict, tree: RuleTree): applied_rules = set()