-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Add HealthStatus attribute on the docker ps command #50281
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
Add HealthStatus attribute on the docker ps command #50281
Conversation
e975835 to
7b24f12
Compare
|
Thanks! |
89a0f83 to
e4fb1d1
Compare
|
Updated |
api/types/container/container.go
Outdated
| NetworkMode string `json:",omitempty"` | ||
| Annotations map[string]string `json:",omitempty"` | ||
| } | ||
| Health HealthSummary |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the discussion:
- If i want to support the older API versions using
*HealthSummaryto allow nullable value, do i need declare something likeversions.LessThan(version, "1.51")or set it as null withHealthSummary json:",omitempty"? But i assume from the @corhere response, it should be ignored by the client. - Let me know if i should update to support nullable or keep it like this.
Thanks
There was a problem hiding this comment.
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.
| 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.
There was a problem hiding this comment.
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
e4fb1d1 to
012edf2
Compare
|
Just want to ask. For the failed windows job https://github.com/moby/moby/actions/runs/16078201519/job/45626075880, is it a flake? |
|
Yes, it's a flake and not related to this PR 👍🏻 |
| type HealthSummary struct { | ||
| Status HealthStatus | ||
| FailingStreak int | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
012edf2 to
bc22a3f
Compare
0c7216d to
1017c1f
Compare
1017c1f to
3b9b04a
Compare
vvoland
left a comment
There was a problem hiding this 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 😅
integration/container/list_test.go
Outdated
| 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++ | ||
| } | ||
| } |
There was a problem hiding this comment.
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 {
^
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
a2c39b5 to
72bb671
Compare
thaJeztah
left a comment
There was a problem hiding this 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"}, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 👍🏻
There was a problem hiding this comment.
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! 🫡
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
72bb671 to
6507aa8
Compare
|
|
||
| // HealthSummary stores a summary of the container's healthcheck results. | ||
| type HealthSummary struct { | ||
| Status HealthStatus // Status is one of [NoHealthcheck], [Starting], [Healthy] or [Unhealthy]. |
There was a problem hiding this comment.
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.
vvoland
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
|
@thaJeztah - LGTY? |
thaJeztah
left a comment
There was a problem hiding this 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]>
6507aa8 to
6e7a2c8
Compare
|
DId a quick rebased after the API module PR was merged. |
| 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 |
There was a problem hiding this comment.
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? 🤔
There was a problem hiding this comment.
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) 😅
healthto list containers API response for ease of monitoring #50253- What I did
Add HealthStatus attribute for dokcer ps command
- How I did it
- How to verify it
curl --unix-socket /var/run/docker.sock http://localhost/containers/json | jq- Human readable description for the release notes