Return an empty stats if "container not found"#34004
Conversation
4c77b79 to
c33a3f4
Compare
|
Oops, I close this pr by mistake and CI stopped @thaJeztah |
|
Looks like CI started again, and is green now 👍 |
daemon/stats/collector.go
Outdated
There was a problem hiding this comment.
Could we make the container not found error a typed error (like we do for notRunningErr)?
There was a problem hiding this comment.
Not introduced in this PR, but while looking at this code:
The double negative is a bit confusing here as well; would this be more readable (assuming a typed error for container not found was implemented;?
for _, pair := range pairs {
stats, err := s.supervisor.GetContainerStats(pair.container)
switch err.(type) {
case nil:
// FIXME: move to containerd on Linux (not Windows)
stats.CPUStats.SystemUsage = systemUsage
stats.CPUStats.OnlineCPUs = onlineCPUs
pair.publisher.Publish(*stats)
case notRunningErr, notFoundErr:
// publish empty stats containing only name and ID if not running or not found
pair.publisher.Publish(types.StatsJSON{
Name: pair.container.Name,
ID: pair.container.ID,
})
default:
logrus.Errorf("collecting stats for %s: %v", pair.container.ID, err)
}
}There was a problem hiding this comment.
@thaJeztah Thanks for your suggestion ❤️ I have updated the codes.
c33a3f4 to
911c002
Compare
daemon/daemon_unix.go
Outdated
There was a problem hiding this comment.
I guess this also needs to be done in the _windows version;
Lines 525 to 529 in 9d87e6e
911c002 to
dc8b314
Compare
daemon/stats/collector.go
Outdated
There was a problem hiding this comment.
Hm, looking at this again; this interface is not specific enough, as both daemon. errNotRunning, and daemon. errNotFound satisfy this interface; see https://play.golang.org/p/HtkBu1_QuM. If you make it more specific, it works though; https://play.golang.org/p/S7DzAuRITj
There was a problem hiding this comment.
@thaJeztah Tons of thanks for finding this ❤️
There was a problem hiding this comment.
@yummypeng you're welcome! I almost missed it as well
dc8b314 to
c567391
Compare
If we get "container not found" error from containerd, it's possibly because that this container has already been stopped. It will be ok to ignore this error and just return an empty stats. Signed-off-by: Yuanhong Peng <pengyuanhong@huawei.com>
c567391 to
4a6cbf9
Compare
|
janky failed but it seems not related to my PR: |
|
ping @thaJeztah @cpuguy83 |
|
LGTM ping @tiborvass |
|
ping @kolyshkin |
|
LGTM |
If we get "container not found" error from containerd, it's possibly because that this container has already been stopped. It will be ok to ignore this error and just return an empty stats. fix DTS2017062812251 related upstream PR: moby#34004 Signed-off-by: Yuanhong Peng <pengyuanhong@huawei.com>
Return an empty stats if "container not found" If we get "container not found" error from containerd, it's possibly because that this container has already been stopped. It will be ok to ignore this error and just return an empty stats. fix DTS2017062812251 related upstream PR: moby#34004 Signed-off-by: Yuanhong Peng <pengyuanhong@huawei.com> See merge request docker/docker!666
If we get "container not found" error from containerd, it's possibly
because that this container has already been stopped. It will be ok to
ignore this error and just return an empty stats.
Steps to reproduce:
It's a duplicate of #27772 which has already been closed by #28026, but #28026 is not a complete fix because if
docker stats --no-streamcomes faster afterdocker run, the container is still running when the code hits https://github.com/moby/moby/blob/master/daemon/stats.go#L35. Then I can see a lot of error logs from daemon:This pr will ignore this error and just return an empty stats. So that client will not hang forever.
after this pr:
Signed-off-by: Yuanhong Peng pengyuanhong@huawei.com
- A picture of a cute animal (not mandatory but encouraged)
