keephq / keep

The open-source alert management and AIOps platform
https://platform.keephq.dev
Other
3.25k stars 262 forks source link

[🐛 Bug]: __handle_formatted_events new pull save #1306

Closed shahargl closed 2 months ago

shahargl commented 3 months ago

Looking an this code: https://github.com/keephq/keep/blob/main/keep/api/tasks/process_event_task.py#L188

  1. The code iterates on events and then checks event.isDuplicate - out side of the for loop - so its undefined behavior.
  2. As deduplicated events already filtered out few lines later with filter(lambda event: not event.isDuplicate, formatted_events) ), I'm not sure why there is save_if_duplicate as it maybe screws the current alert deduplication mechanism
    
    for event in formatted_events:
        event_hash, event_deduplicated = alert_deduplicator.is_deduplicated(event)
        event.alert_hash = event_hash
        event.isDuplicate = event_deduplicated

if event.isDuplicate and not save_if_duplicate: logger.info( "Alert is not saved as a duplicate", extra={ "provider_type": provider_type, "num_of_alerts": len(formatted_events), "provider_id": provider_id, "tenant_id": tenant_id, }, ) return None

shahargl commented 3 months ago

CleanShot 2024-06-29 at 18 20 58@2x

Matvey-Kuk commented 2 months ago

@shahargl thank you for fixing this <3