Skip to content
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

Ignore NotFound errors when getting task stats #928

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cmd/containerd-shim-runhcs-v1/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import (

"github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/options"
"github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/stats"
"github.com/Microsoft/hcsshim/internal/gcs"
"github.com/Microsoft/hcsshim/internal/hcs"
"github.com/Microsoft/hcsshim/internal/shimdiag"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/runtime/v2/task"
specs "github.com/opencontainers/runtime-spec/specs-go"
)
Expand Down Expand Up @@ -93,3 +96,12 @@ type shimTask interface {
// metrics on the UVM may be returned as well.
Stats(ctx context.Context) (*stats.Statistics, error)
}

// isStatsNotFound returns true if the err corresponds to a scenario
// where statistics cannot be retrieved or found
func isStatsNotFound(err error) bool {
return errdefs.IsNotFound(err) ||
hcs.IsNotExist(err) ||
hcs.IsOperationInvalidState(err) ||
gcs.IsNotExist(err)
}
15 changes: 8 additions & 7 deletions cmd/containerd-shim-runhcs-v1/task_hcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,19 +674,20 @@ func hcsPropertiesToWindowsStats(props *hcsschema.Properties) *stats.Statistics_

func (ht *hcsTask) Stats(ctx context.Context) (*stats.Statistics, error) {
s := &stats.Statistics{}

props, err := ht.c.PropertiesV2(ctx, hcsschema.PTStatistics)
if err != nil {
if err != nil && !isStatsNotFound(err) {
return nil, err
}
if ht.isWCOW {
s.Container = hcsPropertiesToWindowsStats(props)
} else {
s.Container = &stats.Statistics_Linux{Linux: props.Metrics}
if props != nil {
dcantah marked this conversation as resolved.
Show resolved Hide resolved
if ht.isWCOW {
s.Container = hcsPropertiesToWindowsStats(props)
} else {
s.Container = &stats.Statistics_Linux{Linux: props.Metrics}
}
}
if ht.ownsHost && ht.host != nil {
vmStats, err := ht.host.Stats(ctx)
if err != nil {
if err != nil && !isStatsNotFound(err) {
return nil, err
}
s.VM = vmStats
Expand Down
4 changes: 2 additions & 2 deletions cmd/containerd-shim-runhcs-v1/task_wcow_podsandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,11 @@ func (wpst *wcowPodSandboxTask) Share(ctx context.Context, req *shimdiag.ShareRe
}

func (wpst *wcowPodSandboxTask) Stats(ctx context.Context) (*stats.Statistics, error) {
stats := &stats.Statistics{}
vmStats, err := wpst.host.Stats(ctx)
if err != nil {
if err != nil && !isStatsNotFound(err) {
return nil, err
}
stats := &stats.Statistics{}
stats.VM = vmStats
return stats, nil
}
9 changes: 9 additions & 0 deletions internal/gcs/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ func (err *rpcError) Error() string {
return "guest RPC failure: " + msg
}

// IsNotExist is a helper function to determine if the inner rpc error is Not Exist
func IsNotExist(err error) bool {
switch rerr := err.(type) {
case *rpcError:
return uint32(rerr.result) == hrComputeSystemDoesNotExist
}
return false
}

// Err returns the RPC's result. This may be a transport error or an error from
// the message response.
func (call *rpc) Err() error {
Expand Down