1
0
mirror of https://github.com/docker/cli.git synced 2026-01-06 05:41:44 +03:00

cli/command/container: don't depend on result.OSType

This field is set for the request as a whole, so can be obtained
from the server-info instead. Docker v29 will provide per-stats
information.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-10-27 16:29:47 +01:00
parent 715467c9d8
commit 4b498addce
2 changed files with 3 additions and 8 deletions

View File

@@ -108,6 +108,9 @@ var acceptedStatsFilters = map[string]bool{
func RunStats(ctx context.Context, dockerCLI command.Cli, options *StatsOptions) error {
apiClient := dockerCLI.Client()
// Get the daemonOSType to handle platform-specific stats fields.
daemonOSType = dockerCLI.ServerInfo().OSType
// waitFirst is a WaitGroup to wait first stat data's reach for each container
waitFirst := &sync.WaitGroup{}
// closeChan is a non-buffered channel used to collect errors from goroutines.
@@ -261,12 +264,6 @@ func RunStats(ctx context.Context, dockerCLI command.Cli, options *StatsOptions)
format = formatter.TableFormatKey
}
}
if daemonOSType == "" {
// Get the daemonOSType if not set already. The daemonOSType variable
// should already be set when collecting stats as part of "collect()",
// so we unlikely hit this code in practice.
daemonOSType = dockerCLI.ServerInfo().OSType
}
// Buffer to store formatted stats text.
// Once formatted, it will be printed in one write to avoid screen flickering.

View File

@@ -95,8 +95,6 @@ func collect(ctx context.Context, s *Stats, cli client.ContainerAPIClient, strea
continue
}
daemonOSType = response.OSType
if daemonOSType != "windows" {
previousCPU = v.PreCPUStats.CPUUsage.TotalUsage
previousSystem = v.PreCPUStats.SystemUsage