Skip to content

Commit

Permalink
fix(deduplication): allow nested fields in dedup (#2232)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahargl authored and VladimirFilonov committed Oct 18, 2024
1 parent 7276ab4 commit 46acbef
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
8 changes: 5 additions & 3 deletions keep/api/tasks/process_event_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def __handle_formatted_events(
for key, value in enriched_formatted_event.dict().items():
if isinstance(value, dict):
for nested_key in value.keys():
fields.append(f"{key}_{nested_key}")
fields.append(f"{key}.{nested_key}")
else:
fields.append(key)

Expand All @@ -326,7 +326,7 @@ def __handle_formatted_events(
fields=fields,
provider_id=enriched_formatted_event.providerId,
provider_type=enriched_formatted_event.providerType,
session=session
session=session,
)

logger.debug(
Expand Down Expand Up @@ -386,7 +386,9 @@ def __handle_formatted_events(
# Now we need to run the rules engine
try:
rules_engine = RulesEngine(tenant_id=tenant_id)
incidents: List[IncidentDto] = rules_engine.run_rules(enriched_formatted_events, session=session)
incidents: List[IncidentDto] = rules_engine.run_rules(
enriched_formatted_events, session=session
)

# TODO: Replace with incidents workflow triggers. Ticket: https://github.com/keephq/keep/issues/1527
# if new grouped incidents were created, we need to push them to the client
Expand Down
11 changes: 9 additions & 2 deletions keep/providers/base/base_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,17 @@ def get_alert_fingerprint(alert: AlertDto, fingerprint_fields: list = []) -> str
fingerprint = hashlib.sha256()
event_dict = alert.dict()
for fingerprint_field in fingerprint_fields:
fingerprint_field_value = event_dict.get(fingerprint_field, None)
keys = fingerprint_field.split(".")
fingerprint_field_value = event_dict
for key in keys:
if isinstance(fingerprint_field_value, dict):
fingerprint_field_value = fingerprint_field_value.get(key, None)
else:
fingerprint_field_value = None
break
if isinstance(fingerprint_field_value, (list, dict)):
fingerprint_field_value = json.dumps(fingerprint_field_value)
if fingerprint_field_value:
if fingerprint_field_value is not None:
fingerprint.update(str(fingerprint_field_value).encode())
return fingerprint.hexdigest()

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "keep"
version = "0.26.0"
version = "0.26.1"
description = "Alerting. for developers, by developers."
authors = ["Keep Alerting LTD"]
readme = "README.md"
Expand Down

0 comments on commit 46acbef

Please sign in to comment.