test(agent): cover mb_served metric in download paths#609
test(agent): cover mb_served metric in download paths#609honeynil wants to merge 2 commits intouber:masterfrom
Conversation
The mb_served counter introduced in uber#597 had no unit test coverage in either the HTTP API path (agent/agentserver) or the Docker registry path (lib/dockerregistry/transfer). Both test suites passed tally.NoopScope to the constructor, which silently discards counter emissions, so a regression (renamed counter, broken division) would not be caught. Switch serverMocks and agentTransfererMocks to tally.TestScope, matching the pattern already used in tracker/trackerserver, and add cases for: - large blob (>= 1 MiB) -> counter equals MiB count - exact 1 MiB blob -> counter equals 1 - sub-MiB blob -> counter is 0 (integer truncation) - cached download (ro_transferer) -> counter increments per call - failing io.Copy in downloadBlobHandler -> counter still increments, documenting that the metric counts attempted serves, not bytes actually delivered
There was a problem hiding this comment.
Pull request overview
This PR adds unit coverage for the mb_served metric introduced in #597 so regressions in the agent’s two download-serving paths are caught by tests rather than being silently dropped by tally.NoopScope.
Changes:
- Replaces test-only
tally.NoopScopeusage withtally.NewTestScopein the affected agent server and read-only transferer test fixtures. - Adds
mb_servedassertions for 2 MiB, exactly 1 MiB, and sub-MiB downloads in both download paths. - Adds behavior-focused tests for repeated cached reads in
ro_transfererand fordownloadBlobHandlerincrementing the metric even when the response write fails.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
lib/dockerregistry/transfer/ro_transferer_test.go |
Updates transferer test fixtures to use tally.TestScope and adds metric assertions for normal and cached download paths. |
agent/agentserver/server_test.go |
Updates server test fixtures to use tally.TestScope and adds metric assertions for HTTP downloads, including write-failure behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // counter is incremented before io.Copy runs, so on a client disconnect (or | ||
| // any other write failure) the counter still records a full serve even though | ||
| // no bytes actually reached the client. This is the existing behavior after | ||
| // PR #597; if a future change moves the increment to after a successful copy, |
There was a problem hiding this comment.
Remove this line from the comment?
|
|
||
| // failingResponseWriter always errors on Write, simulating a client that | ||
| // disconnected after the response headers were sent. | ||
| type failingResponseWriter struct { |
There was a problem hiding this comment.
Let's add a compile-time check after the definition:
var _ http.ResponseWriter = (*failingResponseWriter)(nil)| if c.Name() == "mb_served" { | ||
| total += c.Value() |
There was a problem hiding this comment.
Would the metrics not be emitted to the same counter? If so, we can just immediately return c.Value() from within the loop.
8c3d8d8 to
71fc4a2
Compare
| // failingResponseWriter always errors on Write, simulating a client that | ||
| // disconnected after the response headers were sent. | ||
| type failingResponseWriter struct { | ||
| header http.Header |
There was a problem hiding this comment.
Let's drop this field and simply return http.Header{} from within Header().
71fc4a2 to
b8734d6
Compare
The mb_served counter introduced in #597 had no unit test coverage
in either the HTTP API path (agent/agentserver) or the Docker registry
path (lib/dockerregistry/transfer). Both test suites passed
tally.NoopScope to the constructor, which silently discards counter
emissions, so a regression (renamed counter, broken division) would
not be caught.
Switch serverMocks and agentTransfererMocks to tally.TestScope,
matching the pattern already used in tracker/trackerserver, and add
cases for:
documenting that the metric counts attempted serves, not bytes
actually delivered
Closes #598