Skip to content

Querier: don't compress query API error responses - #7979

Open
blaketsk wants to merge 2 commits into
cortexproject:masterfrom
blaketsk:queryapi-uncompressed-errors
Open

blaketsk wants to merge 2 commits into
cortexproject:masterfrom
blaketsk:queryapi-uncompressed-errors

Conversation

@blaketsk

@blaketsk blaketsk commented Dec 1, 2026

Copy link
Copy Markdown

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.Wrap wraps every handler in CompressionHandler, which compressed every response according to the client's Accept-Encoding, errors included. The HTTP logging middleware logs the body written for 5xx responses with %q, so any client sending Accept-Encoding: gzip, which Go's HTTP client does by default, produced log lines like the one in the issue.

compressedResponseWriter now picks the encoding when it is created, but only starts compressing, and only sets Content-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 calls Write without WriteHeader.

TestCompressionHandler_ShouldNotCompressErrorResponses and Test_ErrorResponseIsNotCompressed fail without the change.

Two things I noticed while testing, which I left out of this PR:

  • An invalid time parameter returns 500 server_error instead of 400 bad_data, because DecorateWithParamName doesn't keep the 400 status of the wrapped httpgrpc error. 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

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]
  • docs/configuration/v1-guarantees.md updated if this PR introduces experimental flags

AI 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

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]>
@blaketsk
blaketsk requested a review from a team as a code owner December 1, 2026 16:10
@blaketsk
blaketsk requested a review from yeya24 December 1, 2026 16:10

This branch has not been deployed

No deployments
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.

Cryptic error message from querier

1 participant