Skip to content

FEAT: Resource Utilization Checks before ingestion. #1351

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

vkhinvasara
Copy link
Contributor

@vkhinvasara vkhinvasara commented Jun 17, 2025

Resource Utilization Thresholds: Sending 503 response if CPU/Memory thresholds exceed.

Description

This PR enhances our ingestion pipeline by implementing an overload protection mechanism during peak usage. Specifically, when CPU or memory utilization crosses predefined thresholds, the system will proactively reject further ingestion requests with an HTTP 503 (Service Unavailable) status. This prevents uncontrolled resource consumption and cascading failures.


File Changes

  • resource_check.rs: This is a middleware which checks resource utilization before every ingestion request.
  • modal/mod.rs : To wrap the above middleware.
  • http/mod.rs: To expose said middleware.

Summary by CodeRabbit

  • New Features
    • Introduced resource utilization checks for incoming HTTP requests. Requests are now automatically rejected with a 503 error if system CPU or memory usage exceeds safe thresholds, helping to maintain server stability under high load.

Copy link
Contributor

coderabbitai bot commented Jun 17, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

A new middleware for monitoring system resource utilization has been introduced and integrated into the HTTP server's middleware stack. This middleware checks CPU and memory usage on each request, rejecting requests with a 503 error if usage exceeds set thresholds. Module declarations were updated to include the new functionality.

Changes

File(s) Change Summary
src/handlers/http/mod.rs Added public submodule declaration for resource_check.
src/handlers/http/modal/mod.rs Imported and inserted resource_check middleware into the Actix middleware stack.
src/handlers/http/resource_check.rs Introduced middleware function to monitor and enforce CPU/memory usage limits per HTTP request.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ActixServer
    participant ResourceCheckMiddleware
    participant NextHandler

    Client->>ActixServer: HTTP Request
    ActixServer->>ResourceCheckMiddleware: Pass request
    ResourceCheckMiddleware->>ResourceCheckMiddleware: Check CPU & Memory usage
    alt Usage exceeds threshold
        ResourceCheckMiddleware-->>Client: 503 Service Unavailable
    else Usage within limits
        ResourceCheckMiddleware->>NextHandler: Forward request
        NextHandler-->>Client: Response
    end
Loading

Poem

A rabbit hops through server land,
Checks the CPU, memory at hand.
If things get hot, requests denied—
With 503, the truth supplied.
But when the coast is clear and bright,
The server runs both fast and light!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 97e5d42 and f623cc8.

📒 Files selected for processing (3)
  • src/handlers/http/mod.rs (1 hunks)
  • src/handlers/http/modal/mod.rs (2 hunks)
  • src/handlers/http/resource_check.rs (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in 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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file 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.

Copy link
Contributor

CLA Assistant Lite bot:
Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request

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.

2 participants