Skip to content

Conversation

@mrpahdan
Copy link
Contributor

@mrpahdan mrpahdan commented Jul 17, 2025

Add ability to configure the min size for response compression.

Checklist

  • I have discussed my proposed changes in an issue and have received approval to proceed.
  • I have followed the coding standards of the project.
  • Tests or benchmarks have been added or updated.
  • Documentation has been updated on https://github.com/wundergraph/cosmo-docs.
  • I have read the Contributors Guide.

Resolve issue: #2056

Documentation update: wundergraph/cosmo-docs#124

Summary by CodeRabbit

  • New Features
    • Added a configurable option to set the minimum response size required to enable HTTP response compression.
    • Updated configuration files and schema to support the new compression size setting, with a default value of 4KB.
  • Tests
    • Introduced tests to verify response compression behavior with custom minimum size settings.

@coderabbitai
Copy link

coderabbitai bot commented Jul 17, 2025

"""

Walkthrough

The changes introduce a configurable parameter for the minimum response size required to enable HTTP response compression in the router. This replaces the previously hardcoded 4KB threshold with a value that can be set in the router's configuration files and schema. A new test verifies compression behavior with different minimum size settings.

Changes

Files/Paths Change Summary
router/core/graph_server.go Uses configurable ResponseCompressionMinSize for gzip compression threshold instead of 4KB.
router/core/router.go Updates DefaultRouterTrafficConfig to set default ResponseCompressionMinSize to 4KiB.
router/pkg/config/config.go Adds ResponseCompressionMinSize field to RouterTrafficConfiguration struct.
router/pkg/config/config.schema.json Adds response_compression_min_size property to router traffic shaping schema.
router/pkg/config/fixtures/full.yaml Adds response_compression_min_size: 4KiB to example configuration under router section.
router/pkg/config/testdata/config_*.json Adds ResponseCompressionMinSize field with value 4096 to router traffic shaping config.
router-tests/response_compression_test.go Adds test TestResponseCompressionWithCustomMinSize to verify compression with custom thresholds.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 8785981 and aa3c1c6.

📒 Files selected for processing (1)
  • router/core/router.go (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • router/core/router.go
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 generate unit tests to generate unit tests for 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)
router/pkg/config/config.schema.json (1)

1472-1476: Consider adding bytes-string format & a sane minimum to tighten validation

The new response_compression_min_size field currently omits the custom bytes-string format and has an empty bytes object, meaning any string – including empty or invalid values like "foobar" or "0" – will pass schema validation.
Other byte-size properties in the schema (e.g. persisted_operations.cache.size) use the format and often specify a minimum threshold, which catches typos early and keeps UX consistent.

             "response_compression_min_size": {
               "type": "string",
+              "format": "bytes-string",
               "description": "The minimum size of the response body in bytes to enable response compression. The size is specified as a string with a number and a unit, e.g. 10KB, 1MB, 1GB. The supported units are 'KB', 'MB', 'GB'.",
               "default": "4KB",
-              "bytes": {}
+              "bytes": {
+                "minimum": "1B"
+              }
             }

Adding these two lines will align validation behaviour with neighbouring fields and prevent silent mis-configurations.
Please double-check that the Go struct tag in config.go still uses the same default after the change.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3f4dea6 and dd443fb.

📒 Files selected for processing (4)
  • router/core/graph_server.go (1 hunks)
  • router/pkg/config/config.go (1 hunks)
  • router/pkg/config/config.schema.json (1 hunks)
  • router/pkg/config/fixtures/full.yaml (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: SkArchon
PR: wundergraph/cosmo#1929
File: router/internal/circuit/manager.go:16-25
Timestamp: 2025-06-30T20:39:02.387Z
Learning: In the Cosmo router project, parameter validation for circuit breaker configuration is handled at the JSON schema level rather than through runtime validation methods on structs. The config.schema.json file contains comprehensive validation constraints for circuit breaker parameters.
router/pkg/config/config.go (1)
Learnt from: endigma
PR: wundergraph/cosmo#2009
File: router/pkg/config/config.go:0-0
Timestamp: 2025-07-03T10:33:25.778Z
Learning: The CardinalityLimit field in the Metrics struct (router/pkg/config/config.go) is validated at the JSON schema level in config.schema.json with a minimum value constraint of 1, preventing zero or negative values without requiring runtime validation.
router/pkg/config/config.schema.json (2)

undefined

<retrieved_learning>
Learnt from: endigma
PR: #2009
File: router/pkg/config/config.go:0-0
Timestamp: 2025-07-03T10:33:25.778Z
Learning: The CardinalityLimit field in the Metrics struct (router/pkg/config/config.go) is validated at the JSON schema level in config.schema.json with a minimum value constraint of 1, preventing zero or negative values without requiring runtime validation.
</retrieved_learning>

<retrieved_learning>
Learnt from: SkArchon
PR: #1929
File: router/internal/circuit/manager.go:16-25
Timestamp: 2025-06-30T20:39:02.387Z
Learning: In the Cosmo router project, parameter validation for circuit breaker configuration is handled at the JSON schema level rather than through runtime validation methods on structs. The config.schema.json file contains comprehensive validation constraints for circuit breaker parameters.
</retrieved_learning>

🧬 Code Graph Analysis (1)
router/pkg/config/config.go (1)
router/pkg/config/marshaler.go (1)
  • BytesString (54-54)
🔇 Additional comments (2)
router/pkg/config/fixtures/full.yaml (1)

197-202: Fixture looks good – confirms schema update

The sample now includes response_compression_min_size: 4KB, matching the new struct field and preserving the previous hard-coded default.
Nothing to change here.

router/core/graph_server.go (1)

286-286: LGTM! Clean implementation of configurable response compression minimum size.

The change successfully replaces the hardcoded 4KB threshold with a configurable value from the router traffic configuration. The type conversion to int is appropriate for the gzhttp.MinSize function parameter.

@SkArchon SkArchon mentioned this pull request Jul 22, 2025
5 tasks
Copy link
Contributor

@SkArchon SkArchon left a comment

Choose a reason for hiding this comment

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

Could you also add the original default value to this function

func DefaultRouterTrafficConfig() *config.RouterTrafficConfiguration {

@SkArchon SkArchon merged commit 455fb0d into wundergraph:main Jul 25, 2025
49 of 52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants