mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
fix pre-1.22 docker stats
This fixes a bug introduced in #15786: * if a pre-v1.20 client requested docker stats, the daemon would return both an API-compatible JSON blob *and* an API-incompatible JSON blob: see https://gist.github.com/donhcd/338a5b3681cd6a071629 Signed-off-by: Donald Huang <don.hcd@gmail.com>
This commit is contained in:
parent
23a0fe9627
commit
d2c04f844b
1 changed files with 7 additions and 18 deletions
|
@ -71,7 +71,8 @@ func (daemon *Daemon) ContainerStats(prefixOrName string, config *ContainerStats
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
statsJSON := getStatJSON(v)
|
var statsJSON interface{}
|
||||||
|
statsJSONPost120 := getStatJSON(v)
|
||||||
if config.Version.LessThan("1.21") {
|
if config.Version.LessThan("1.21") {
|
||||||
var (
|
var (
|
||||||
rxBytes uint64
|
rxBytes uint64
|
||||||
|
@ -83,7 +84,7 @@ func (daemon *Daemon) ContainerStats(prefixOrName string, config *ContainerStats
|
||||||
txErrors uint64
|
txErrors uint64
|
||||||
txDropped uint64
|
txDropped uint64
|
||||||
)
|
)
|
||||||
for _, v := range statsJSON.Networks {
|
for _, v := range statsJSONPost120.Networks {
|
||||||
rxBytes += v.RxBytes
|
rxBytes += v.RxBytes
|
||||||
rxPackets += v.RxPackets
|
rxPackets += v.RxPackets
|
||||||
rxErrors += v.RxErrors
|
rxErrors += v.RxErrors
|
||||||
|
@ -93,8 +94,8 @@ func (daemon *Daemon) ContainerStats(prefixOrName string, config *ContainerStats
|
||||||
txErrors += v.TxErrors
|
txErrors += v.TxErrors
|
||||||
txDropped += v.TxDropped
|
txDropped += v.TxDropped
|
||||||
}
|
}
|
||||||
statsJSONPre121 := &v1p20.StatsJSON{
|
statsJSON = &v1p20.StatsJSON{
|
||||||
Stats: statsJSON.Stats,
|
Stats: statsJSONPost120.Stats,
|
||||||
Network: types.NetworkStats{
|
Network: types.NetworkStats{
|
||||||
RxBytes: rxBytes,
|
RxBytes: rxBytes,
|
||||||
RxPackets: rxPackets,
|
RxPackets: rxPackets,
|
||||||
|
@ -106,20 +107,8 @@ func (daemon *Daemon) ContainerStats(prefixOrName string, config *ContainerStats
|
||||||
TxDropped: txDropped,
|
TxDropped: txDropped,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
if !config.Stream && noStreamFirstFrame {
|
statsJSON = statsJSONPost120
|
||||||
// prime the cpu stats so they aren't 0 in the final output
|
|
||||||
noStreamFirstFrame = false
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := enc.Encode(statsJSONPre121); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !config.Stream {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !config.Stream && noStreamFirstFrame {
|
if !config.Stream && noStreamFirstFrame {
|
||||||
|
|
Loading…
Add table
Reference in a new issue