Skip to content

Conversation

@tchoumi313
Copy link
Contributor

@tchoumi313 tchoumi313 commented Dec 9, 2025

Added config to silence the django-structlog’s middleware request

Summary by CodeRabbit

  • Chores
    • Added a logging filter to ignore specific 404 request entries related to the /api/build endpoint.
    • Registered and applied the filter to console logging and to file-based logging when enabled.
    • Improves log clarity by reducing irrelevant 404 entries and making operational logs easier to scan.

✏️ Tip: You can customize this high-level summary in your review settings.

@tchoumi313 tchoumi313 self-assigned this Dec 9, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 9, 2025

📝 Walkthrough

Walkthrough

Added an IgnoreApiBuildFilter logging.Filter in two Django settings modules, registered it in each LOGGING["filters"], and applied it to the console handler and to the file handler (when enabled) to suppress 404 request_finished logs for the /api/build endpoint.

Changes

Cohort / File(s) Summary
Add logging filter & apply to handlers
backend/ciso_assistant/settings.py, enterprise/backend/enterprise_core/settings.py
Added IgnoreApiBuildFilter(logging.Filter) with filter(self, record) that returns False for 404 request_finished records targeting /api/build (with or without trailing slash); registered as ignore_api_build in LOGGING["filters"]; added "filters": ["ignore_api_build"] to the console handler and to the file handler when LOG_OUTFILE is enabled.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I hop through logs at eventide,
Quieting 404s the build can't hide.
A nibble here, a soft goodnight,
Console calm beneath moonlight. 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: remove useless log' accurately describes the main objective of the PR—adding configuration to suppress 404 logs for /api/build endpoints that are considered useless.
✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 729f34e and 59f98f4.

📒 Files selected for processing (2)
  • backend/ciso_assistant/settings.py
  • enterprise/backend/enterprise_core/settings.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • backend/ciso_assistant/settings.py
  • enterprise/backend/enterprise_core/settings.py
⏰ 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). (9)
  • GitHub Check: build_community_frontend
  • GitHub Check: build_enterprise_frontend
  • GitHub Check: startup-functional-test (3.12)
  • GitHub Check: startup-docker-compose-test
  • GitHub Check: enterprise-startup-docker-compose-test
  • GitHub Check: enterprise-startup-functional-test (3.12)
  • GitHub Check: build (3.12)
  • GitHub Check: test (3.12)
  • GitHub Check: Analyze (python)

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Collaborator

@eric-intuitem eric-intuitem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This removes all logs at info and warning level. What we want is to avoid 1 specific log.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
enterprise/backend/enterprise_core/settings.py (1)

41-50: Consider extracting filter to shared module to eliminate duplication.

The IgnoreApiBuildFilter class is duplicated between backend/ciso_assistant/settings.py and enterprise/backend/enterprise_core/settings.py. While settings files are often self-contained, extracting this filter to a shared logging utility module would improve maintainability.

The same concerns from the community edition apply here:

  • Verify that the request attribute contains a string path (not an HttpRequest object)
  • The substring match "/api/build" in request could match unintended paths

Example refactor:

Create backend/ciso_assistant/logging_utils.py:

import logging

class IgnoreApiBuildFilter(logging.Filter):
    """Filter out request_finished logs for /api/build endpoint with 404 status."""

    def filter(self, record):
        request = getattr(record, "request", None)
        code = getattr(record, "code", None)
        if code == 404 and request and request.endswith("/api/build"):
            return False
        return True

Then import in both settings files:

from ciso_assistant.logging_utils import IgnoreApiBuildFilter
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 24a0657 and 781619d.

📒 Files selected for processing (2)
  • backend/ciso_assistant/settings.py (2 hunks)
  • enterprise/backend/enterprise_core/settings.py (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
enterprise/backend/enterprise_core/settings.py (1)
backend/ciso_assistant/settings.py (2)
  • IgnoreApiBuildFilter (44-52)
  • filter (47-52)
backend/ciso_assistant/settings.py (1)
enterprise/backend/enterprise_core/settings.py (2)
  • IgnoreApiBuildFilter (41-49)
  • filter (44-49)
⏰ 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). (7)
  • GitHub Check: ruff-community (3.12)
  • GitHub Check: test (3.12)
  • GitHub Check: build (3.12)
  • GitHub Check: build_community_frontend
  • GitHub Check: build_enterprise_frontend
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (python)
🔇 Additional comments (4)
backend/ciso_assistant/settings.py (2)

68-77: LGTM - Filter registration and application is correct.

The filter is properly registered and applied to the console handler using Django's logging configuration format.


90-97: Verify if file handler should also filter /api/build logs.

The ignore_api_build filter is only applied to the console handler. When LOG_OUTFILE is set, the file handler will still log 404 responses for /api/build. Confirm whether this is intentional (keeping complete audit logs in files) or if the filter should also be applied to the file handler.

enterprise/backend/enterprise_core/settings.py (2)

65-74: LGTM - Filter configuration matches community edition.

The filter registration and application is correctly configured, consistent with the implementation in backend/ciso_assistant/settings.py.


82-89: Same file handler concern as community edition.

As with backend/ciso_assistant/settings.py, the file handler does not include the ignore_api_build filter. Verify that this behavior is consistent and intentional across both the community and enterprise editions.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
backend/ciso_assistant/settings.py (1)

44-56: Note: Inconsistency with enterprise version.

The enterprise version at enterprise/backend/enterprise_core/settings.py (lines 40-48) still uses the old substring matching approach ("/api/build" in request) that was fixed here. Consider applying the same endswith() fix to the enterprise version to avoid false positives.

Would you like me to open an issue to track updating the enterprise version with the same fix?

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 781619d and ab772ba.

📒 Files selected for processing (1)
  • backend/ciso_assistant/settings.py (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
backend/ciso_assistant/settings.py (1)
enterprise/backend/enterprise_core/settings.py (2)
  • IgnoreApiBuildFilter (41-49)
  • filter (44-49)
⏰ 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). (9)
  • GitHub Check: enterprise-startup-functional-test (3.12)
  • GitHub Check: enterprise-startup-docker-compose-test
  • GitHub Check: startup-functional-test (3.12)
  • GitHub Check: startup-docker-compose-test
  • GitHub Check: build_community_frontend
  • GitHub Check: build_enterprise_frontend
  • GitHub Check: build (3.12)
  • GitHub Check: test (3.12)
  • GitHub Check: Analyze (python)
🔇 Additional comments (2)
backend/ciso_assistant/settings.py (2)

72-76: LGTM!

The filter is correctly registered in the logging configuration.


44-56: The endswith() approach won't catch requests with query parameters, while the enterprise version's substring matching would.

The current filter matches /api/build and /api/build/ but will miss requests like /api/build?version=1. While this is unlikely in practice (since the endpoint doesn't exist), the enterprise version uses substring matching ("/api/build" in request), which handles this case. Consider whether to align with the enterprise approach or document why the narrower match is sufficient for the community version.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ab772ba and 729f34e.

📒 Files selected for processing (2)
  • backend/ciso_assistant/settings.py (3 hunks)
  • enterprise/backend/enterprise_core/settings.py (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
backend/ciso_assistant/settings.py (1)
enterprise/backend/enterprise_core/settings.py (2)
  • IgnoreApiBuildFilter (41-49)
  • filter (44-49)
enterprise/backend/enterprise_core/settings.py (1)
backend/ciso_assistant/settings.py (2)
  • IgnoreApiBuildFilter (44-56)
  • filter (47-56)
⏰ 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). (9)
  • GitHub Check: startup-docker-compose-test
  • GitHub Check: startup-functional-test (3.12)
  • GitHub Check: enterprise-startup-docker-compose-test
  • GitHub Check: enterprise-startup-functional-test (3.12)
  • GitHub Check: build (3.12)
  • GitHub Check: build_community_frontend
  • GitHub Check: build_enterprise_frontend
  • GitHub Check: test (3.12)
  • GitHub Check: Analyze (python)
🔇 Additional comments (1)
backend/ciso_assistant/settings.py (1)

44-56: LGTM! Filter implementation is correct.

The filter correctly uses endswith() checks to precisely match the /api/build endpoint, avoiding false positives with similar paths. The filter is properly registered and applied to both console and file handlers.

Copy link
Collaborator

@nas-tabchiche nas-tabchiche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. To merge once CI is green

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants