Skip to content

refactor(api): replace response copy wrappers with Jetty content count - #6982

Open
halibobo1205 wants to merge 1 commit into
tronprotocol:release_v4.8.3from
halibobo1205:feature/jetty_content_count
Open

halibobo1205 wants to merge 1 commit into
tronprotocol:release_v4.8.3from
halibobo1205:feature/jetty_content_count

Conversation

@halibobo1205

Copy link
Copy Markdown
Collaborator

What does this PR do?

Replaces response-body copying for HTTP traffic metrics with Jetty's native Response.getContentCount(). Removes CharResponseWrapper, ServletOutputStreamCopy, and the unused response wrapping in HttpApiAccessFilter.

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. HttpApiAccessFilter built 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 OutputStreamWriter buffer. Unflushed print() calls could lose an entire small response or the trailing bytes of a larger response. This is latent rather than live: every servlet under services/http ends with println, and the one non-println writer 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:

  • Unit Tests
    • Real-Jetty tests cover println, unflushed print, output-stream writes with Content-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.
    • On the pre-change classes, the print and large-body tests fail; mutation testing confirms the
      remaining assertions are not vacuous.
    • Focused tests passed.
  • Manual Testing
    • Test by private chain.

Follow up

Heads-up for whoever lands #6923: it removes the Codahale MetricsUtil.meterMark calls from this
same method, so the two will conflict textually. The byte count itself is still needed afterwards
for the Prometheus tron:http_bytes histogram.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:api rpc/http related issue topic:metrics

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

2 participants