Skip to content
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

Fix request.body rego builtin sporadic unexpected EOF #31

Merged
merged 1 commit into from
Jan 15, 2024

Conversation

cclerget
Copy link
Contributor

@cclerget cclerget commented Jan 15, 2024

Summary by CodeRabbit

  • Refactor
    • Improved request body processing for enhanced performance and reliability.
    • Extended BeskarConfig struct to include a new Router field, offering additional configuration options.
    • Modified RegoRouter struct to include a new bodyLimit field, enhancing router settings.
    • Removed unnecessary package import, type, and variable in the builtin router.
    • Modified register and initRouter functions to handle additional parameters for improved plugin and router configuration.
    • Updated startGossipWatcher method to accommodate an additional parameter, impacting plugin registration logic.

Copy link
Contributor

coderabbitai bot commented Jan 15, 2024

Walkthrough

The recent modifications aim to enhance the flexibility and configurability of the Beskar plugin system and streamline the request handling in the routing package. These changes involve adding new configuration options, modifying method signatures to accommodate additional parameters, and refining the request body processing mechanism for improved efficiency.

Changes

File Path Change Summary
internal/pkg/beskar/plugin.go, internal/pkg/beskar/registry.go Modified functions to take additional configuration parameters, affecting plugin and router initialization logic.
internal/pkg/config/beskar.go Extended BeskarConfig struct to include a new Router field for router settings configuration.
internal/pkg/router/builtin.go Removed sync import, bodyCloser type, and bufferPool variable, refactored requestBodyBuiltin for improved request body processing.
internal/pkg/router/router.go Modified RegoRouter struct to include a new bodyLimit field, added WithBodyLimit function, and updated New function and Decision method to utilize bodyLimit.

Poem

🐇 A code dance, a tune so sweet,
🌟 Changes woven, a refactor feat.
🚫 Out with the old, in with the sleek,
🎉 CodeRabbit hops, improvements to seek!

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?

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>.
    • Generate unit-tests for this file.
  • 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 generate unit tests for this file.
    • @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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6aec20b and cea17b6.
Files selected for processing (1)
  • internal/pkg/router/builtin.go (3 hunks)
Additional comments: 5
internal/pkg/router/builtin.go (5)
  • 151-154: The check for nil or http.NoBody on the request body is a good practice to avoid unnecessary processing or potential nil dereferences.
  • 156-156: Initializing a new buffer to read the request body is a standard approach and is correctly implemented.
  • 165-171: Reading the buffered data into a bytes.Reader and then converting it to an AST value is done correctly.
  • 174-174: Resetting the request body with io.NopCloser wrapped around the bytes.Reader is a clean way to allow for potential re-reads without the risk of an EOF error from a closed body.
  • 176-176: Returning the new AST term created from the request body is the expected outcome of this function.

internal/pkg/router/builtin.go Outdated Show resolved Hide resolved
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6aec20b and 3c0282d.
Files ignored due to path filters (1)
  • internal/pkg/config/default/beskar.yaml is excluded by: !**/*.yaml
Files selected for processing (5)
  • internal/pkg/beskar/plugin.go (6 hunks)
  • internal/pkg/beskar/registry.go (2 hunks)
  • internal/pkg/config/beskar.go (1 hunks)
  • internal/pkg/router/builtin.go (4 hunks)
  • internal/pkg/router/router.go (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • internal/pkg/router/builtin.go
Additional comments: 13
internal/pkg/router/router.go (4)
  • 34-34: The addition of the bodyLimit field to the RegoRouter struct is consistent with the PR's objective to manage the request body size.
  • 63-68: The WithBodyLimit function is correctly implemented to set the bodyLimit field in the RegoRouter struct.
  • 79-79: Initializing the bodyLimit field to 8192 in the New function is a sensible default, aligning with the PR's intent to manage request body sizes.
  • 98-100: The Decision method now correctly uses the bodyLimit field from the RegoRouter instance, which should help in handling the request body size as intended.
internal/pkg/config/beskar.go (2)
  • 34-36: The Router struct with the BodyLimit attribute has been correctly added to the BeskarConfig struct, allowing configuration of the request body limit.
  • 45-45: The new Router field in the BeskarConfig struct is properly defined and follows the expected structure for configuration files.
internal/pkg/beskar/plugin.go (5)
  • 31-31: The import statement for the config package is correctly added to use the new configuration options in the plugin logic.
  • 122-122: The register function now correctly takes an additional beskarConfig *config.BeskarConfig parameter, which is necessary for passing the new configuration options.
  • 150-150: The initRouter function within the plugin struct is correctly modified to take an additional bodyLimit int64 parameter, aligning with the PR's objectives.
  • 164-164: The initRouter function is correctly updated to handle the new bodyLimit parameter during plugin updates.
  • 353-361: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [347-358]

The initRouter function is correctly updated to include the bodyLimit parameter when initializing the router with the new configuration options.

internal/pkg/beskar/registry.go (2)
  • 161-161: The additional parameter br.beskarConfig is correctly passed to the register method call within the gossip.PluginInstance case block, ensuring the new configuration is used when registering plugins.
  • 185-185: The register method is consistently called with the new br.beskarConfig parameter in another instance within the gossip.PluginInstance case block.

@ikaneshiro ikaneshiro merged commit 445099c into main Jan 15, 2024
3 checks passed
@cclerget cclerget deleted the plugin-api-eof-fix branch January 16, 2024 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants