Repository navigation
Conversation
manugarg
left a comment
There was a problem hiding this comment.
Thanks for the PR, and for the thorough tests! A few comments.
Body read happens under resultMu, which skews both new metrics
doHTTPRequest takes resultMu right after client.Do() returns, and io.ReadAll(resp.Body) runs under that lock. That's pre-existing, but the new timings now span it. With requests_per_probe > 1:
total_latencyincludes time spent waiting for other requests to finish reading their bodies, so it's inflated.response_read_latencyis deflated: while a request waits for the lock, its body is already arriving in the socket buffer, so the timed read is mostly a buffer copy.
The docs acknowledge this, but for slow APIs with large bodies (the use case in #1568), both numbers end up misleading.
Could you move the body read before taking the lock? Keep the read error and handle it after result.total++. Then total ≈ latency + response_read, concurrent requests no longer read their bodies one at a time, and the lock-wait paragraph in the docs can go.
Do we need both metrics?
Once the read is outside the lock, the non-distribution case gives total_latency == latency + response_read_latency exactly, since all three are recorded only on success. TOTAL_LATENCY is really needed only for distributions, because you can't get end-to-end percentiles from two separate histograms. Conversely, response_read_latency's sum can be derived from total - latency. To keep things simple, how about adding only TOTAL_LATENCY? Is there a strong need for read-time percentiles specifically?
Smaller points
ALL_STAGESnow emits extra metrics. ExistingALL_STAGESusers get additional series per target (additional histograms withlatency_distribution), and total latency isn't really a stage. Worth considering leaving it out ofALL_STAGESand requiring it explicitly.- Proto comments: existing enum values have a trailing
// Exported as xxx_latency; please follow that for the new value(s). - Docs: the FAQ addition is long for what it adds. After the lock fix it can be a couple of lines: what it measures, that it's recorded only for successful probes, and that it overlaps the stage metrics.
- Tests:
TestFullResponseLatencyFailurespacks five scenarios into one handler withif scenario == ...branches. A table with a per-case handler and expected error would be easier to read.- These tests would normally go in
http_test.gorather than a new file. - With the lock fix, the concurrent test could assert
total >= latency + response_readper request.
a7b8de9 to
8553378
Compare
- Move io.ReadAll(resp.Body) before acquiring resultMu so concurrent requests no longer serialize their body reads. Capture totalLatency at body-end time, before the lock, to exclude lock wait. - Drop RESPONSE_READ_LATENCY. With the lock fix, response_read equals total - latency in the non-distribution case, and read-time percentiles alone aren't a strong enough use case. - Exclude TOTAL_LATENCY from ALL_STAGES: total isn't a stage, and implicit inclusion would add an unexpected series for existing ALL_STAGES users. Require explicit selection. - Align proto "Exported as" comments with existing enum values. - Trim FAQ; the lock-wait paragraph is no longer needed. - Merge full-response tests into http_test.go and refactor the failure scenarios into a table-driven test with per-case handlers. Concurrent test now also asserts wall time stays well below serialized-read time.
8553378 to
4fdacdc
Compare
|
Hi @manugarg , Thanks for the review — all addressed in 4fdacdc:
One honest call-out on the concurrent test: it only verifies per-sample accounting — it can't distinguish body-read-inside-lock from body-read-outside-lock, since both produce identical aggregated distribution shapes. A blocking-transport barrier could enforce the lock property deterministically; I left it out for simplicity but happy to add one if you'd like the stronger regression guard.
|
Add RESPONSE_READ_LATENCY and TOTAL_LATENCY to HTTP latency_breakdown,
including ALL_STAGES. Existing latency semantics remain unchanged.
Both measurements reuse latency aggregation, histogram configuration,
metric naming, and units. Durations stop when the response body read
completes, before validation and response metrics parsing. Samples are
recorded only after a complete read and successful validation.
Preserve existing timeout accounting, error handling, and locking behavior.
Update protobuf configuration, generated code, and documentation.
Validation:
Tests cover delayed bodies, histogram aggregation, custom names and units,
timeouts, truncated responses, validation failures, and concurrent requests.
close #1568