-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[WEB-5071] chore: implement webhook logging to MongoDB and fallback to database #7896
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
Conversation
…7887) - Added a new function `save_webhook_log` to log webhook requests and responses to MongoDB, with a fallback to the database if the MongoDB save fails. - Updated the `webhook_send_task` to utilize the new logging function. - Modified the `get_webhook_logs_queryset` to order logs by creation date and adjusted the chunk size for iteration.
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughAdds Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant WS as webhook_send_task
participant SL as save_webhook_log
participant MG as MongoConnection.collection
participant DB as WebhookLog (SQL DB)
WS->>SL: call save_webhook_log(webhook, req/resp, retry_count, event_type)
Note over SL: assemble log payload (webhook, request, response, retry, event)
alt Mongo connection & collection present
SL->>MG: insert_one(payload)
alt insert succeeds
MG-->>SL: success
SL-->>WS: return (logged)
else insert fails
MG--x SL: error
SL->>DB: create(payload)
DB-->>SL: ack/error
SL-->>WS: return (logged or failed)
end
else Mongo not available
SL->>DB: create(payload)
DB-->>SL: ack/error
SL-->>WS: return (logged or failed)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Linked to Plane Work Item(s) This comment was auto-generated by Plane |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements webhook logging to MongoDB with database fallback functionality. The changes introduce a new save_webhook_log function that attempts to save webhook logs to MongoDB first, and falls back to the existing database if MongoDB operations fail.
- Extracted webhook logging logic into a reusable
save_webhook_logfunction with MongoDB primary storage and database fallback - Updated webhook task to use the new logging function instead of direct database operations
- Modified webhook logs queryset to include ordering and adjusted chunk size
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| apps/api/plane/bgtasks/webhook_task.py | Added save_webhook_log function with MongoDB/database fallback and updated webhook task to use new logging |
| apps/api/plane/bgtasks/cleanup_task.py | Updated webhook logs queryset with ordering and modified chunk size |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (1)
apps/api/plane/bgtasks/cleanup_task.py (1)
413-414: Consider using a constant for the chunk size.The explicit ordering by
created_atis beneficial for deterministic processing and aligns well with the new centralized logging approach.However, the hardcoded chunk size of
100deviates from the pattern used in other queryset functions (which useBATCH_SIZE). If this smaller chunk size is intentional for webhook logs (e.g., due to larger payloads), consider introducing a dedicated constant likeWEBHOOK_BATCH_SIZEfor maintainability.Apply this diff if you'd like to introduce a dedicated constant:
+WEBHOOK_BATCH_SIZE = 100 + def get_webhook_logs_queryset(): """Get email logs older than cutoff days.""" cutoff_days = int(os.environ.get("HARD_DELETE_AFTER_DAYS", 30)) cutoff_time = timezone.now() - timedelta(days=cutoff_days) logger.info(f"Webhook logs cutoff time: {cutoff_time}") return ( WebhookLog.all_objects.filter(created_at__lte=cutoff_time) .values( "id", "created_at", "workspace_id", "webhook", "event_type", # Request "request_method", "request_headers", "request_body", # Response "response_status", "response_body", "response_headers", "retry_count", ) .order_by("created_at") - .iterator(chunk_size=100) + .iterator(chunk_size=WEBHOOK_BATCH_SIZE) )
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
apps/api/plane/bgtasks/cleanup_task.py(1 hunks)apps/api/plane/bgtasks/webhook_task.py(3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/api/plane/bgtasks/webhook_task.py (2)
apps/api/plane/settings/mongo.py (2)
MongoConnection(18-122)get_collection(91-109)apps/api/plane/db/models/webhook.py (2)
Webhook(30-57)WebhookLog(60-86)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Lint API
- GitHub Check: Cursor Bugbot
- GitHub Check: Analyze (javascript)
🔇 Additional comments (1)
apps/api/plane/bgtasks/webhook_task.py (1)
51-51: LGTM!The import is necessary for MongoDB integration in the new logging function.
|
You have run out of free Bugbot PR reviews for this billing cycle. This will reset on October 20. To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Description
save_webhook_logto log webhook requests and responses to MongoDB, with a fallback to the database if the MongoDB save fails.webhook_send_taskto utilize the new logging function.get_webhook_logs_querysetto order logs by creation date and adjusted the chunk size for iteration.Type of Change
Test Scenarios
References
WEB-5071
Summary by CodeRabbit