Repository navigation
Conversation
The query API compressed every response according to the client's Accept-Encoding header, errors included. The HTTP logging middleware logs the body written for 5xx responses, so for clients sending Accept-Encoding, like the Go HTTP client which sends gzip by default, the log showed a compressed blob instead of the error. Choose the encoding up front but only start compressing when the response header is written with a status code below 400. Fixes cortexproject#3912 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YDgKpXdZmLs9YSYU1ZSf8d Signed-off-by: Andrey Osipov <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YDgKpXdZmLs9YSYU1ZSf8d Signed-off-by: Andrey Osipov <[email protected]>
2 of 4 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does:
Stops compressing query API error responses, so a failed query is logged with a readable error instead of a compressed blob.
As @sandy2008 found in #3912,
QueryAPI.Wrapwraps every handler inCompressionHandler, which compressed every response according to the client'sAccept-Encoding, errors included. The HTTP logging middleware logs the body written for 5xx responses with%q, so any client sendingAccept-Encoding: gzip, which Go's HTTP client does by default, produced log lines like the one in the issue.compressedResponseWriternow picks the encoding when it is created, but only starts compressing, and only setsContent-Encoding, when the response header is written with a status code below 400. Error bodies are small, so leaving them uncompressed costs nothing. Successful responses are compressed as before, including when the handler callsWritewithoutWriteHeader.TestCompressionHandler_ShouldNotCompressErrorResponsesandTest_ErrorResponseIsNotCompressedfail without the change.Two things I noticed while testing, which I left out of this PR:
timeparameter returns500 server_errorinstead of400 bad_data, becauseDecorateWithParamNamedoesn't keep the 400 status of the wrappedhttpgrpcerror. Happy to open a separate issue or PR.-api.response-compression-enabled(gzhttp, disabled by default) can still compress error bodies above its 1400 bytes minimum size.Which issue(s) this PR fixes:
Fixes #3912
Checklist
CHANGELOG.mdupdated - the order of entries should be[CHANGE],[FEATURE],[ENHANCEMENT],[BUGFIX]docs/configuration/v1-guarantees.mdupdated if this PR introduces experimental flagsAI disclosure: per GENAI_POLICY.md, the fix and the tests were prepared with Claude Code. I reviewed and verified the changes.
🤖 Generated with Claude Code