fix: update endsAt when resolving alerts via API
Description
Fixes issue #4554 where was not being updated when resolving alerts via the API.
Problem
When posting an alert via the API with only set (to resolve an existing alert), the field was not being updated. This happened due to two issues:
-
Merge condition too restrictive: The merge logic in only merged alerts when there was an overlap in activity range. When resolving an alert, the new (in the past) doesn't overlap with the old (future timeout), so no merge occurred.
-
Merge function bug: The function in didn't properly handle the case where a new resolved alert is merged with an existing unresolved alert.
Solution
-
Updated merge condition: Modified to also merge alerts when updating an existing alert (same fingerprint), allowing updates like setting to resolve an alert even without overlap.
-
Fixed Merge function: Updated to always use the new alert's when it is resolved, ensuring that resolving an alert via API properly updates the timestamp.
Testing
- Verified the fix handles the scenario described in #4554
- Existing merge tests should continue to pass
- The fix maintains backward compatibility with existing alert merging behavior
Type of Change
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
Fixes #4554
I believe this behavior is intentional, see here.