Skip to content

Commit

Permalink
feat: sort fingerprint fields
Browse files Browse the repository at this point in the history
  • Loading branch information
shahargl committed Aug 3, 2024
1 parent 18066fc commit 38949ce
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions keep/providers/openobserve_provider/openobserve_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,35 @@ def _format_alert(
"Calculating fingerprint fields",
extra={"fingerprint_fields": fingerprint_fields},
)

# sort the fields to ensure the fingerprint is consistent
# for e.g. host1, host2 is the same as host2, host1
for field in fingerprint_fields:
try:
field_attr = getattr(alert_dto, field)
if "," not in field_attr:
continue
# sort it lexographically
logger.info(
"Sorting field attributes",
extra={"field": field, "field_attr": field_attr},
)
sorted_field_attr = sorted(field_attr.replace(" ", "").split(","))
sorted_field_attr = ", ".join(sorted_field_attr)
logger.info(
"Sorted field attributes",
extra={"field": field, "sorted_field_attr": sorted_field_attr},
)
# set the attr
setattr(alert_dto, field, sorted_field_attr)
except AttributeError:
pass
except Exception as e:
logger.error(
"Error while sorting field attributes",
extra={"field": field, "error": e},
)

alert_dto.fingerprint = OpenobserveProvider.get_alert_fingerprint(
alert_dto, fingerprint_fields=fingerprint_fields
)
Expand Down

0 comments on commit 38949ce

Please sign in to comment.