Skip to content

fix: incident merging #4058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions keep/api/core/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -4373,16 +4373,11 @@ def merge_incidents_to_id(
enrich_incidents_with_alerts(tenant_id, source_incidents, session=session)

merged_incident_ids = []
skipped_incident_ids = []
failed_incident_ids = []
for source_incident in source_incidents:
source_incident_alerts_fingerprints = [
alert.fingerprint for alert in source_incident._alerts
]
if not source_incident_alerts_fingerprints:
logger.info(f"Source incident {source_incident.id} doesn't have alerts")
skipped_incident_ids.append(source_incident.id)
continue
source_incident.merged_into_incident_id = destination_incident.id
source_incident.merged_at = datetime.now(tz=timezone.utc)
source_incident.status = IncidentStatus.MERGED.value
Expand Down Expand Up @@ -4413,7 +4408,7 @@ def merge_incidents_to_id(

session.commit()
session.refresh(destination_incident)
return merged_incident_ids, skipped_incident_ids, failed_incident_ids
return merged_incident_ids, failed_incident_ids


def get_alerts_count(
Expand Down
1 change: 0 additions & 1 deletion keep/api/models/incident.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ class MergeIncidentsRequestDto(BaseModel):

class MergeIncidentsResponseDto(BaseModel):
merged_incident_ids: list[UUID]
skipped_incident_ids: list[UUID]
failed_incident_ids: list[UUID]
destination_incident_id: UUID
message: str
Expand Down
10 changes: 5 additions & 5 deletions keep/api/routes/incidents.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def merge_incidents(
)

try:
merged_ids, skipped_ids, failed_ids = merge_incidents_to_id(
merged_ids, failed_ids = merge_incidents_to_id(
tenant_id,
command.source_incident_ids,
command.destination_incident_id,
Expand All @@ -517,14 +517,12 @@ def merge_incidents(
else:
message = f"{pluralize(len(merged_ids), 'incident')} merged into {command.destination_incident_id} successfully"

if skipped_ids:
message += f", {pluralize(len(skipped_ids), 'incident')} were skipped"
if failed_ids:
message += f", {pluralize(len(failed_ids), 'incident')} failed to merge"
raise HTTPException(f"Some incidents failed to merge. {message}")

return MergeIncidentsResponseDto(
merged_incident_ids=merged_ids,
skipped_incident_ids=skipped_ids,
failed_incident_ids=failed_ids,
destination_incident_id=command.destination_incident_id,
message=message,
Expand Down Expand Up @@ -847,7 +845,9 @@ def change_incident_status(

incident_bl = IncidentBl(tenant_id, session)

new_incident_dto = incident_bl.change_status(incident_id, change.status, authenticated_entity)
new_incident_dto = incident_bl.change_status(
incident_id, change.status, authenticated_entity
)

return new_incident_dto

Expand Down