Skip to content

[probes.http] Add full response latency measurements - #1567

Open
suikammd wants to merge 2 commits into
cloudprober:mainfrom
suikammd:http-full-response-latency
Open

suikammd wants to merge 2 commits into
cloudprober:mainfrom
suikammd:http-full-response-latency

Conversation

@suikammd

@suikammd suikammd commented Nov 17, 2026 •

Copy link
Copy Markdown

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:

  • go test -race ./probes/http/... ./probes/options/... ./config/...
  • go test -race ./probes/http/... -run 'TestFullResponseLatency' -count=3

Tests cover delayed bodies, histogram aggregation, custom names and units,
timeouts, truncated responses, validation failures, and concurrent requests.

close #1568

@manugarg manugarg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_latency includes time spent waiting for other requests to finish reading their bodies, so it's inflated.
  • response_read_latency is 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

  1. ALL_STAGES now emits extra metrics. Existing ALL_STAGES users get additional series per target (additional histograms with latency_distribution), and total latency isn't really a stage. Worth considering leaving it out of ALL_STAGES and requiring it explicitly.
  2. Proto comments: existing enum values have a trailing // Exported as xxx_latency; please follow that for the new value(s).
  3. 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.
  4. Tests:
    • TestFullResponseLatencyFailures packs five scenarios into one handler with if 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.go rather than a new file.
    • With the lock fix, the concurrent test could assert total >= latency + response_read per request.

@suikammd
suikammd force-pushed the http-full-response-latency branch 6 times, most recently from a7b8de9 to 8553378 Compare November 20, 2026 06:01
- 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.
@suikammd
suikammd force-pushed the http-full-response-latency branch from 8553378 to 4fdacdc Compare November 20, 2026 06:01
@suikammd

suikammd commented Nov 20, 2026 •

Copy link
Copy Markdown
Author

Hi @manugarg ,

Thanks for the review — all addressed in 4fdacdc:

  • Moved body read before resultMu.Lock(); totalLatency is captured at body-end so it excludes lock wait. Read error is handled after result.total++.
  • Dropped RESPONSE_READ_LATENCY.
  • TOTAL_LATENCY is no longer part of ALL_STAGES; requires explicit opt-in.
  • Added // Exported as ... on the new enum, trimmed the FAQ, moved tests into http_test.go, made the failure scenarios table-driven.

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.

go test -race ./probes/http/... ./probes/options/... ./config/... is green.

This branch has not been deployed

No deployments
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.

[probes.http] Support full HTTP response latency measurements

2 participants