Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimise BodyCapturer #592

Merged
merged 1 commit into from
Jul 22, 2019
Merged

Optimise BodyCapturer #592

merged 1 commit into from
Jul 22, 2019

Conversation

axw
Copy link
Member

@axw axw commented Jul 19, 2019

We optimise apm.BodyCapturer in two ways to reduce its overhead:

  • BodyCapturers are now pooled: CaptureHTTPRequestBody will
    acquire from the pool, and the new BodyCapturer.Discard method
    will release back to the pool.
  • We no longer use io.TeeReader to read into a bytes.Buffer,
    as that may lead to reading the entire request body into
    memory. Since we truncate the captured body anyway, we now
    copy only a limited amount into a buffer.

Fixes #580

@codecov-io
Copy link

codecov-io commented Jul 19, 2019

Codecov Report

Merging #592 into master will increase coverage by 0.04%.
The diff coverage is 94.11%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #592      +/-   ##
==========================================
+ Coverage   87.68%   87.72%   +0.04%     
==========================================
  Files         121      121              
  Lines        7218     7253      +35     
==========================================
+ Hits         6329     6363      +34     
- Misses        791      793       +2     
+ Partials       98       97       -1
Impacted Files Coverage Δ
module/apmhttp/handler.go 83.89% <100%> (+0.13%) ⬆️
module/apmhttprouter/handler.go 76.19% <100%> (+0.38%) ⬆️
module/apmechov4/middleware.go 88.77% <100%> (+0.11%) ⬆️
module/apmrestful/filter.go 90% <100%> (+0.2%) ⬆️
module/apmgin/middleware.go 86.84% <100%> (+0.17%) ⬆️
module/apmecho/middleware.go 88.77% <100%> (+0.11%) ⬆️
capturebody.go 95.52% <93.33%> (-4.48%) ⬇️
tracer.go 92% <0%> (+0.38%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e92cea0...2913ce5. Read the comment docs.

We optimise apm.BodyCapturer in two ways to reduce its overhead:

- BodyCapturers are now pooled: CaptureHTTPRequestBody will
  acquire from the pool, and the new BodyCapturer.Discard method
  will release back to the pool.
- We no longer use io.TeeReader to read into a bytes.Buffer,
  as that may lead to reading the entire request body into
  memory. Since we truncate the captured body anyway, we now
  copy only a limited amount into a buffer.
@axw axw force-pushed the capture-body-limit-buffer branch from 6da8cac to 2913ce5 Compare July 22, 2019 03:31
@axw axw merged commit 05673a1 into elastic:master Jul 22, 2019
@axw axw deleted the capture-body-limit-buffer branch July 22, 2019 04:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Truncate large captured body
2 participants