Skip to content

test(agent): cover mb_served metric in download paths#609

Merged
thijmv merged 2 commits intouber:masterfrom
dmedovich:test/mb-served-coverage
May 11, 2026
Merged

test(agent): cover mb_served metric in download paths#609
thijmv merged 2 commits intouber:masterfrom
dmedovich:test/mb-served-coverage

Conversation

@dmedovich
Copy link
Copy Markdown
Contributor

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:

  • 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

Closes #598

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:

  - 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
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 28, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.NoopScope usage with tally.NewTestScope in the affected agent server and read-only transferer test fixtures.
  • Adds mb_served assertions for 2 MiB, exactly 1 MiB, and sub-MiB downloads in both download paths.
  • Adds behavior-focused tests for repeated cached reads in ro_transferer and for downloadBlobHandler incrementing 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.

Comment thread agent/agentserver/server_test.go Outdated
// 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,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Remove this line from the comment?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed, thanks!

@dmedovich dmedovich requested a review from sambhav-jain-16 May 5, 2026 15:44
Copy link
Copy Markdown
Collaborator

@thijmv thijmv left a comment

Choose a reason for hiding this comment

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

Two small comments:

Comment thread agent/agentserver/server_test.go Outdated

// failingResponseWriter always errors on Write, simulating a client that
// disconnected after the response headers were sent.
type failingResponseWriter struct {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's add a compile-time check after the definition:

var _ http.ResponseWriter = (*failingResponseWriter)(nil)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sure, thx sir!

Comment thread agent/agentserver/server_test.go Outdated
Comment on lines +118 to +119
if c.Name() == "mb_served" {
total += c.Value()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would the metrics not be emitted to the same counter? If so, we can just immediately return c.Value() from within the loop.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sure, thx sir!

@dmedovich dmedovich force-pushed the test/mb-served-coverage branch from 8c3d8d8 to 71fc4a2 Compare May 6, 2026 14:40
Comment thread agent/agentserver/server_test.go Outdated
// failingResponseWriter always errors on Write, simulating a client that
// disconnected after the response headers were sent.
type failingResponseWriter struct {
header http.Header
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's drop this field and simply return http.Header{} from within Header().

@dmedovich dmedovich force-pushed the test/mb-served-coverage branch from 71fc4a2 to b8734d6 Compare May 7, 2026 14:20
@dmedovich dmedovich requested a review from thijmv May 8, 2026 15:57
@thijmv thijmv merged commit 39d69e4 into uber:master May 11, 2026
10 checks passed
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.

feat(agent): add unit tests for mb_served metric in download paths

5 participants