Merge pull request #17890 from Luap99/stats-compat

stats compat API: return "id" lowercase
This commit is contained in:
OpenShift Merge Robot 2023-03-24 04:27:50 -04:00 committed by GitHub
commit 8720235164
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 2 deletions

View File

@ -202,7 +202,14 @@ streamLabel: // A label to flatten the scope
Networks: net,
}
if err := coder.Encode(s); err != nil {
var jsonOut interface{}
if utils.IsLibpodRequest(r) {
jsonOut = s
} else {
jsonOut = DockerStatsJSON(s)
}
if err := coder.Encode(jsonOut); err != nil {
logrus.Errorf("Unable to encode stats: %v", err)
return
}

View File

@ -53,3 +53,16 @@ type StatsJSON struct {
// Networks request version >=1.21
Networks map[string]docker.NetworkStats `json:"networks,omitempty"`
}
// DockerStatsJSON is the same as StatsJSON except for the lowercase
// "id" in the JSON tag. This is needed for docker compat but we should
// not change the libpod API output for backwards compat reasons.
type DockerStatsJSON struct {
Stats
Name string `json:"name,omitempty"`
ID string `json:"id,omitempty"`
// Networks request version >=1.21
Networks map[string]docker.NetworkStats `json:"networks,omitempty"`
}

View File

@ -113,7 +113,13 @@ if root; then
podman run --name $CTRNAME -d -m 512m -v /tmp:/tmp $IMAGE top
t GET libpod/containers/$CTRNAME/stats?stream=false 200 \
.memory_stats.limit=536870912
.memory_stats.limit=536870912 \
.Id~[0-9a-f]\\{64\\}
# Make sure docker compat endpoint shows "id" lowercase
t GET containers/$CTRNAME/stats?stream=false 200 \
.memory_stats.limit=536870912 \
.id~[0-9a-f]\\{64\\}
podman rm -f $CTRNAME
fi