Skip to content

Commit

Permalink
Count the size of logs towards TotalUsageBytes
Browse files Browse the repository at this point in the history
  • Loading branch information
qiutongs committed Sep 22, 2021
1 parent aaa0aea commit 9811dc8
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions container/containerd/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/containerd/containerd/errdefs"
"golang.org/x/net/context"
criapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"

"github.com/google/cadvisor/container"
"github.com/google/cadvisor/container/common"
Expand All @@ -36,6 +37,8 @@ type fsUsageProvider struct {
ctx context.Context
containerID string
client ContainerdClient
fsInfo fs.FsInfo
logPath string
}

type containerdContainerHandler struct {
Expand Down Expand Up @@ -129,8 +132,9 @@ func newContainerdContainerHandler(
// Special container name for sandbox(pause)
// It is defined in https://github.com/kubernetes/kubernetes/blob/master/pkg/kubelet/dockershim/naming.go#L50-L52
containerName := "POD"
var status *criapi.ContainerStatus
if cntr.Labels["io.cri-containerd.kind"] != "sandbox" {
status, err := client.ContainerStatus(ctx, id)
status, err = client.ContainerStatus(ctx, id)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -220,6 +224,9 @@ func newContainerdContainerHandler(
ctx: ctx,
client: client,
containerID: id,
// Path of logs, e.g. /var/log/pods/XXX
logPath: status.LogPath,
fsInfo: fsInfo,
})
}

Expand Down Expand Up @@ -370,9 +377,17 @@ func (f *fsUsageProvider) Usage() (*common.FsUsage, error) {
if err != nil {
return nil, err
}
var logUsedBytes uint64
if f.logPath != "" {
logUsage, err := f.fsInfo.GetDirUsage(f.logPath)
if err != nil {
return nil, err
}
logUsedBytes = logUsage.Bytes
}
return &common.FsUsage{
BaseUsageBytes: stats.WritableLayer.UsedBytes.Value,
TotalUsageBytes: stats.WritableLayer.UsedBytes.Value,
TotalUsageBytes: stats.WritableLayer.UsedBytes.Value + logUsedBytes,
InodeUsage: stats.WritableLayer.InodesUsed.Value,
}, nil
}
Expand Down

0 comments on commit 9811dc8

Please sign in to comment.