Skip to content

Conversation

@mdaffad
Copy link
Contributor

@mdaffad mdaffad commented Jun 28, 2025

- What I did
Add HealthStatus attribute for dokcer ps command

- How I did it

  1. Add new attribute with type HealthSummary on ContainerSummary

- How to verify it

  1. Run container with health check
# healthy status
docker run -d   --name traefik-test   --health-cmd="wget -qO- http://localhost:8080/ping || exit 1"   --health-interval=5s   --health-retries=3   traefik:v2.11   --ping
# unhealthy status
docker run -d --name test-fail   --health-cmd="exit 1"   --health-interval=3s   busybox:latest   sleep 300
  1. Run this command curl --unix-socket /var/run/docker.sock http://localhost/containers/json | jq

- Human readable description for the release notes

`GET /containers/json` now includes a `Health` field describing container healthcheck status.

@vvoland vvoland added area/api API kind/feature Functionality or other elements that the project doesn't currently have. Features are new and shiny labels Jun 30, 2025
@vvoland vvoland added this to the 29.0.0 milestone Jun 30, 2025
@mdaffad mdaffad force-pushed the 50253-add-container-health-on-containers-list-api branch from e975835 to 7b24f12 Compare July 4, 2025 16:15
@vvoland
Copy link
Contributor

vvoland commented Jul 4, 2025

Thanks!
Please rebase the branch and squash commits, see: https://github.com/moby/moby/blob/master/CONTRIBUTING.md#review

@mdaffad mdaffad force-pushed the 50253-add-container-health-on-containers-list-api branch from 89a0f83 to e4fb1d1 Compare July 4, 2025 17:00
@mdaffad
Copy link
Contributor Author

mdaffad commented Jul 4, 2025

Updated

NetworkMode string `json:",omitempty"`
Annotations map[string]string `json:",omitempty"`
}
Health HealthSummary
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we want to make it *HealthSummary and make it nil/null instead of the Status=none.

Thoughts?

cc @moby/moby-committers

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we probably want it to be omitted for older API versions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We historically haven't bothered omitting fields in responses for older API versions since clients that don't know about them just ignore them. I don't think it's worth fussing about here, either.

I like it the way it is. Clients can trivially detect whether the daemon is capable of providing health summaries by the presence of the Health property in the response, even when the container being inspected is not running.

Copy link
Contributor Author

@mdaffad mdaffad Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the discussion:

  1. If i want to support the older API versions using *HealthSummary to allow nullable value, do i need declare something like versions.LessThan(version, "1.51") or set it as null with HealthSummary json:",omitempty"? But i assume from the @corhere response, it should be ignored by the client.
  2. Let me know if i should update to support nullable or keep it like this.

Thanks

Copy link
Contributor

@corhere corhere Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussing further with the other maintainers, we have reached the consensus that the HealthSummary should be omitted entirely from responses to requests with an older API version.

Suggested change
Health HealthSummary
Health *HealthSummary `json:",omitempty"`

Responses to requests with API version >= 1.51 should unconditionally include the HealthSummary. This includes containers with no health checks configured, or containers that are not running -- respond with Status=none.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated with new test case for version less than 1.51

@mdaffad mdaffad force-pushed the 50253-add-container-health-on-containers-list-api branch from e4fb1d1 to 012edf2 Compare July 9, 2025 10:18
@mdaffad
Copy link
Contributor Author

mdaffad commented Jul 9, 2025

Just want to ask. For the failed windows job https://github.com/moby/moby/actions/runs/16078201519/job/45626075880, is it a flake?

@vvoland
Copy link
Contributor

vvoland commented Jul 9, 2025

Yes, it's a flake and not related to this PR 👍🏻

Comment on lines 29 to 33
type HealthSummary struct {
Status HealthStatus
FailingStreak int
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type and fields could use some GoDoc / documentation here. We've not always done a good job at that, but it's an exported type, so having some docs is useful to whoever uses it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. I added comment on HealthSummary

@mdaffad mdaffad force-pushed the 50253-add-container-health-on-containers-list-api branch from 012edf2 to bc22a3f Compare July 10, 2025 09:15
@thompson-shaun thompson-shaun moved this from New to Complete in 🔦 Maintainer spotlight Jul 10, 2025
@mdaffad mdaffad force-pushed the 50253-add-container-health-on-containers-list-api branch 2 times, most recently from 0c7216d to 1017c1f Compare July 11, 2025 10:36
@mdaffad mdaffad force-pushed the 50253-add-container-health-on-containers-list-api branch from 1017c1f to 3b9b04a Compare July 11, 2025 15:05
@mdaffad mdaffad requested a review from vvoland July 11, 2025 15:05
Copy link
Contributor

@vvoland vvoland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall, just a linter failure that needs fixing 😅

Comment on lines 165 to 168
for _, container := range containers {
if (container.Health == nil && versions.LessThan(version, "1.51")) {
total++
} else if container.Health != nil && container.Health.Status == healthStatus && versions.GreaterThanOrEqualTo(version, "1.51"){
total++
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linter failure (https://github.com/moby/moby/actions/runs/16223267852/job/45939842246?pr=50281#step:6:71)

integration/container/list_test.go:166:1: File is not properly formatted (gofmt)
			if (container.Health == nil && versions.LessThan(version, "1.51")) {
^
integration/container/list_test.go:162:10: nilness: impossible condition: nil != nil (govet)
		if err != nil {
		       ^

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, looks like i missed to run gofmt -s -w. Updated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edited, re-run hack/validate/golangci-lint on dev container

@mdaffad mdaffad force-pushed the 50253-add-container-health-on-containers-list-api branch 2 times, most recently from a2c39b5 to 72bb671 Compare July 15, 2025 13:26
@mdaffad mdaffad requested a review from vvoland July 15, 2025 13:26
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quick "request changes" so that we don't forget to bump the API version (we can do the actual bump in a separate PR first)

apiVersion string
}{
{apiVersion: "1.50"},
{apiVersion: "1.51"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before we merge; I think API v1.51 already shipped, so we need a version bump for v29 and move these to 1.52; https://github.com/moby/moby/blob/v28.3.2/api/common.go#L5-L6

Copy link
Contributor Author

@mdaffad mdaffad Jul 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can i bump it to 1.52 on the different PR for this file https://github.com/moby/moby/blob/v28.3.2/api/common.go#L5-L6? Or we also need to bump on the other files at this commit
27f2e0e

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good catch!

I opened a PR to bump the API, you can rebase your PR once we get it in: #50418

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merged, you can rebase and adjust the API version check 👍🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks for the help! 🫡

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@mdaffad mdaffad force-pushed the 50253-add-container-health-on-containers-list-api branch from 72bb671 to 6507aa8 Compare July 16, 2025 13:20
@mdaffad mdaffad requested a review from thaJeztah July 16, 2025 13:22

// HealthSummary stores a summary of the container's healthcheck results.
type HealthSummary struct {
Status HealthStatus // Status is one of [NoHealthcheck], [Starting], [Healthy] or [Unhealthy].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: no need to enumerate the possible values in the doc comment; users are capable of following the link to HealthStatus in the go doc. And besides, the bracketed identifiers don't get rendered as links anyway, e.g.

Copy link
Contributor

@vvoland vvoland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@thompson-shaun
Copy link
Contributor

@thaJeztah - LGTY?

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Signed-off-by: Muhammad Daffa Dinaya <[email protected]>
Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah thaJeztah force-pushed the 50253-add-container-health-on-containers-list-api branch from 6507aa8 to 6e7a2c8 Compare July 21, 2025 20:57
@thaJeztah
Copy link
Member

DId a quick rebased after the API module PR was merged.

Comment on lines +5349 to +5371
Health:
type: "object"
description: |-
Summary of health status
Added in v1.52, before that version all container summary not include Health.
After this attribute introduced, it includes containers with no health checks configured,
or containers that are not running with none
properties:
Status:
type: "string"
description: |-
the health status of the container
enum:
- "none"
- "starting"
- "healthy"
- "unhealthy"
example: "healthy"
FailingStreak:
description: "FailingStreak is the number of consecutive failures"
type: "integer"
example: 0
Copy link
Contributor

@vvoland vvoland Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the changes were included again in the vendor. Is this expected? 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, because we don't use the code from master, we use the module (which gets vendored) 😅

@thaJeztah thaJeztah merged commit b20888a into moby:master Jul 21, 2025
208 of 209 checks passed
@mdaffad mdaffad deleted the 50253-add-container-health-on-containers-list-api branch July 22, 2025 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/api API impact/changelog kind/feature Functionality or other elements that the project doesn't currently have. Features are new and shiny status/4-merge

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Add container health to list containers API response for ease of monitoring

6 participants