Skip to content

Commit

Permalink
convert labeler label values to lists in prefixed_label property
Browse files Browse the repository at this point in the history
- Ensures all values in the `prefixed_label` dictionary are lists.
- Adds a unit test to validate the behavior for labeler rules.
  • Loading branch information
dtrai2 committed Dec 23, 2024
1 parent af7d38e commit 35bf7a1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion logprep/processor/labeler/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def label(self) -> dict:

@property
def prefixed_label(self) -> dict:
return {f"label.{key}": value for key, value in self.label.items()}
return {f"label.{key}": list(value) for key, value in self.label.items()}

def conforms_to_schema(self, schema: LabelingSchema) -> bool:
"""Check if labels are valid."""
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/processor/labeler/test_labeler_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# pylint: disable=missing-function-docstring
# pylint: disable=wrong-import-position
from copy import deepcopy

import pytest

from logprep.filter.expression.filter_expression import StringFilterExpression
Expand Down Expand Up @@ -268,3 +269,13 @@ def test_complex_lucene_regex_does_not_match_returns_true_for_matching_document(
assert not rule.matches({"applyrule": "UPloXXXX"})
assert not rule.matches({"applyrule": "88888888"})
assert not rule.matches({"applyrule": "UPlo$$7"})

def test_prefixed_label_property_is_a_dicts_with_only_list_values(self):
rule_definition = {
"filter": 'applyrule: "yes"',
"labeler": {"label": {"reporter": {"windows"}}}, # label is given as set
}
rule = LabelerRule._create_from_dict(rule_definition)
assert all(
isinstance(val, list) for val in rule.prefixed_label.values()
), "prefixed_labels contain non-list values"

0 comments on commit 35bf7a1

Please sign in to comment.