Skip to content

Commit 4b498ad

Browse files
committed
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 <[email protected]>
1 parent 715467c commit 4b498ad

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

cli/command/container/stats.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ var acceptedStatsFilters = map[string]bool{
108108
func RunStats(ctx context.Context, dockerCLI command.Cli, options *StatsOptions) error {
109109
apiClient := dockerCLI.Client()
110110

111+
// Get the daemonOSType to handle platform-specific stats fields.
112+
daemonOSType = dockerCLI.ServerInfo().OSType
113+
111114
// waitFirst is a WaitGroup to wait first stat data's reach for each container
112115
waitFirst := &sync.WaitGroup{}
113116
// 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)
261264
format = formatter.TableFormatKey
262265
}
263266
}
264-
if daemonOSType == "" {
265-
// Get the daemonOSType if not set already. The daemonOSType variable
266-
// should already be set when collecting stats as part of "collect()",
267-
// so we unlikely hit this code in practice.
268-
daemonOSType = dockerCLI.ServerInfo().OSType
269-
}
270267

271268
// Buffer to store formatted stats text.
272269
// Once formatted, it will be printed in one write to avoid screen flickering.

cli/command/container/stats_helpers.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ func collect(ctx context.Context, s *Stats, cli client.ContainerAPIClient, strea
9595
continue
9696
}
9797

98-
daemonOSType = response.OSType
99-
10098
if daemonOSType != "windows" {
10199
previousCPU = v.PreCPUStats.CPUUsage.TotalUsage
102100
previousSystem = v.PreCPUStats.SystemUsage

0 commit comments

Comments
 (0)