Skip to content

daemon: Daemon.stats: fill-in container ID and Name when collecting#51302

Merged
thaJeztah merged 2 commits intomoby:masterfrom
thaJeztah:fix_one_shot_stats
Oct 27, 2025
Merged

daemon: Daemon.stats: fill-in container ID and Name when collecting#51302
thaJeztah merged 2 commits intomoby:masterfrom
thaJeztah:fix_one_shot_stats

Conversation

@thaJeztah
Copy link
Member

Propagate these fields when collecting the data, instead of patching the result inside the router.

This also fixes a bug where the ID and Name fields were not set when using one-shot.

Before this patch, the "id" and "name" fields were not set in one-shot mode:

curl -s --unix-socket /var/run/docker.sock 'http://localhost/v1.51/containers/foo/stats?stream=false' | jq .id
"125d7f3df7919c33195fa4ec0636c27cdbe6d9b14339867d2920900565bcaf7e"
curl -s --unix-socket /var/run/docker.sock 'http://localhost/v1.51/containers/foo/stats?stream=false' | jq .name
"/foo"

curl -s --unix-socket /var/run/docker.sock 'http://localhost/v1.51/containers/foo/stats?stream=false&one-shot=true' | jq .id
null
curl -s --unix-socket /var/run/docker.sock 'http://localhost/v1.51/containers/foo/stats?stream=false&one-shot=true' | jq .name
null

With this patch, both are set:

curl -s --unix-socket /var/run/docker.sock 'http://localhost/v1.51/containers/foo/stats?stream=false&one-shot=true' | jq .id
"125d7f3df7919c33195fa4ec0636c27cdbe6d9b14339867d2920900565bcaf7e"
curl -s --unix-socket /var/run/docker.sock 'http://localhost/v1.51/containers/foo/stats?stream=false&one-shot=true' | jq .name
"/foo"

- What I did

- How I did it

- How to verify it

- Human readable description for the release notes

Fix a bug where collecting container stats in "one-shot" mode would not include the container's ID and Name.

- A picture of a cute animal (not mandatory but encouraged)

Propagate these fields when collecting the data, instead of patching the
result inside the router.

This also fixes a bug where the ID and Name fields were not set when using
one-shot.

Before this patch, the "id" and "name" fields were not set in one-shot mode:

    curl -s --unix-socket /var/run/docker.sock 'http://localhost/v1.51/containers/foo/stats?stream=false' | jq .id
    "125d7f3df7919c33195fa4ec0636c27cdbe6d9b14339867d2920900565bcaf7e"
    curl -s --unix-socket /var/run/docker.sock 'http://localhost/v1.51/containers/foo/stats?stream=false' | jq .name
    "/foo"

    curl -s --unix-socket /var/run/docker.sock 'http://localhost/v1.51/containers/foo/stats?stream=false&one-shot=true' | jq .id
    null
    curl -s --unix-socket /var/run/docker.sock 'http://localhost/v1.51/containers/foo/stats?stream=false&one-shot=true' | jq .name
    null

With this patch, both are set:

    curl -s --unix-socket /var/run/docker.sock 'http://localhost/v1.51/containers/foo/stats?stream=false&one-shot=true' | jq .id
    "125d7f3df7919c33195fa4ec0636c27cdbe6d9b14339867d2920900565bcaf7e"
    curl -s --unix-socket /var/run/docker.sock 'http://localhost/v1.51/containers/foo/stats?stream=false&one-shot=true' | jq .name
    "/foo"

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah merged commit 6511d86 into moby:master Oct 27, 2025
285 of 288 checks passed
@thaJeztah thaJeztah deleted the fix_one_shot_stats branch October 27, 2025 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants