Skip to content

Commit

Permalink
make rules a tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
ekneg54 committed Aug 26, 2024
1 parent bed01ed commit 6dc6509
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions logprep/abc/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class Config(Component.Config):
"_generic_tree",
"result",
"_bypass_rule_tree",
"_rules",
]

rule_class: "Rule"
Expand All @@ -120,6 +121,7 @@ class Config(Component.Config):
_generic_tree: RuleTree
_strategy = None
_bypass_rule_tree: bool
_rules: tuple["Rule"]
result: ProcessorResult

def __init__(self, name: str, configuration: "Processor.Config"):
Expand All @@ -142,6 +144,8 @@ def __init__(self, name: str, configuration: "Processor.Config"):
self.result = None
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):
Expand Down Expand Up @@ -171,7 +175,7 @@ def rules(self):
-------
rules: list[Rule]
"""
return [*self._generic_rules, *self._specific_rules]
return (*self._generic_rules, *self._specific_rules)

@property
def metric_labels(self) -> dict:
Expand Down Expand Up @@ -201,21 +205,21 @@ 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)
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, rules: List["Rule"]):
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 rules:
for rule in self._rules:
if rule.matches(event):
_process_rule(rule, event)

Expand Down

0 comments on commit 6dc6509

Please sign in to comment.