Skip to content

CLI: Add container stats command#40500

Open
dkbennett wants to merge 10 commits into
masterfrom
user/dkbennett/containerstatscmd
Open

CLI: Add container stats command#40500
dkbennett wants to merge 10 commits into
masterfrom
user/dkbennett/containerstatscmd

Conversation

@dkbennett
Copy link
Copy Markdown
Member

@dkbennett dkbennett commented May 11, 2026

Summary of the Pull Request

Adds container stats command, also aliased to the root as 'stats'.
Fixes a few bugs in TableOutput discovered in testing.
Fixes a bug in the container stats runtime (name and id were omitted).
Added loc for table headers for container list and container stats.
Adds E2E CLI tests for container stats command.
Updates unit tests for commands for the new stats command.

image

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Copilot will do a much better job of a detailed description than I could write here.

Validation Steps Performed

  • Manual testing of the command
  • Automated tests added pass
  • TableOutput unit tests and ContainerStats runtime tests were also run and pass since they were updated.

Copilot AI review requested due to automatic review settings May 11, 2026 18:58
@dkbennett dkbennett requested a review from a team as a code owner May 11, 2026 18:58
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 a new wslc container stats command (also available at the root as stats) to display a snapshot of container resource usage, wiring the feature end-to-end from the Docker HTTP client through the COM container API into the CLI, and adding both unit/integration and E2E coverage.

Changes:

  • Add Docker /containers/{id}/stats support, plumb it through IWSLCContainer::Stats, and surface it via wslc container stats / wslc stats.
  • Extend the CLI with a new ContainerStatsCommand and implement formatted tabular output for CPU/memory/net/block/PIDs.
  • Add/update tests (TAEF + E2E) and localize CLI table headers and command descriptions.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
test/windows/WSLCTests.cpp Adds runtime-level tests for IWSLCContainer::Stats (running/created containers, null output pointer).
test/windows/wslc/e2e/WSLCE2EContainerStatsTests.cpp New E2E CLI tests validating container stats output/flags.
test/windows/wslc/CommandLineTestCases.h Adds command-line parsing test cases for the new stats command and aliases.
src/windows/wslcsession/WSLCContainer.h Adds Stats to the container implementation and COM wrapper declarations.
src/windows/wslcsession/WSLCContainer.cpp Implements WSLCContainerImpl::Stats and the COM WSLCContainer::Stats entrypoint.
src/windows/wslcsession/DockerHTTPClient.h Declares DockerHTTPClient::ContainerStats.
src/windows/wslcsession/DockerHTTPClient.cpp Implements /containers/{id}/stats HTTP transaction (non-streaming snapshot).
src/windows/wslc/tasks/ContainerTasks.h Declares the new ShowContainerStats task.
src/windows/wslc/tasks/ContainerTasks.cpp Implements ShowContainerStats formatting/aggregation and integrates localized table headers.
src/windows/wslc/services/ContainerService.h Adds ContainerService::Stats and includes docker schema types.
src/windows/wslc/services/ContainerService.cpp Implements stats retrieval via IWSLCContainer::Stats and JSON deserialization.
src/windows/wslc/core/TableOutput.h Adjusts console-width behavior and adds support for keeping header width even with empty columns.
src/windows/wslc/commands/RootCommand.cpp Registers ContainerStatsCommand at the root level (alias behavior).
src/windows/wslc/commands/ContainerStatsCommand.cpp New command implementation wiring tasks into container stats.
src/windows/wslc/commands/ContainerCommand.h Declares the new ContainerStatsCommand.
src/windows/wslc/commands/ContainerCommand.cpp Registers ContainerStatsCommand under container.
src/windows/service/inc/wslc.idl Adds Stats to the IWSLCContainer COM interface.
src/windows/inc/docker_schema.h Adds JSON schema structs for the Docker container stats response.
localization/strings/en-US/Resources.resw Adds localized strings for stats descriptions and CLI table headers.

Comment thread src/windows/wslc/core/TableOutput.h
Comment thread src/windows/wslc/tasks/ContainerTasks.cpp
Comment thread src/windows/wslc/tasks/ContainerTasks.cpp Outdated
Comment thread test/windows/wslc/e2e/WSLCE2EContainerStatsTests.cpp Outdated
Comment thread test/windows/wslc/e2e/WSLCE2EContainerStatsTests.cpp Outdated
Comment thread test/windows/wslc/e2e/WSLCE2EContainerStatsTests.cpp Outdated
Comment thread test/windows/wslc/e2e/WSLCE2EContainerStatsTests.cpp Outdated
Copilot AI review requested due to automatic review settings May 11, 2026 19:50
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

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.

Comment thread test/windows/wslc/e2e/WSLCE2EContainerStatsTests.cpp Outdated
Comment thread src/windows/wslc/commands/RootCommand.cpp
Comment thread src/windows/wslc/commands/ContainerCommand.cpp
Comment thread src/windows/wslc/tasks/ContainerTasks.cpp Outdated
Comment thread test/windows/WSLCTests.cpp
Copilot AI review requested due to automatic review settings May 11, 2026 21:00
Comment thread src/windows/wslc/tasks/ContainerTasks.cpp Outdated
Comment thread src/windows/wslc/tasks/ContainerTasks.cpp Outdated
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

Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.

Comment thread test/windows/WSLCTests.cpp
Comment thread src/windows/wslc/tasks/ContainerTasks.cpp
Comment thread src/windows/wslc/tasks/ContainerTasks.cpp Outdated
Comment thread test/windows/wslc/e2e/WSLCE2EContainerStatsTests.cpp
ptrivedi
ptrivedi previously approved these changes May 11, 2026
Copy link
Copy Markdown
Contributor

@ptrivedi ptrivedi left a comment

Choose a reason for hiding this comment

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

some comments, but otherwise lgtm

Comment thread src/windows/wslc/tasks/ContainerTasks.cpp Outdated
Copilot AI review requested due to automatic review settings May 13, 2026 05:45
@dkbennett
Copy link
Copy Markdown
Member Author

I updated that any failure to get stats errors out and reports the error with no table or json printed.

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

Copilot reviewed 16 out of 16 changed files in this pull request and generated no new comments.

@dkbennett dkbennett requested a review from OneBlue May 13, 2026 05:56
@dkbennett dkbennett requested a review from ptrivedi May 13, 2026 05:56
Copy link
Copy Markdown
Collaborator

@OneBlue OneBlue left a comment

Choose a reason for hiding this comment

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

LGTM, one minor comment

}
catch (const wil::ResultException& ex)
{
LOG_HR_MSG(ex.GetErrorCode(), "Failed to get stats for container %ws", containerId.c_str());
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.

If the user didn't ask for specific containers, we should ignore RPC_E_DISCONNECTED, in case a container was deleted between the time we enumerated it and the time we queried its stats

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.

4 participants