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
Reduce the number of expensive calls in the Windows stats queries for dockershim #104287
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,6 @@ limitations under the License. | |
package dockershim | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"time" | ||
|
||
|
@@ -29,26 +28,21 @@ import ( | |
"k8s.io/klog/v2" | ||
) | ||
|
||
func (ds *dockerService) getContainerStats(containerID string) (*runtimeapi.ContainerStats, error) { | ||
info, err := ds.client.Info() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
hcsshimContainer, err := hcsshim.OpenContainer(containerID) | ||
func (ds *dockerService) getContainerStats(c *runtimeapi.Container) (*runtimeapi.ContainerStats, error) { | ||
hcsshimContainer, err := hcsshim.OpenContainer(c.Id) | ||
if err != nil { | ||
// As we moved from using Docker stats to hcsshim directly, we may query HCS with already exited container IDs. | ||
// That will typically happen with init-containers in Exited state. Docker still knows about them but the HCS does not. | ||
// As we don't want to block stats retrieval for other containers, we only log errors. | ||
if !hcsshim.IsNotExist(err) && !hcsshim.IsAlreadyStopped(err) { | ||
klog.V(4).InfoS("Error opening container (stats will be missing)", "containerID", containerID, "err", err) | ||
klog.V(4).InfoS("Error opening container (stats will be missing)", "containerID", c.Id, "err", err) | ||
} | ||
return nil, nil | ||
} | ||
defer func() { | ||
closeErr := hcsshimContainer.Close() | ||
if closeErr != nil { | ||
klog.ErrorS(closeErr, "Error closing container", "containerID", containerID) | ||
klog.ErrorS(closeErr, "Error closing container", "containerID", c.Id) | ||
} | ||
}() | ||
|
||
|
@@ -61,30 +55,19 @@ func (ds *dockerService) getContainerStats(containerID string) (*runtimeapi.Cont | |
// These hcs errors do not have helpers exposed in public package so need to query for the known codes | ||
// https://github.com/microsoft/hcsshim/blob/master/internal/hcs/errors.go | ||
// PR to expose helpers in hcsshim: https://github.com/microsoft/hcsshim/pull/933 | ||
klog.V(4).InfoS("Container is not in a state that stats can be accessed. This occurs when the container is created but not started.", "containerID", containerID, "err", err) | ||
klog.V(4).InfoS("Container is not in a state that stats can be accessed. This occurs when the container is created but not started.", "containerID", c.Id, "err", err) | ||
return nil, nil | ||
} | ||
return nil, err | ||
} | ||
|
||
containerJSON, err := ds.client.InspectContainerWithSize(containerID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
statusResp, err := ds.ContainerStatus(context.Background(), &runtimeapi.ContainerStatusRequest{ContainerId: containerID}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
status := statusResp.GetStatus() | ||
|
||
timestamp := time.Now().UnixNano() | ||
containerStats := &runtimeapi.ContainerStats{ | ||
Attributes: &runtimeapi.ContainerAttributes{ | ||
Id: containerID, | ||
Metadata: status.Metadata, | ||
Labels: status.Labels, | ||
Annotations: status.Annotations, | ||
Id: c.Id, | ||
Metadata: c.Metadata, | ||
Labels: c.Labels, | ||
Annotations: c.Annotations, | ||
}, | ||
Cpu: &runtimeapi.CpuUsage{ | ||
Timestamp: timestamp, | ||
|
@@ -97,8 +80,11 @@ func (ds *dockerService) getContainerStats(containerID string) (*runtimeapi.Cont | |
}, | ||
WritableLayer: &runtimeapi.FilesystemUsage{ | ||
Timestamp: timestamp, | ||
FsId: &runtimeapi.FilesystemIdentifier{Mountpoint: info.DockerRootDir}, | ||
UsedBytes: &runtimeapi.UInt64Value{Value: uint64(*containerJSON.SizeRw)}, | ||
FsId: &runtimeapi.FilesystemIdentifier{Mountpoint: ds.dockerRootDir}, | ||
// used bytes from image are not implemented on Windows | ||
// don't query for it since it is expensive to call docker over named pipe | ||
// https://github.com/moby/moby/blob/1ba54a5fd0ba293db3bea46cd67604b593f2048b/daemon/images/image_windows.go#L11-L14 | ||
UsedBytes: &runtimeapi.UInt64Value{Value: 0}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you have a sense of how much of the perf improvements you see on Windows are due to info from the docker api vs how much is due to not querying for this data on Windows? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not this specifically but I added a comment here with some details #104287 (comment) |
||
}, | ||
} | ||
return containerStats, 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.
this is a change of behavior. If docker is slow to respond, kubelet may fail to start now? I don't think it's a critical change, just leaving this comment for other reviewers to pay attention.
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.
agreed, I called this out here: #104287 (comment). There are other calls to the docker during this time that could cause a failure, so we should be confident that docker is 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.
yep, I see it now =) Sorry missed it