Skip to content

Commit b0d95d1

Browse files
committed
cli/command/formatter: NewStats: update GoDoc and add TODO
Update the GoDoc to better align with the actual implementation. The "idOrName" is used for fuzzy-matching the container, which can result in multiple stats for the same container: docker ps --format 'table {{.ID}}\t{{.Names}}' CONTAINER ID NAMES b49e6c21d12e quizzical_maxwell docker stats --no-stream quizzical_maxwell b49e6c21d12e b49e6 CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS b49e6c21d12e quizzical_maxwell 0.10% 140.8MiB / 7.653GiB 1.80% 3.11MB / 13.4kB 115MB / 1.12MB 28 b49e6c21d12e quizzical_maxwell 0.10% 140.8MiB / 7.653GiB 1.80% 3.11MB / 13.4kB 115MB / 1.12MB 28 b49e6c21d12e quizzical_maxwell 0.10% 140.8MiB / 7.653GiB 1.80% 3.11MB / 13.4kB 115MB / 1.12MB 28 We should resolve the canonical ID once, then use that as reference to prevent duplicates. Various parts in the code compare Container against "ID" only (not considering "name" or "ID-prefix"). Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 8a2e52e commit b0d95d1

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

cli/command/container/formatter_stats.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,14 @@ func NewStatsFormat(source, osType string) formatter.Format {
111111
return formatter.Format(source)
112112
}
113113

114-
// NewStats returns a new Stats entity and sets in it the given name
115-
func NewStats(container string) *Stats {
116-
return &Stats{StatsEntry: StatsEntry{Container: container}}
114+
// NewStats returns a new Stats entity using the given ID, ID-prefix, or
115+
// name to resolve the container.
116+
func NewStats(idOrName string) *Stats {
117+
// FIXME(thaJeztah): "idOrName" is used for fuzzy-matching the container, which can result in multiple stats for the same container.
118+
// We should resolve the canonical ID once, then use that as reference
119+
// to prevent duplicates. Various parts in the code compare Container
120+
// against "ID" only (not considering "name" or "ID-prefix").
121+
return &Stats{StatsEntry: StatsEntry{Container: idOrName}}
117122
}
118123

119124
// statsFormatWrite renders the context for a list of containers statistics

0 commit comments

Comments
 (0)