refactor(api): replace response copy wrappers with Jetty content count - #6982
Open
halibobo1205 wants to merge 1 commit into
Open
halibobo1205 wants to merge 1 commit into
halibobo1205 wants to merge 1 commit into
Conversation
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 does this PR do?
Replaces response-body copying for HTTP traffic metrics with Jetty's native
Response.getContentCount(). RemovesCharResponseWrapper,ServletOutputStreamCopy, and the unused response wrapping inHttpApiAccessFilter.Why are these changes required?
The old wrappers retained response bodies in memory solely to measure their size. Full-node wallet requests could pass through two copies, and bulk writes fell back to a per-byte loop. Jetty already maintains a byte count, including content still in its output buffer, so these copies are unnecessary.
HttpApiAccessFilterbuilt a wrapper it never read, on four HTTP services — three of which register no interceptor at all.Using Jetty's native response writer also fixes incomplete responses caused by bytes remaining in the old wrapper's unflushed
OutputStreamWriterbuffer. Unflushedprint()calls could lose an entire small response or the trailing bytes of a larger response. This is latent rather than live: every servlet underservices/httpends withprintln, and the one non-printlnwriter call runs upstream of any wrapper.Before/after checks found matching response bodies and byte counts for the tested synchronous production write patterns, including
println, JSON-RPC output-stream writes, and UTF-8 responses.Metrics are still recorded after the filter chain returns. They measure response-body bytes written to Jetty, excluding HTTP headers and chunk framing; they do not guarantee delivery to the client. Existing exclusions for disabled-API and lite-node responses remain. Requests without a Jetty base request record zero bytes, and the new lookup introduces no cast. Production filter registration and request parsing are unchanged.
This PR has been tested by:
println, unflushedprint, output-stream writes withContent-Length,UTF-8, a body past the output buffer, and HTTP 400, using the access-filter-before-interceptor
ordering of full-node wallet endpoints. An outer completion latch keeps the metric assertions
deterministic. Unit tests cover the non-Jetty fallback and propagation to both traffic meters.
printand large-body tests fail; mutation testing confirms theremaining assertions are not vacuous.
Follow up
Heads-up for whoever lands #6923: it removes the Codahale
MetricsUtil.meterMarkcalls from thissame method, so the two will conflict textually. The byte count itself is still needed afterwards
for the Prometheus
tron:http_byteshistogram.