-
Notifications
You must be signed in to change notification settings - Fork 2.5k
support disk usage metrics for containerd factory #3502
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
base: master
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -413,6 +413,8 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | |
| 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= | ||
|
Collaborator
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. hmm, we really should not be creating circular dependencies!
Author
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. 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?
Collaborator
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. correct! it took us a few years to straighten out the dependencies. |
||
| k8s.io/cri-api v0.34.3/go.mod h1:4qVUjidMg7/Z9YGZpqIDygbkPWkg3mkS1PvOx/kpHTE= | ||
| k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= | ||
| k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= | ||
| k8s.io/utils v0.0.0-20250502105355-0f33e8f1c979 h1:jgJW5IePPXLGB8e/1wvd0Ich9QE97RvvF3a8J3fP/Lg= | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,9 +16,12 @@ package containerd | |
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "net" | ||
| "path" | ||
| "strings" | ||
| "sync" | ||
| "time" | ||
|
|
||
|
|
@@ -31,6 +34,9 @@ import ( | |
| "google.golang.org/grpc/backoff" | ||
| "google.golang.org/grpc/credentials/insecure" | ||
| emptypb "google.golang.org/protobuf/types/known/emptypb" | ||
| runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1" | ||
|
|
||
| "github.com/google/cadvisor/container/containerd/config" | ||
|
|
||
| "github.com/google/cadvisor/container/containerd/containers" | ||
| "github.com/google/cadvisor/container/containerd/pkg/dialer" | ||
|
|
@@ -40,6 +46,7 @@ type client struct { | |
| containerService containersapi.ContainersClient | ||
| taskService tasksapi.TasksClient | ||
| versionService versionapi.VersionClient | ||
| runtimeService runtimeapi.RuntimeServiceClient | ||
| } | ||
|
|
||
| type ContainerdClient interface { | ||
|
|
@@ -48,12 +55,18 @@ type ContainerdClient interface { | |
| LoadTaskProcess(ctx context.Context, id string) (*tasktypes.Process, error) | ||
| TaskExitStatus(ctx context.Context, id string) (uint32, error) | ||
| Version(ctx context.Context) (string, error) | ||
| RootfsDir(ctx context.Context) (string, error) | ||
| } | ||
|
|
||
| var ( | ||
| ErrTaskIsInUnknownState = errors.New("containerd task is in unknown state") // used when process reported in containerd task is in Unknown State | ||
| ) | ||
|
|
||
| var ( | ||
| statePlugin = "io.containerd.grpc.v1.cri" | ||
| taskRuntimePlugin = "io.containerd.runtime.v2.task" | ||
| ) | ||
|
|
||
| var once sync.Once | ||
| var ctrdClient ContainerdClient = nil | ||
| var ctrdClientErr error = nil | ||
|
|
@@ -106,6 +119,7 @@ func Client(address, namespace string) (ContainerdClient, error) { | |
| containerService: containersapi.NewContainersClient(conn), | ||
| taskService: tasksapi.NewTasksClient(conn), | ||
| versionService: versionapi.NewVersionClient(conn), | ||
| runtimeService: runtimeapi.NewRuntimeServiceClient(conn), | ||
| } | ||
| }) | ||
| return ctrdClient, ctrdClientErr | ||
|
|
@@ -166,6 +180,19 @@ func (c *client) Version(ctx context.Context) (string, error) { | |
| return response.Version, nil | ||
| } | ||
|
|
||
| func (c *client) RootfsDir(ctx context.Context) (string, error) { | ||
| r, err := c.runtimeService.Status(ctx, &runtimeapi.StatusRequest{Verbose: true}) | ||
|
Collaborator
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. please find another way. we can't be creating circular dependencies |
||
| if err != nil { | ||
| return "", err | ||
| } | ||
| configStr := r.Info["config"] | ||
| config := config.Config{} | ||
| if err := json.Unmarshal([]byte(configStr), &config); err != nil { | ||
| return "", err | ||
| } | ||
| return path.Join(strings.TrimSuffix(config.StateDir, statePlugin), taskRuntimePlugin), nil | ||
| } | ||
|
|
||
| func containerFromProto(containerpb *containersapi.Container) *containers.Container { | ||
| var runtime containers.RuntimeInfo | ||
| // TODO: is nil check required for containerpb | ||
|
|
||
Large diffs are not rendered by default.
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.
please remove the extra
go mod tidy