Skip to content

Commit

Permalink
option to bypass rule tree (#655)
Browse files Browse the repository at this point in the history
* add option to bypass rule tree
* make rules a tuple
* update changelog
  • Loading branch information
ekneg54 authored Aug 27, 2024
1 parent a9880b7 commit 4b5694d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 25 additions & 0 deletions logprep/abc/processor.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -109,6 +110,8 @@ class Config(Component.Config):
"_specific_tree",
"_generic_tree",
"result",
"_bypass_rule_tree",
"_rules",
]

rule_class: "Rule"
Expand All @@ -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"):
Expand All @@ -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):
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 4b5694d

Please sign in to comment.