feat: change relation between alerts and incidents to work with fingerprints instead of alert ids
Closes #2398
📑 Description
✅ Checks
- [ ] 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
- [ ] All the tests have passed
ℹ Additional Information
Summary by CodeRabbit
Release Notes
-
New Features
- Introduced fingerprint-based identification for alerts, replacing event IDs in incident management.
- Added new API endpoints for fetching random workflow templates and enhanced workflow execution details.
- Enhanced incident data with associated alerts for improved incident management.
-
Bug Fixes
- Improved error handling in workflow management and alert processing.
-
Documentation
- Updated test cases to reflect changes in alert handling and ensure accuracy in incident management.
-
Chores
- Enhanced test fixtures for better alert state management and performance metrics.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| keep | ⬜️ Ignored (Inspect) | Visit Preview | Dec 2, 2024 3:06pm |
@coderabbitai review
:white_check_mark: Actions performed
Review triggered.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
Walkthrough
The changes in this pull request primarily focus on transitioning the alert management system from using alert IDs to fingerprints for associating alerts with incidents. This involves modifications across various components, including the UI, database models, API routes, and tests. New database tables are introduced to store the latest alerts and their relationships with incidents, enhancing the system's efficiency and reducing the size of related tables. The overall control flow and logic remain intact, but the underlying data structures and identifiers have been updated to reflect this new approach.
Changes
| File Path | Change Summary |
|---|---|
keep-ui/app/alerts/alert-associate-incident-modal.tsx |
Modified associateAlertsHandler to send fingerprint instead of event_id in POST request payload. |
keep-ui/app/incidents/[id]/alerts/incident-alert-menu.tsx |
Updated onRemove to send fingerprint instead of alert.event_id in DELETE request payload. |
keep-ui/entities/incidents/model/models.ts |
Added fingerprint: string property to IncidentDto interface. |
keep/api/bl/incidents_bl.py |
Updated methods to accept alert fingerprints instead of UUIDs for adding and deleting alerts from incidents. |
keep/api/core/db.py |
Introduced enrich_incidents_with_alerts, updated functions to use fingerprints, and added methods for managing last alerts. |
keep/api/models/db/alert.py |
Added LastAlert and LastAlertToIncident classes; modified existing relationships in AlertToIncident and Incident classes. |
keep/api/models/db/migrations/versions/2024-11-13-22-48_bdae8684d0b4.py |
Created migration script for new lastalert and lastalerttoincident tables, including data population logic. |
keep/api/routes/incidents.py |
Updated add_alerts_to_incident and delete_alerts_from_incident to use fingerprints instead of alert IDs. |
keep/api/routes/workflows.py |
Added is_v2 parameter to get_workflows, modified run_workflow, and introduced a new endpoint for fetching random templates. |
keep/api/tasks/process_event_task.py |
Added call to set_last_alert after creating an AlertDto instance. |
keep/api/utils/enrichment_helpers.py |
Updated convert_db_alerts_to_dto_alerts to use LastAlertToIncident and added session management. |
keep/rulesengine/rulesengine.py |
Changed assign_alert_to_incident to use fingerprints instead of alert IDs. |
tests/conftest.py |
Enhanced fixtures to manage LastAlert records and added timing logic for alert setup. |
tests/test_incidents.py |
Updated tests to handle fingerprints for adding/removing alerts from incidents. |
tests/test_metrics.py |
Modified test_add_remove_alert_to_incidents to use fingerprints instead of alert IDs. |
tests/test_rules_engine.py |
Updated tests to call set_last_alert and handle alert fingerprints correctly. |
Assessment against linked issues
| Objective | Addressed | Explanation |
|---|---|---|
| Change relation between Alerts and Incidents to work with fingerprints instead of alert_ids (#2398) | ✅ | |
| Introduce a new table for latest alerts to simplify finding the last appearance (#2398) | ✅ | |
| Migrate existing data to the new structure while maintaining functionality (#2398) | ✅ |
🐰 "In the fields where alerts play,
Fingerprints now lead the way.
Incidents and alerts entwine,
A new structure, oh so fine!
With every hop, we track with glee,
Last appearances, clear as can be!" 🐇✨
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Generate unit testing code for this file.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai generate unit testing code for this file.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and generate unit testing code.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.@coderabbitai help me debug CodeRabbit configuration file.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
Codecov Report
Attention: Patch coverage is 39.56044% with 110 lines in your changes missing coverage. Please review.
Project coverage is 44.14%. Comparing base (
3ddeacc) to head (dec8598). Report is 2 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #2473 +/- ##
==========================================
+ Coverage 44.07% 44.14% +0.07%
==========================================
Files 156 156
Lines 14837 14910 +73
==========================================
+ Hits 6539 6582 +43
- Misses 8298 8328 +30
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.