Skip to content

support disk usage metrics for containerd factory#3502

Open
chengjoey wants to merge 1 commit intogoogle:masterfrom
chengjoey:feat/containerd-disk-usage
Open

support disk usage metrics for containerd factory#3502
chengjoey wants to merge 1 commit intogoogle:masterfrom
chengjoey:feat/containerd-disk-usage

Conversation

@chengjoey
Copy link
Copy Markdown

query rootfs dir from contianerd status and get disk usage stat by rootfs dir /run/containerd/io.containerd.runtime.v2.task/${contianerid}/rootfs

set hasFileSystem to true for containerd when included disk usage metrics
added common fs handler for container rootfs

@k8s-ci-robot
Copy link
Copy Markdown
Collaborator

Hi @chengjoey. Thanks for your PR.

I'm waiting for a google member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@chengjoey
Copy link
Copy Markdown
Author

Comment thread container/docker/handler_test.go Outdated

var fsStats info.FsStats
addDiskStats(fileSystems, nil, &fsStats)
fs.AddDiskStats(fileSystems, nil, &fsStats)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test should be moved to fs module.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done~

Comment thread container/docker/handler_test.go Outdated

// Act
addDiskStats(fileSystems, &fsInfo, &fsStats)
fs.AddDiskStats(fileSystems, &fsInfo, &fsStats)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done~

Comment thread container/containerd/client.go Outdated
}
configStr := r.Info["config"]
config := make(map[string]interface{})
if err := json.Unmarshal([]byte(configStr), &config); err != nil {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you unmarshal config into a struct? It will be easier to grasp what values are interesting.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original definition of config is here

I extracted the struct in config.go to container/containerd/config

@iwankgb
Copy link
Copy Markdown
Collaborator

iwankgb commented Mar 31, 2024

/ok-to-test

@chengjoey
Copy link
Copy Markdown
Author

/retest

@silence8013
Copy link
Copy Markdown

Will this commit continue? Looking forward to it~

@duanhongyi
Copy link
Copy Markdown

I am looking forward to this feature merging.

@jianxiaoguo
Copy link
Copy Markdown

I eagerly anticipate the completion of this feature.

@EamonZhang
Copy link
Copy Markdown

This feature is particularly important and I'm looking forward to it

@wsszh
Copy link
Copy Markdown

wsszh commented May 24, 2024

Hi, I think the disk usage of a container should include the usage of log files in /var/log/pods.

@chengjoey
Copy link
Copy Markdown
Author

Hi, I think the disk usage of a container should include the usage of log files in /var/log/pods.

hi @wsszh , The disk usage calculation of contianerd is similar to that of docker and podman. I think that several container factories currently do not include /var/log/pods in the calculation. This may be because cadvisor is more about container-level calculations rather than pods. It is also difficult to know which directory should be calculated because it is not fixed in /var/log/pods. although I think it should be calculated, the specific directory of the log cannot be obtained from the info interface of cri.

@chengjoey
Copy link
Copy Markdown
Author

Hi, I think the disk usage of a container should include the usage of log files in /var/log/pods.

if a container should include the usage of log files, I would like to submit another PR to modify the container runtimes such as podman, docker, containerd, etc. This PR only does usage metric for containerd

@chengjoey chengjoey force-pushed the feat/containerd-disk-usage branch 7 times, most recently from 1b85ff8 to 9e7a939 Compare August 14, 2024 15:13
@kxbin
Copy link
Copy Markdown

kxbin commented Dec 19, 2024

great work,Hope to speed up to merge in master

@melikeiremguler
Copy link
Copy Markdown

melikeiremguler commented Dec 30, 2024

Hi, will this pull request solve this problem ?

@chengjoey
Copy link
Copy Markdown
Author

Hi, will this pull request solve this problem ?

@melikeiremguler , Yes, this PR is to solve the issue of 2785.

@gigilee
Copy link
Copy Markdown

gigilee commented Mar 24, 2025

Is this PR going to be merged?

@Imlosing
Copy link
Copy Markdown

Looking forward to the early merge.

@Imlosing
Copy link
Copy Markdown

Looking forward to the early merge.

Or is there any alternative solution now?

@kam1kaze
Copy link
Copy Markdown

kam1kaze commented May 5, 2025

@iwankgb How could we speed up merge process of this code? We are using it on production and it works perfect.

@Imlosing
Copy link
Copy Markdown

@iwankgb How could we speed up merge process of this code? We are using it on production and it works perfect.

@kam1kaze I also merged this PR and tried to use it, but I found that the actual value collected was greater than the writable layer capacity. Have you encountered this problem?

@kamikaze
Copy link
Copy Markdown

please

@desert3agle
Copy link
Copy Markdown

is it still in work or has been abandoned?

@ttc0419
Copy link
Copy Markdown

ttc0419 commented Nov 11, 2025

@iwankgb could you take a look again?

@till
Copy link
Copy Markdown

till commented Dec 14, 2025

@dims maybe you can help review this? And re-open the ticket

@dims
Copy link
Copy Markdown
Collaborator

dims commented Dec 14, 2025

@till if/when it gets rebased/updated the PR author can reopen this PR

query rootfs dir from contianerd status and get disk usage stat by rootfs dir `/run/containerd/io.containerd.runtime.v2.task/${contianerid}/rootfs`

Signed-off-by: joey <zchengjoey@gmail.com>
@chengjoey chengjoey force-pushed the feat/containerd-disk-usage branch from 9e7a939 to 578c27f Compare December 15, 2025 02:30
Comment thread build/build.sh
# Since github.com/google/cadvisor/cmd is a submodule, we must build from inside that directory
pushd cmd > /dev/null
go build ${GO_FLAGS} -ldflags "${ldflags}" -o "${output_file}" "${repo_path}/cmd"
go mod tidy && go build ${GO_FLAGS} -ldflags "${ldflags}" -o "${output_file}" "${repo_path}/cmd"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove the extra go mod tidy

Comment thread cmd/go.sum
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.0.2 h1:kG1BFyqVHuQoVQiR1bWGnfz/fmHvvuiSPIV7rvl360E=
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
k8s.io/cri-api v0.34.3 h1:zFdQSHZuQlQXesw9ncjQRUyDpvLng/84Q4qLKd8x2zE=
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, we really should not be creating circular dependencies!

Copy link
Copy Markdown
Author

@chengjoey chengjoey Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This circular dependency refers to the fact that k8s(kubelet) already depends on cAdvisor, so should cAdvisor not depend on the packages in the k8s repository?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct! it took us a few years to straighten out the dependencies.

}

func (c *client) RootfsDir(ctx context.Context) (string, error) {
r, err := c.runtimeService.Status(ctx, &runtimeapi.StatusRequest{Verbose: true})
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please find another way. we can't be creating circular dependencies

@github-actions
Copy link
Copy Markdown

This PR is stale because it has been open 90 days with no activity. This PR will be closed in 30 days unless new comments are made or the stale label is removed. To skip these checks, apply the "lifecycle/frozen" label.

@github-actions github-actions Bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Mar 16, 2026
@mindw
Copy link
Copy Markdown

mindw commented Apr 5, 2026

still relevant.

@github-actions github-actions Bot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.