Skip to content

Commit

Permalink
Only filter by app & title keys by default
Browse files Browse the repository at this point in the history
Matching against url, editor payload keys, etc could be problematic. The existing rules are written against these two fields, as far as I can tell.
  • Loading branch information
iloveitaly committed Jun 8, 2022
1 parent 8aaa353 commit b085d42
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions aw_transform/classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Rule:
ignore_case: bool

def __init__(self, rules: Dict[str, Any]):
self.select_keys = rules.get("select_keys", None)
self.select_keys = rules.get("select_keys", ["app", "title"])
self.ignore_case = rules.get("ignore_case", False)

# NOTE: Also checks that the regex isn't an empty string (which would erroneously match everything)
Expand All @@ -29,10 +29,15 @@ def __init__(self, rules: Dict[str, Any]):
)

def match(self, e: Event) -> bool:
if self.select_keys:
values = [e.data.get(key, None) for key in self.select_keys]
else:
# `data` contains keys like 'app', 'title'
# by default, the rule regex is matched against all values

if self.select_keys == 'all'
values = list(e.data.values())
elif self.select_keys:
values = [e.data.get(key, None) for key in self.select_keys]

# although there is a `type` field on the rule name, right now the only valid type is regex
if self.regex:
for val in values:
if isinstance(val, str) and self.regex.search(val):
Expand All @@ -45,6 +50,7 @@ def categorize(events: List[Event], classes: List[Tuple[Category, Rule]]):


def _categorize_one(e: Event, classes: List[Tuple[Category, Rule]]) -> Event:
# TODO can we add a color here too? why is color rendered on the frontend?
e.data["$category"] = _pick_category(
[_cls for _cls, rule in classes if rule.match(e)]
)
Expand Down

0 comments on commit b085d42

Please sign in to comment.