Repository navigation
Answer a malformed Prometheus request body with a 4xx - #120938
nikitamikhaylov merged 3 commits into
Conversation
…as wrong A remote-write or remote-read body the server cannot decompress was answered with a 500, because SNAPPY_UNCOMPRESS_FAILED and ZSTD_DECODER_FAILED are not on the 4xx list. A sender treats a 5xx as retryable, so Prometheus resent a body it had encoded wrongly and could never fix, for as long as it kept it. The codes themselves stay where they are: the same snappy code is raised for reading a stored file, where a server-side failure is exactly what a 500 means. Only the two handlers that decode a request body retag their own failure as BAD_ARGUMENTS, which is already what the protobuf parse of that same body raises one line further down. The message it carries said "snappy uncompress failed: " and stopped, with a colon before a reason the library never supplies: snappy::Uncompress answers with a bool and nothing else. It now names what was attempted instead, the size of the block and the uncompressed length the block's own header declares, which is the vocabulary the framed reader beside it already uses. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QtEKPyQDMCBZfJkiJcs789
|
Workflow [PR], commit [2c9a9c3] Summary: ✅
AI ReviewSummaryThis PR changes Prometheus remote-read / remote-write body-decode failures from PR Metadata
Tests
Final Verdict
LLVM Coverage ReportMeasured on commit 2c9a9c3.
Changed lines: Changed C/C++ lines covered: 23/29 (79.31%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units8 translation units recompiled, 12 s compile time in total, 8 of them have a recent master baseline. |
The status of an undecodable request body is a user-visible contract and had no test: the suite covered the happy paths and the header refusals only, so the `500` this commit's parent replaced could come back the next time the handler or the HTTP exception mapping moved. One test per affected path, each sending a body that is not what its `Content-Encoding` claims: remote write under `snappy` and under `zstd`, and remote read under `snappy`. Each asserts the `400` and the part of the message that says the body could not be decoded. The body is posted verbatim rather than through the helpers, which would compress it on the way out. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QtEKPyQDMCBZfJkiJcs789
|
Should be ready for review. |
| with a 5xx, which Prometheus retries for as long as it keeps the batch.""" | ||
| response = post_undecodable_body("/write", content_encoding) | ||
| assert response.status_code == requests.codes.bad_request, response.text | ||
| assert "Cannot decode the request body" in response.text |
There was a problem hiding this comment.
This locks in the 400, but not the new snappy diagnostic the PR is also introducing. Both snappy paths would still stay green if SnappyBasicReadBuffer regressed back to a generic decompression message, because the assertion only checks the outer Cannot decode the request body wrapper. Please add one snappy-specific fragment here and in test_remote_read_undecodable_body (for example declares / uncompressed bytes) so the user-visible message this change advertises is actually covered.
PromQL Compliance ReportBaseline: S3 master
Note: score is unchanged vs baseline. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
A Prometheus remote-write or remote-read request whose body cannot be decompressed is now answered with
400instead of500, and the error names the size of the block and the uncompressed length it declares.Documentation entry for user-facing changes
No documentation change: the status of a malformed request is not described in the Prometheus protocol docs.
A body the client encoded wrongly is the client's permanent fault, but the two decoder error codes are not on the 4xx list, so the server answered
500. Prometheus treats5xxas retryable, so a sender resent a body it could never fix, for as long as it kept it.Measured before, against a remote-write body whose snappy frame declares 70000 uncompressed bytes over a 65536-byte literal:
and after:
The error codes themselves are deliberately left where they are.
SNAPPY_UNCOMPRESS_FAILEDis also raised bySnappyFramedReadBufferandHadoopSnappyReadBuffer, which read stored files — there a500is exactly right, because the failure is the server's. So only the two handlers that decode a request body retag their own failure asBAD_ARGUMENTS, which is already what the protobuf parse of that same body raises one line further down.The message ended in a colon before a reason that never came:
snappy::Uncompressreturns a barebooland offers no error string, so there was nothing to put after it. It now names what was attempted instead — the size of the block, and the uncompressed length the block's own header declares viasnappy::GetUncompressedLength, which is the vocabularySnappyFramedReadBufferbeside it already uses. On a body that is not snappy at all the numbers say so at a glance:a 63 byte block declares 10 uncompressed bytes.Found while testing #117170 against real scraped Prometheus data; it reproduces identically on a plain
TimeSeriestable, so it is not that PR's.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/120938]
Version info
26.10.1.466-master(included in26.10and later)