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

Fix the first alias of container reference #2931

Merged
merged 2 commits into from
Aug 31, 2021

Conversation

qiutongs
Copy link
Contributor

@qiutongs qiutongs commented Aug 27, 2021

Signed-off-by: Qiutong Song songqt01@gmail.com

Overview

Previous PR: #2919

In Prometheus and Statsd, they use the first container alias as the "container name" in the output metrics. However, docker handler and containerd handler have different logics for the alias.

In docker, it is k8s_<container-name>_<pod-name>_<namespace>_<pod-uid>_<restart-count> but it is in containerd.

This PR is to make containerd behave the same way as docker.

Notes

  • For sandbox container (pause), the restart is hardcoded to "0"

Testing

$ go test github.com/google/cadvisor/container/containerd
$ make test

Query Prometheus endpont: localhost:8080/metrics

name="k8s_nginx-pod_nginx-pod_default_3842c335-15cc-4b1a-8aa2-112a1eac3f82_0"
name="k8s_POD_coredns-755cd654d4-pg5wm_kube-system_5fc14a57-9ca9-4237-9e05-38802c229dbd_0"

Kill the container process (to force restarted) and re-query

name="k8s_nginx-pod_nginx-pod_default_3842c335-15cc-4b1a-8aa2-112a1eac3f82_1"
name="k8s_POD_coredns-755cd654d4-pg5wm_kube-system_5fc14a57-9ca9-4237-9e05-38802c229dbd_0"

Signed-off-by: Qiutong Song <songqt01@gmail.com>
@k8s-ci-robot
Copy link
Collaborator

Hi @qiutongs. 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.

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.

@@ -112,11 +112,31 @@ func newContainerdContainerHandler(
rootfs = "/rootfs"
}

var restart uint32 = 0
containerName := "POD"
Copy link
Collaborator

Choose a reason for hiding this comment

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

For clarity, maybe move this into a constant and leave a comment that POD is container name for sandbox container and it is defined here: https://github.com/kubernetes/kubernetes/blob/master/pkg/kubelet/dockershim/naming.go#L50-L52

@@ -112,11 +112,31 @@ func newContainerdContainerHandler(
rootfs = "/rootfs"
}

var restart uint32 = 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: you can just do var restart uint32 and use the default value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for reminding. I would just explicitly set to 0

if err != nil {
return nil, err
}
restart = status.Metadata.Attempt
Copy link
Collaborator

Choose a reason for hiding this comment

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

leave a comment that sandbox container restart is not tracked as you mentioned in the PR description

For sandbox container (pause), the restart is hardcoded to "0"

@bobbypage
Copy link
Collaborator

LGTM, thanks!

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.

3 participants