Add Metrics to RetryableHTTPClient #4545
Open
+177
−4
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.
Description:
This PR adds a new HTTP response body size metric to
InstrumentedTransport, which is the currentTransportforSaneHTTPClient.InstrumentedTransportis also set to be used as theTransportforRetryableHTTPClient.Challenge with Response Body Size Calculation:
Responseobject has aContentLengthfield that may have exactly what we're looking for, but it is not guaranteed to be provided by the server. Also it is never available for a chunked response.RoundTrip()call, and would require restoring the body so that downstream code can read it again.Solution:
To address this, a
responseSizeCounterReadCloseris introduced to measure the size of the response body WHILE the downstream code reads it. This ensures no overhead is added in theRoundTrip()call. This however will not work if the downstream code never reads the body (e.g. detectors where only theStatusCodeis used to verify), so to handle this, we add a check in theClose()method of theReadCloserto drain the body if it's not consumed.Checklist:
make test-community)?make lintthis requires golangci-lint)?