Skip to content

Commit b309524

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 abd2e21 commit b309524

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
@@ -112,9 +112,14 @@ func NewStatsFormat(source, osType string) formatter.Format {
112112
return formatter.Format(source)
113113
}
114114

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

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

0 commit comments

Comments
 (0)