Skip to content

Commit

Permalink
fix generic_adder tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dtrai2 committed Nov 7, 2024
1 parent 926c064 commit f29b24f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
2 changes: 1 addition & 1 deletion logprep/processor/base/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ def __init__(
message = (
"The following fields could not be written, because "
"one or more subfields existed and could not be extended: "
f"{skipped_fields}"
f"{', '.join(skipped_fields)}"
)
super().__init__(message, event, rule)
22 changes: 4 additions & 18 deletions logprep/processor/generic_adder/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@

from logprep.abc.processor import Processor
from logprep.factory_error import InvalidConfigurationError
from logprep.processor.base.exceptions import FieldExistsWarning
from logprep.processor.generic_adder.mysql_connector import MySQLConnector
from logprep.processor.generic_adder.rule import GenericAdderRule
from logprep.util.helper import add_field_to, get_dotted_field_value
from logprep.util.helper import get_dotted_field_value, add_batch_to


def sql_config_validator(_, attribute, value):
Expand Down Expand Up @@ -225,29 +224,16 @@ def _apply_rules(self, event: dict, rule: GenericAdderRule):
FieldExistsWarning
Raises if an addition would overwrite an existing field or value.
"""
conflicting_fields = []

use_db = rule.db_target and self._db_table
if use_db:
self._update_db_table()
items_to_add = self._get_items_to_add_from_db(event, rule)
else:
items_to_add = rule.add.items()

# Add the items to the event
for dotted_field, value in items_to_add:
add_successful = add_field_to(
event,
target_field=dotted_field,
content=value,
extends_lists=rule.extend_target_list,
overwrite_output_field=rule.overwrite_target,
)
if not add_successful:
conflicting_fields.append(dotted_field)

if conflicting_fields:
raise FieldExistsWarning(rule, event, conflicting_fields)
if items_to_add:
targets, contents = zip(*items_to_add)
add_batch_to(event, targets, contents, rule.extend_target_list, rule.overwrite_target)

def _get_items_to_add_from_db(self, event: dict, rule: GenericAdderRule) -> list:
"""Get the sub part of the value from the event using a regex pattern"""
Expand Down

0 comments on commit f29b24f

Please sign in to comment.