Skip to content

Commit 5c54f75

Browse files
committed
cli/command/container: use ping-result for OS-version
The daemonOSType variable is already set when collecting stats, so we unlikely hit this code in practice, and it would only be set if `collect()` failed and we never got a stats response. If we do need to get this information, let's use the OSVersion we already obtained from the ping response. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 952c807 commit 5c54f75

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

cli/command/container/stats.go

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

109-
// Get the daemonOSType if not set already
110-
if daemonOSType == "" {
111-
sv, err := apiClient.ServerVersion(ctx)
112-
if err != nil {
113-
return err
114-
}
115-
daemonOSType = sv.Os
116-
}
117-
118109
// waitFirst is a WaitGroup to wait first stat data's reach for each container
119110
waitFirst := &sync.WaitGroup{}
120111
// closeChan is a non-buffered channel used to collect errors from goroutines.
@@ -267,6 +258,12 @@ func RunStats(ctx context.Context, dockerCLI command.Cli, options *StatsOptions)
267258
format = formatter.TableFormatKey
268259
}
269260
}
261+
if daemonOSType == "" {
262+
// Get the daemonOSType if not set already. The daemonOSType variable
263+
// should already be set when collecting stats as part of "collect()",
264+
// so we unlikely hit this code in practice.
265+
daemonOSType = dockerCLI.ServerInfo().OSType
266+
}
270267
statsCtx := formatter.Context{
271268
Output: dockerCLI.Out(),
272269
Format: NewStatsFormat(format, daemonOSType),

0 commit comments

Comments
 (0)