keep icon indicating copy to clipboard operation
keep copied to clipboard

[🐛 Bug]: Manual notes and dismissions are disappearing when new event arrives for an alert

Open imorph opened this issue 2 years ago • 1 comments

Describe the bug

  1. I am making a note for an alert (or dismiss it)
  2. after some time new event of the exact same alert arrives (its deduplicated to the same alert)
  3. this arrival updates some fields AND wipes out note as well as returns alert from dismissed

To Reproduce Create alert:

curl -X POST 'https://keep-host/alerts/event/keep' \
  --header 'X-API-KEY: XXXXXXXXXXXXXXXXXXXXXXX' \
  --header 'Content-Type: application/json' \
  --data-raw $'{
  "id": "ieury777777",
  "name": "this_is_test_alert_number7",
  "severity": "critical",
  "status":"firing",
  "lastReceived":"2024-10-24T14:16:00.000Z",
  "environment": "test",
  "service": "test",
  "message": "test",
  "description": "this is test"
}'

Check for alert by fingerprint:

{
  "id": "ieury777777",
  "name": "this_is_test_alert_number7",
  "status": "firing",
  "severity": "critical",
  "lastReceived": "2024-10-24T14:16:00.000Z",
  "firingStartTime": "2024-10-24T14:16:00.000Z",
  "environment": "test",
  "isFullDuplicate": false,
  "isPartialDuplicate": false,
  "duplicateReason": null,
  "service": "test",
  "source": [
    "keep"
  ],
  "apiKeyRef": "api_access",
  "message": "test",
  "description": "this is test",
  "pushed": true,
  "event_id": "bcd7752c-bf27-4838-9541-f145aa7f36e0",
  "url": null,
  "labels": {},
  "fingerprint": "7b20096c981ecfe3229604adfb38932ea000f7f43c0ef6905adac36a56d752d5",
  "deleted": false,
  "dismissUntil": null,
  "dismissed": false,
  "assignee": null,
  "providerId": null,
  "providerType": "keep",
  "note": null,
  "startedAt": "2024-10-24 15:34:14.388000",
  "isNoisy": false,
  "enriched_fields": [],
  "incident": null,
  "alert_hash": "6396ebf707eff1acae0b21932a224413c60385effeb7df21c7a9a1f7d5d92216"
}

add note in UI, and check for alert again through API:

{
  "id": "ieury777777",
  "name": "this_is_test_alert_number7",
  "status": "firing",
  "severity": "critical",
  "lastReceived": "2024-10-24T14:16:00.000Z",
  "firingStartTime": "2024-10-24T14:16:00.000Z",
  "environment": "test",
  "isFullDuplicate": false,
  "isPartialDuplicate": false,
  "duplicateReason": null,
  "service": "test",
  "source": [
    "keep"
  ],
  "apiKeyRef": "api_access",
  "message": "test",
  "description": "this is test",
  "pushed": true,
  "event_id": "bcd7752c-bf27-4838-9541-f145aa7f36e0",
  "url": null,
  "labels": {},
  "fingerprint": "7b20096c981ecfe3229604adfb38932ea000f7f43c0ef6905adac36a56d752d5",
  "deleted": false,
  "dismissUntil": null,
  "dismissed": false,
  "assignee": null,
  "providerId": null,
  "providerType": "keep",
  "note": "<p>some note</p>",
  "startedAt": "2024-10-24 15:34:14.388000",
  "isNoisy": false,
  "enriched_fields": [
    "note"
  ],
  "incident": null,
  "disposable_note": {
    "value": "<p>some note</p>",
    "timestamp": 1729784247.012157
  },
  "alert_hash": "6396ebf707eff1acae0b21932a224413c60385effeb7df21c7a9a1f7d5d92216"
}

for some reason note now disposable

Send duplicate of this event again through API (with description field updated -- which is not part of fingerprinting), and check it again:

{
  "id": "ieury777777",
  "name": "this_is_test_alert_number7",
  "status": "firing",
  "severity": "critical",
  "lastReceived": "2024-10-24T14:17:00.000Z",
  "firingStartTime": "2024-10-24T14:16:00.000Z",
  "environment": "test",
  "isFullDuplicate": false,
  "isPartialDuplicate": true,
  "duplicateReason": null,
  "service": "test",
  "source": [
    "keep"
  ],
  "apiKeyRef": "api_access",
  "message": "test",
  "description": "desc is updated",
  "pushed": true,
  "event_id": "cbf9e1c8-0c18-46b4-afa1-e1dfcce01218",
  "url": null,
  "labels": {},
  "fingerprint": "7b20096c981ecfe3229604adfb38932ea000f7f43c0ef6905adac36a56d752d5",
  "deleted": false,
  "dismissUntil": null,
  "dismissed": false,
  "assignee": null,
  "providerId": null,
  "providerType": "keep",
  "note": null,
  "startedAt": "2024-10-24 15:34:14.388000",
  "isNoisy": false,
  "enriched_fields": [],
  "incident": null,
  "alert_hash": "c512d81a7a049175da0c560e0033b5f3d09c23afb8dd07f55611434cb222fe24"
}

note field is null now

Expected behavior notes and status of dismissions should persist throughout alert lifecycle

imorph avatar Oct 24 '24 15:10 imorph

The issue you're experiencing seems to be related to how the Keep platform handles updates to alert fields when new events arrive. Specifically, it appears that manual notes and dismissals are not being persisted across these updates, which is not the expected behavior.

The function responsible for updating alert fields when a new event arrives is __handle_formatted_events, which calls bulk_upsert_alert_fields to update the alert fields in the database. This function uses conflict resolution strategies to ensure that alert fields are either updated or inserted as needed [1][2].

However, it seems that the current implementation might not be correctly handling the persistence of manual changes like notes and dismissals. This could be due to how the fields are being updated or overwritten during the deduplication process.

To address this issue, you might need to review the logic in the bulk_upsert_alert_fields function to ensure that manual changes are preserved. This could involve modifying the update logic to retain existing values for fields like note and dismissed unless explicitly changed by the new event data.

To continue talking to Dosu, mention @dosu.

dosubot[bot] avatar Oct 24 '24 15:10 dosubot[bot]