Skip to content

Conversation

patsevanton
Copy link
Contributor

This PR introduces a new configuration parameter cpu_limit_multiplier to the SimpleLimitStrategy, providing more flexible control over CPU limit recommendations.

Changes:

  • Added cpu_limit_multiplier field to SimpleLimitStrategySettings with default value of 1.0
  • Updated CPU limit calculation to multiply the percentile-based value by the multiplier
  • Modified strategy description to reflect the new multiplier in the output format
  • Updated example command in description to include the new parameter

Benefits:

  • Allows users to set CPU limits as a percentage of the calculated percentile (e.g., 200% of 96th percentile)
  • Provides more granular control over resource allocation strategies
  • Maintains backward compatibility with default multiplier of 1.0
  • Useful for workloads that need headroom above statistical percentiles

Example Usage:

krr simple_limit --cpu_limit_multiplier=2.0  # Sets limit to 200% of percentile
krr simple_limit --cpu_limit_multiplier=1.5  # Sets limit to 150% of percentile

Copy link

coderabbitai bot commented Jul 12, 2025

Walkthrough

A new cpu_limit_multiplier setting was introduced to the SimpleLimitStrategySettings class, enabling the CPU limit percentile to be scaled by a configurable multiplier. The strategy's description and CPU proposal calculation logic were updated to incorporate this multiplier in both the explanation and the computation.

Changes

File(s) Change Summary
robusta_krr/strategies/simple_limit.py Added cpu_limit_multiplier to settings; updated description property and CPU proposal calculation to use the multiplier.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SimpleLimitStrategy
    participant MetricsPodData
    participant K8sObjectData

    User->>SimpleLimitStrategy: Configure with cpu_limit_multiplier
    SimpleLimitStrategy->>SimpleLimitStrategy: description (shows multiplier in text)
    User->>SimpleLimitStrategy: Request CPU proposal
    SimpleLimitStrategy->>MetricsPodData: Fetch CPU history data
    SimpleLimitStrategy->>K8sObjectData: Fetch object data
    SimpleLimitStrategy->>SimpleLimitStrategy: Calculate base percentile value
    SimpleLimitStrategy->>SimpleLimitStrategy: Multiply by cpu_limit_multiplier
    SimpleLimitStrategy-->>User: Return CPU limit recommendation
Loading
✨ 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

@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)
robusta_krr/strategies/simple_limit.py (1)

30-32: Consider adding an upper bound constraint for the multiplier.

While the gt=0 constraint prevents negative and zero values, there's no upper limit on the multiplier. Consider adding a reasonable upper bound to prevent unrealistic CPU limit recommendations.

For example, you could add an upper bound:

     cpu_limit_multiplier: float = pd.Field(
-        1.0, gt=0, description="Multiplier for CPU limit based on percentile. For example, 2.0 means 200% of percentile, 1.5 means 150%."
+        1.0, gt=0, le=10.0, description="Multiplier for CPU limit based on percentile. For example, 2.0 means 200% of percentile, 1.5 means 150%. Maximum value is 10.0."
     )
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 79680ee and 0d3a52c.

📒 Files selected for processing (1)
  • robusta_krr/strategies/simple_limit.py (3 hunks)
🔇 Additional comments (2)
robusta_krr/strategies/simple_limit.py (2)

30-32: LGTM! Well-designed field with proper validation.

The new cpu_limit_multiplier field is well-implemented with appropriate type annotation, sensible default value (1.0 for backward compatibility), proper validation constraint (gt=0), and clear description with examples.


143-145: LGTM! Correct implementation of the multiplier logic.

The CPU limit calculation correctly applies the multiplier to the base percentile value. The two-step approach (calculate base, then multiply) is clear and maintainable.

Comment on lines +98 to 106
cpu_limit_percentage = int(self.settings.cpu_limit_multiplier * 100)
s = textwrap.dedent(f"""\
CPU request: {self.settings.cpu_request}% percentile, limit: {self.settings.cpu_limit}% percentile
CPU request: {self.settings.cpu_request}% percentile, limit: {cpu_limit_percentage}% of {self.settings.cpu_limit}% percentile
Memory request: max + {self.settings.memory_buffer_percentage}%, limit: max + {self.settings.memory_buffer_percentage}%
History: {self.settings.history_duration} hours
Step: {self.settings.timeframe_duration} minutes
All parameters can be customized. For example: `krr simple_limit --cpu_request=66 --cpu_limit=96 --memory_buffer_percentage=15 --history_duration=24 --timeframe_duration=0.5`
All parameters can be customized. For example: `krr simple_limit --cpu_request=66 --cpu_limit=96 --cpu_limit_multiplier=2.0 --memory_buffer_percentage=15 --history_duration=24 --timeframe_duration=0.5`
""")
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve description clarity and handle decimal multipliers properly.

The description formatting has some clarity issues:

  1. Converting the multiplier to an integer percentage (int(self.settings.cpu_limit_multiplier * 100)) truncates decimal values, which could be misleading for multipliers like 1.5.
  2. The description format "200% of 96% percentile" might be confusing - consider a clearer format.

Apply this diff to improve clarity:

-        cpu_limit_percentage = int(self.settings.cpu_limit_multiplier * 100)
+        cpu_limit_multiplier = self.settings.cpu_limit_multiplier
         s = textwrap.dedent(f"""\
-            CPU request: {self.settings.cpu_request}% percentile, limit: {cpu_limit_percentage}% of {self.settings.cpu_limit}% percentile
+            CPU request: {self.settings.cpu_request}% percentile, limit: {self.settings.cpu_limit}% percentile × {cpu_limit_multiplier}
             Memory request: max + {self.settings.memory_buffer_percentage}%, limit: max + {self.settings.memory_buffer_percentage}%
             History: {self.settings.history_duration} hours
             Step: {self.settings.timeframe_duration} minutes
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
cpu_limit_percentage = int(self.settings.cpu_limit_multiplier * 100)
s = textwrap.dedent(f"""\
CPU request: {self.settings.cpu_request}% percentile, limit: {self.settings.cpu_limit}% percentile
CPU request: {self.settings.cpu_request}% percentile, limit: {cpu_limit_percentage}% of {self.settings.cpu_limit}% percentile
Memory request: max + {self.settings.memory_buffer_percentage}%, limit: max + {self.settings.memory_buffer_percentage}%
History: {self.settings.history_duration} hours
Step: {self.settings.timeframe_duration} minutes
All parameters can be customized. For example: `krr simple_limit --cpu_request=66 --cpu_limit=96 --memory_buffer_percentage=15 --history_duration=24 --timeframe_duration=0.5`
All parameters can be customized. For example: `krr simple_limit --cpu_request=66 --cpu_limit=96 --cpu_limit_multiplier=2.0 --memory_buffer_percentage=15 --history_duration=24 --timeframe_duration=0.5`
""")
cpu_limit_multiplier = self.settings.cpu_limit_multiplier
s = textwrap.dedent(f"""\
CPU request: {self.settings.cpu_request}% percentile, limit: {self.settings.cpu_limit}% percentile × {cpu_limit_multiplier}
Memory request: max + {self.settings.memory_buffer_percentage}%, limit: max + {self.settings.memory_buffer_percentage}%
History: {self.settings.history_duration} hours
Step: {self.settings.timeframe_duration} minutes
All parameters can be customized. For example: `krr simple_limit --cpu_request=66 --cpu_limit=96 --cpu_limit_multiplier=2.0 --memory_buffer_percentage=15 --history_duration=24 --timeframe_duration=0.5`
""")
🤖 Prompt for AI Agents
In robusta_krr/strategies/simple_limit.py around lines 98 to 106, the current
code converts cpu_limit_multiplier to an integer percentage, truncating decimals
and causing potential confusion in the description format. To fix this, keep the
multiplier as a float and format it with one or two decimal places to preserve
precision. Also, rephrase the description to clearly explain the relationship,
for example by stating "CPU limit: cpu_limit_multiplier times the cpu_limit
percentile" instead of using percentage multiplication wording.

@aantn
Copy link
Contributor

aantn commented Jul 20, 2025

@patsevanton could you achieve something similar by modifying the existing limit field so it can take values above 100%? (e.g. 120%)

    cpu_limit: float = pd.Field(96, gt=0, description="The percentile to use for the CPU limit.")

@patsevanton
Copy link
Contributor Author

@aantn using percentages greater than 100 may not make practical sense in the context of statistics, since a percentage of 100% already represents the maximum value in the dataset.

@aantn
Copy link
Contributor

aantn commented Jul 22, 2025 via email

@patsevanton
Copy link
Contributor Author

I will try build and run. later

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