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

feat: add compression handler to server handler #5433

Closed

Conversation

burnerlee
Copy link
Contributor

@burnerlee burnerlee commented Dec 2, 2022

Signed-off-by: burnerlee avi.aviral140@gmail.com
resolves #5310

Feature addition

This PR adds CompressionHandler to the server initialised in server.go file.
Also, it updates the test - TestRequestLogging to enable checking for gzip compression. If gzip is specified as Accept-Encoding header value, then a gzip compressed payload is returned and the response has Content-Encoding header set to gzip. We verify this, and verify the compressed payload by decompressing it manually and matching it to the original string.

@burnerlee burnerlee changed the title [WIP] feat: add compression handler to server handler feat: add compression handler to server handler Dec 7, 2022
@burnerlee burnerlee marked this pull request as ready for review December 7, 2022 03:44
@netlify
Copy link

netlify bot commented Dec 7, 2022

Deploy Preview for openpolicyagent ready!

Name Link
🔨 Latest commit 50cb4f1e72d91c3992f7c06d68b4ecff87074398
🔍 Latest deploy log https://app.netlify.com/sites/openpolicyagent/deploys/63900c1322bd9a0009b696ba
😎 Deploy Preview https://deploy-preview-5433--openpolicyagent.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Dec 7, 2022

Deploy Preview for openpolicyagent ready!

Name Link
🔨 Latest commit cd9f2f030a30085b0c88af6ae00d9c00d86c0663
🔍 Latest deploy log https://app.netlify.com/sites/openpolicyagent/deploys/63900c5fc361f60009b4cc2e
😎 Deploy Preview https://deploy-preview-5433--openpolicyagent.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Signed-off-by: burnerlee <avi.aviral140@gmail.com>
Signed-off-by: burnerlee <avi.aviral140@gmail.com>
reader := bytes.NewReader([]byte(act))
gzreader, _ := gzip.NewReader(reader)
output, _ := io.ReadAll(gzreader)
act = string(output)
Copy link
Contributor

Choose a reason for hiding this comment

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

This adjusts the test, but if you're running opa with

opa run --server --log-level debug

will it spill gzip binary data into your logs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes if the client sends the request with Accept-Encoding header set to gzip, then it would do so. But isn't it the intended behaviour?

Copy link
Contributor

Choose a reason for hiding this comment

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

😅 spewing binary data into the logs is not the intended behaviour. For the metrics endpoint, we'll log "binary payload" instead -- this is what the test was about. For the data endpoints, I think we should include the decompressed data in the debug logs.

Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose decompressing what we've previously compressed to log it is also kind of weird, and an indicator that logging should be wired differently. 🤔

@@ -71,6 +71,7 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/flatbuffers v1.12.1 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that these were recently archived, I'm wondering what other options would be.

Choose a reason for hiding this comment

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

how about just include the handlers internally I see the implementation of gorilla/handlers is not dependent on another gorilla package https://github.com/gorilla/handlers/blob/v1.5.1/compress.go#L63

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah that's a possibility. Sorry there are so many things in flight here right now, please note #5483.

@srenatus
Copy link
Contributor

srenatus commented Jan 5, 2023

🧹 cleaning out open PRs. Feel free to re-open if you happen to get back to this. 😃

@srenatus srenatus closed this Jan 5, 2023
@johanneslarsson
Copy link
Contributor

I think this should wait until gorilla/mux has been replaced, #5483

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.

server: compress large response payloads if client supports it
4 participants