cosmo icon indicating copy to clipboard operation
cosmo copied to clipboard

Add support for response compression

Open StarpTech opened this issue 1 year ago • 18 comments

Component(s)

router

Is your feature request related to a problem? Please describe.

As a user, I'd like to be able to compress data between the client <-> router and router <-> subgraphs to save bandwidth and improve performance.

Describe the solution you'd like

Request compression is done transparently. The user of the router doesn't need to configure anything. The exchange is done through HTTP headers Accept-Encoding and Content-Encoding. The implementation should support Gzip, Deflate and Brotli as compression methods.

We need to extend the router to decompress client requests and extend the engine transport to compress outgoing requests to subgraphs. A very reasonable choice for gzip could be https://github.com/klauspost/compress/tree/master/gzhttp which also serve as good inspiration for the other methods.

Requirements:

  • No CGO.
  • Functionality must be provided in separate Go modules with unit tests and integration test. See test suite.
  • Use compression defaults that favor a good mix between compute time and space savings.

Describe alternatives you've considered

No response

Additional context

We use gin as http framework. The router engine transport can be found here https://github.com/wundergraph/cosmo/blob/main/router/core/transport.go

Previous issue #153

StarpTech avatar Mar 05 '24 18:03 StarpTech

WunderGraph commits fully to Open Source and we want to make sure that we can help you as fast as possible. The roadmap is driven by our customers and we have to prioritize issues that are important to them. You can influence the priority by becoming a customer. Please contact us here.

github-actions[bot] avatar Mar 05 '24 18:03 github-actions[bot]

/bounty $200

StarpTech avatar Mar 05 '24 21:03 StarpTech

~~## 💎 $100 bounty • WunderGraph Cosmo~~

~~### Steps to solve:~~ ~~1. Start working: Comment /attempt #602 with your implementation plan~~ ~~2. Submit work: Create a pull request including /claim #602 in the PR body to claim the bounty~~ ~~3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts~~

~~Important~~ ~~Bounty is up for challenger for those who can independently solve the task. We're here to support you with a final review and architectural assistance, but it's designed to be a solo challenge. Certain tasks require a deep understanding of the technology and ecosystem. Please consider this before diving in and spending your time on it. You are subject to a maximum attempt of 3 and you have 3 weeks after first attempt to complete the challenge. After that, you can no longer participate in the selected bounty.~~

~~Thank you for contributing to wundergraph/cosmo!~~

~~Add a bountyShare on socials~~

Attempt Started (GMT+0) Solution
🔴 @ibishal Mar 5, 2024, 9:56:36 PM WIP
🟢 @pi600 Mar 5, 2024, 9:57:23 PM WIP
🟢 @Rutik7066 Apr 11, 2024, 4:16:20 AM #723

algora-pbc[bot] avatar Mar 05 '24 21:03 algora-pbc[bot]

/attempt #602 can i get assigned

Options

pi600 avatar Mar 05 '24 21:03 pi600

@StarpTech do we need prehandler and posthandler to decode and encode the request body?

rutikthakre avatar Mar 31 '24 17:03 rutikthakre

/attempt #602

Algora profile Completed bounties Tech Active attempts Options
@Rutik7066 5 bounties from 4 projects
Go, Rust,
TypeScript & more
Cancel attempt

rutikthakre avatar Apr 11 '24 04:04 rutikthakre

[!NOTE] The user @pi600 is already attempting to complete issue #602 and claim the bounty. We recommend checking in on @pi600's progress, and potentially collaborating, before starting a new solution.

algora-pbc[bot] avatar Apr 11 '24 04:04 algora-pbc[bot]

💡 @Rutik7066 submitted a pull request that claims the bounty. You can visit your bounty board to reward.

algora-pbc[bot] avatar Apr 11 '24 12:04 algora-pbc[bot]

Hi @StarpTech I have raised the draft PR. I would appreciate your help with further development. I need to know where I should use compression and decompression functions to achieve the desired results.

rutikthakre avatar Apr 11 '24 12:04 rutikthakre

Hi @Rutik7066, I really like your ambitions but please respect the bounty requirements. We picked small tasks which should be solved alone. If you believe this task is too complicated, please move on with another one.

We're here to support you with a final review and architectural assistance, but it's designed to be a solo challenge.

StarpTech avatar Apr 11 '24 13:04 StarpTech

Hi @StarpTech I need you help in architectural understanding in know in I have to add it as prehandler and posthandler. But I am unable to understand where other prehandler and posthandler is added.

rutikthakre avatar Apr 11 '24 13:04 rutikthakre

@Rutik7066 take a look at the referenced issue https://github.com/wundergraph/cosmo/issues/153 We want to support client response compression. This means, a middleware needs to be implemented that overwrites responseWriter to support the compression algorithm. You can use https://github.com/go-chi/chi/blob/master/middleware/compress.go This is already almost the full story. If I assistant you more, I could the address the bounty myself 😄

StarpTech avatar Apr 11 '24 15:04 StarpTech

@Rutik7066 take a look at the referenced issue https://github.com/wundergraph/cosmo/issues/153 We want to support client response compression. This means, a middleware needs to be implemented that overwrites responseWriter to support the compression algorithm. You can use https://github.com/go-chi/chi/blob/master/middleware/compress.go This is already almost the full story. If I assistant you more, I could the address the bounty myself 😄

Got it 🫡

rutikthakre avatar Apr 11 '24 15:04 rutikthakre

Hi @StarpTech work is completed. Could you please review PR

rutikthakre avatar May 02 '24 03:05 rutikthakre

I'm interested in taking a shot at this, adding my name to the queue!

leonhfr avatar May 06 '24 07:05 leonhfr

I'm interested in taking a shot at this, adding my name to the queue!

PR submitted already everything is done. I am waiting for @StarpTech to review the PR

rutikthakre avatar May 06 '24 09:05 rutikthakre

Hi @StarpTech could you please review the PR

rutikthakre avatar May 11 '24 21:05 rutikthakre

Hi @Rutik7066 , there is a lot going on right now. I promise to review it at the beginning of next week. Thank you for your patience.

StarpTech avatar May 11 '24 21:05 StarpTech

🎉🎈 @Rutik7066 has been awarded $100! 🎈🎊

algora-pbc[bot] avatar May 26 '24 15:05 algora-pbc[bot]

I have decreased the scope of the ticket and therefore also the reward. Thanks for the contribution @Rutik7066

StarpTech avatar May 26 '24 15:05 StarpTech

@StarpTech what?

rutikthakre avatar May 26 '24 15:05 rutikthakre

@StarpTech I think you know I worked because of 200$ bounty price right. If anything from my side needs to be corrected or completed then you should tell me instead of this thing.

rutikthakre avatar May 26 '24 15:05 rutikthakre

Hi @Rutik7066,

I appreciate the effort you put into the project. However, it's important to note that the requirements were clearly outlined from the start. We've provided significant guidance throughout this process, which wasn't the intent of the bounty. You have completed response compression, which is only half of the requirement, and therefore received $100 as a reward.

The issue is closed.

Thank you for your understanding and contribution.

StarpTech avatar May 26 '24 16:05 StarpTech