Skip to content

Commit 8ae4550

Browse files
qiutongsbobbypage
authored andcommitted
address comments
1 parent 31eeb3b commit 8ae4550

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

container/common/fsHandler.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type FsUsage struct {
4040
type FsUsageProvider interface {
4141
// Usage returns the fs usage
4242
Usage() (*FsUsage, error)
43-
// Targets returns where the fs usage metric is collected,it maybe a directory ,a file or some
43+
// Targets returns where the fs usage metric is collected,it maybe a directory, a file or some
4444
// information about the snapshotter(for containerd)
4545
Targets() []string
4646
}
@@ -139,8 +139,9 @@ func (fh *realFsHandler) Usage() FsUsage {
139139
}
140140

141141
type fsUsageProvider struct {
142-
fsInfo fs.FsInfo
143-
rootFs string
142+
fsInfo fs.FsInfo
143+
rootFs string
144+
// The directory consumed by the container but outside rootFs, e.g. directory of saving logs
144145
extraDir string
145146
}
146147

@@ -184,7 +185,7 @@ func (f *fsUsageProvider) Usage() (*FsUsage, error) {
184185

185186
// Combine errors into a single error to return
186187
if rootErr != nil || extraErr != nil {
187-
return nil, fmt.Errorf("rootDiskErr: %v, extraDiskErr: %v", rootErr, extraErr)
188+
return nil, fmt.Errorf("failed to obtain filesystem usage; rootDiskErr: %v, extraDiskErr: %v", rootErr, extraErr)
188189
}
189190

190191
return usage, nil

container/containerd/handler.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import (
2222
"time"
2323

2424
"github.com/containerd/containerd/errdefs"
25+
criapi "github.com/google/cadvisor/cri-api/pkg/apis/runtime/v1alpha2"
2526
"golang.org/x/net/context"
26-
criapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
2727

2828
"github.com/google/cadvisor/container"
2929
"github.com/google/cadvisor/container/common"
@@ -176,15 +176,17 @@ func newContainerdContainerHandler(
176176
if includedMetrics.Has(container.DiskUsageMetrics) && cntr.Labels["io.cri-containerd.kind"] != "sandbox" {
177177
mounts, err := client.SnapshotMounts(ctx, cntr.Snapshotter, cntr.SnapshotKey)
178178
if err != nil {
179-
return nil, err
179+
return nil, fmt.Errorf("failed to obtain containerd snapshot mounts for disk usage metrics: %v", err)
180180
}
181181

182-
// Default to top directory if the specific upperdir snapshot is not found
182+
// Default to top directory
183183
snapshotDir := "/var/lib/containerd"
184-
// Example: upperdir=/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/5001/fs
185-
if len(mounts) > 0 {
184+
// TODO: only overlay snapshotters is handled as of now.
185+
// Note: overlay returns single mount. https://github.com/containerd/containerd/blob/main/snapshots/overlay/overlay.go
186+
if len(mounts) > 0 && mounts[0].Type == "overlay" {
186187
for _, option := range mounts[0].Options {
187-
if strings.Index(option, "upperdir=") == 0 {
188+
// Example: upperdir=/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/5001/fs
189+
if strings.HasPrefix(option, "upperdir=") {
188190
snapshotDir = option[len("upperdir="):]
189191
break
190192
}

0 commit comments

Comments
 (0)