keep icon indicating copy to clipboard operation
keep copied to clipboard

fix: Avoid race condition in set_last_alert

Open diegovb-sys opened this issue 1 month ago • 1 comments

Closes #5354

📑 Description

In order to face the race condition. it has been modified the checking strategy after if the value is present. With the current strategy, a query is built where we include the action in case of conflict, i.e when the lastalert already exists. Moreover, as this strategy depends on the underlying engine, it has been implemented for 3 engines:

  • SQLite
  • PostreSQL
  • MySQL

About the fails catching, it has been moved to the decorator.

With this modification race conditions should be avoided, when the same alert (tenant+fingerprint) comes in twice.

✅ Checks

  • [X] My pull request adheres to the code style of this project
  • [ ] My code requires changes to the documentation
  • [ ] I have updated the documentation as required
  • [X] All the tests have passed

ℹ Additional Information

Since the function modified is so called in the principal flow, be careful in its review.

diegovb-sys avatar Oct 14 '25 12:10 diegovb-sys

@diegovb-sys is attempting to deploy a commit to the KeepHQ Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Oct 14 '25 12:10 vercel[bot]

@diegovb-sys it looks like linter fails, wdyt can you fix it?

shahargl avatar Nov 16 '25 13:11 shahargl

Codecov Report

:x: Patch coverage is 23.07692% with 20 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 30.62%. Comparing base (97c263a) to head (eaf6d33). :warning: Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
keep/api/core/db_utils.py 26.31% 14 Missing :warning:
keep/api/core/db.py 14.28% 6 Missing :warning:

:exclamation: There is a different number of reports uploaded between BASE (97c263a) and HEAD (eaf6d33). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (97c263a) HEAD (eaf6d33)
2 1
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #5364       +/-   ##
===========================================
- Coverage   46.39%   30.62%   -15.78%     
===========================================
  Files         176      101       -75     
  Lines       18412    11656     -6756     
===========================================
- Hits         8543     3570     -4973     
+ Misses       9869     8086     -1783     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Nov 16 '25 14:11 codecov[bot]