CLI: Add container stats command#40500
Conversation
There was a problem hiding this comment.
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}/statssupport, plumb it throughIWSLCContainer::Stats, and surface it viawslc container stats/wslc stats. - Extend the CLI with a new
ContainerStatsCommandand 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. |
ptrivedi
left a comment
There was a problem hiding this comment.
some comments, but otherwise lgtm
|
I updated that any failure to get stats errors out and reports the error with no table or json printed. |
OneBlue
left a comment
There was a problem hiding this comment.
LGTM, one minor comment
| } | ||
| catch (const wil::ResultException& ex) | ||
| { | ||
| LOG_HR_MSG(ex.GetErrorCode(), "Failed to get stats for container %ws", containerId.c_str()); |
There was a problem hiding this comment.
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
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.
PR Checklist
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