Skip to content

Commit

Permalink
change order of preprocessors and adjust test to reflect correct value
Browse files Browse the repository at this point in the history
  • Loading branch information
djkhl committed Feb 27, 2025
1 parent 79c2e29 commit 132f173
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
23 changes: 12 additions & 11 deletions logprep/abc/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,16 @@ class Config(Connector.Config):
events by environment variables. To activate this preprocessor the fields value has to be
a mapping from the target field name (key) to the environment variable name (value).
- `add_full_event_to_target_field` - If required it is possible to automatically write
all event fields to one singular field or subfield. If needed as an escaped string. The exact fields
in the event do not have to be known to use this preprocessor. To use this preprocessor
the fields :code:`format` and :code:`target_field` have to bet set. When the format :code:`str` ist set
the event is automatically escaped. This can be used to identify and resolve mapping errors thrown by
opensearch.
- :code:`format` - specifies the format which the event is written in. The default format ist
:code:`str` which leads to automatic json escaping of the given event. Also possible is the value :code:`dict`
which writes the event as mapping to the specified :code:`target_field`.
all event fields to one singular field or subfield. If needed as an escaped string.
The exact fields in the event do not have to be known to use this preprocessor. To use this
preprocessor the fields :code:`format` and :code:`target_field` have to bet set. When the
format :code:`str` ist set the event is automatically escaped. This can be used to identify
and resolve mapping errors thrown by opensearch.
- :code:`format` - specifies the format which the event is written in. The default
format ist :code:`str` which leads to automatic json escaping of the given event. Also
possible is the value :code:`dict` which writes the event as mapping to the specified
:code:`target_field`.
- :code:`target_field` - specifies the field to which the event should be written to.
the default is :code:`event.original`
"""
Expand Down Expand Up @@ -319,6 +320,8 @@ def get_next(self, timeout: float) -> dict | None:
if not isinstance(event, dict):
raise CriticalInputError(self, "not a dict", event)
try:
if self._add_full_event_to_target_field:
self._write_full_event_to_target_field(event, raw_event)
if self._add_hmac:
event = self._add_hmac_to(event, raw_event)
if self._add_version_info:
Expand All @@ -329,8 +332,6 @@ def get_next(self, timeout: float) -> dict | None:
self._add_arrival_timedelta_information_to_event(event)
if self._add_env_enrichment:
self._add_env_enrichment_to_event(event)
if self._add_full_event_to_target_field:
self._write_full_event_to_target_field(event, raw_event)
except FieldExistsWarning as error:
raise CriticalInputError(self, error.args[0], event) from error
return event
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/connector/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,9 @@ def test_add_full_event_to_targetfield_vs_version_info_target(self):
connector._get_event = mock.MagicMock(return_value=(test_event, None))
result = connector.get_next(0.01)
expected = {
"any": {"content": '"{\\"any\\":\\"content\\"}"'}
} # TODO: define expected and adapt
"any": {"content": '"{\\"any\\":\\"content\\"}"'},
"version_info": {"logprep": "", "configuration": ""},
}
assert result == expected, f"{expected} is not the same as {result}"

def test_add_full_event_to_target_field_with_dict_format(self):
Expand Down

0 comments on commit 132f173

Please sign in to comment.