Skip to content

Commit ca06b22

Browse files
committed
api/types/container: merge Stats and StatsResponse
The StatsResponse type was a compatibility-wrapper introduced in d337994 to differentiate responses for API < 1.21 and API >= 1.21. API versions lower than 1.24 are deprecated, and we can merge these types again. The Stats type was not used directly, but deprecating it, and making it an alias for StatsResponse, which provides a superset of its fields. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 033f975 commit ca06b22

3 files changed

Lines changed: 20 additions & 22 deletions

File tree

api/types/container/stats.go

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,15 @@ type PidsStats struct {
148148
}
149149

150150
// Stats is Ultimate struct aggregating all types of stats of one container
151-
type Stats struct {
151+
//
152+
// Deprecated: use [StatsResponse] instead. This type will be removed in the next release.
153+
type Stats = StatsResponse
154+
155+
// StatsResponse aggregates all types of stats of one container.
156+
type StatsResponse struct {
157+
Name string `json:"name,omitempty"`
158+
ID string `json:"id,omitempty"`
159+
152160
// Common stats
153161
Read time.Time `json:"read"`
154162
PreRead time.Time `json:"preread"`
@@ -162,20 +170,8 @@ type Stats struct {
162170
StorageStats StorageStats `json:"storage_stats,omitempty"`
163171

164172
// Shared stats
165-
CPUStats CPUStats `json:"cpu_stats,omitempty"`
166-
PreCPUStats CPUStats `json:"precpu_stats,omitempty"` // "Pre"="Previous"
167-
MemoryStats MemoryStats `json:"memory_stats,omitempty"`
168-
}
169-
170-
// StatsResponse is newly used Networks.
171-
//
172-
// TODO(thaJeztah): unify with [Stats]. This wrapper was to account for pre-api v1.21 changes, see https://github.com/moby/moby/commit/d3379946ec96fb6163cb8c4517d7d5a067045801
173-
type StatsResponse struct {
174-
Stats
175-
176-
Name string `json:"name,omitempty"`
177-
ID string `json:"id,omitempty"`
178-
179-
// Networks request version >=1.21
180-
Networks map[string]NetworkStats `json:"networks,omitempty"`
173+
CPUStats CPUStats `json:"cpu_stats,omitempty"`
174+
PreCPUStats CPUStats `json:"precpu_stats,omitempty"` // "Pre"="Previous"
175+
MemoryStats MemoryStats `json:"memory_stats,omitempty"`
176+
Networks map[string]NetworkStats `json:"networks,omitempty"`
181177
}

daemon/stats_unix.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ func (daemon *Daemon) stats(c *container.Container) (*containertypes.StatsRespon
4444
}
4545
return nil, err
4646
}
47-
s := &containertypes.StatsResponse{}
48-
s.Read = cs.Read
47+
s := &containertypes.StatsResponse{
48+
Read: cs.Read,
49+
}
4950
stats := cs.Metrics
5051
switch t := stats.(type) {
5152
case *statsV1.Metrics:

daemon/stats_windows.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ func (daemon *Daemon) stats(c *container.Container) (*containertypes.StatsRespon
2727
}
2828

2929
// Start with an empty structure
30-
s := &containertypes.StatsResponse{}
31-
s.Stats.Read = stats.Read
32-
s.Stats.NumProcs = platform.NumProcs()
30+
s := &containertypes.StatsResponse{
31+
Read: stats.Read,
32+
NumProcs: platform.NumProcs(),
33+
}
3334

3435
if stats.HCSStats != nil {
3536
hcss := stats.HCSStats

0 commit comments

Comments
 (0)