Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stats compat API: return "id" lowercase #17890

Merged
merged 1 commit into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pkg/api/handlers/compat/containers_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/api/handlers/compat/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
8 changes: 7 additions & 1 deletion test/apiv2/20-containers.at
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down