-
Notifications
You must be signed in to change notification settings - Fork 18.7k
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
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 👍 |
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.
Left some suggestions :)
daemon/stats/collector.go
Outdated
// 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. | ||
if _, ok := err.(notRunningErr); !ok && !strings.Contains(err.Error(), "container not found") { |
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.
Could we make the container not found
error a typed error (like we do for notRunningErr
)?
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thaJeztah Thanks for your suggestion ❤️ I have updated the codes.
c33a3f4
to
911c002
Compare
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.
left one more comment
also /cc @cpuguy83 for review
@@ -1165,6 +1165,9 @@ func (daemon *Daemon) stats(c *container.Container) (*types.StatsJSON, error) { | |||
} | |||
stats, err := daemon.containerd.Stats(c.ID) | |||
if err != nil { | |||
if strings.Contains(err.Error(), "container not found") { |
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.
I guess this also needs to be done in the _windows
version;
Lines 525 to 529 in 9d87e6e
// Obtain the stats from HCS via libcontainerd | |
stats, err := daemon.containerd.Stats(c.ID) | |
if err != nil { | |
return nil, err | |
} |
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 😉 @thaJeztah
911c002
to
dc8b314
Compare
daemon/stats/collector.go
Outdated
|
||
type notFoundErr interface { | ||
error | ||
} |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thaJeztah Tons of thanks for finding this ❤️
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.
@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 <[email protected]>
c567391
to
4a6cbf9
Compare
janky failed but it seems not related to my PR:
|
ping @thaJeztah @cpuguy83 |
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
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 <[email protected]>
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 <[email protected]> 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-stream
comes 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 [email protected]
- A picture of a cute animal (not mandatory but encouraged)
