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

kubelet: expose OOM metrics #108004

Merged

Conversation

jonkerj
Copy link
Contributor

@jonkerj jonkerj commented Feb 8, 2022

What type of PR is this?

/kind feature

What this PR does / why we need it:

cAdvisor has code to expose the OOM metric container_oom_events_total since 0.40.0, which is included in kubelet since 1.23.0, but this was not activated in Kubelet coede.

Which issue(s) this PR fixes:

Fixes # (n/a, if needed, let me know and I'll raise a ticket)

Special notes for your reviewer:

My test environment is Talos 0.14.x, with k8s 1.23.3, so I tested it by:

  • cherry-picking this commit onto v1.23.3
  • make WHAT=cmd/kubelet from golang:1.17-buster
  • monkey-patch resulting binary into an image based on talos-systems/kubelet
  • Result is docker.io/jonkerj/talos-kubelet:0.0.2

The nodes running that specific Kubelet expose the metric, and I see the metric increasing if I go beyond memory resource limits (using stress-ng).

Does this PR introduce a user-facing change?

Add the metric `container_oom_events_total` to kubelet's cAdvisor metric endpoint.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

cAdvisor has code to expose OOM metrics since 0.40.0, but this was not
included in Kubelet so far. This commit enables it.

Signed-off-by: Jorik Jonker <jorik.jonker@eu.equinix.com>
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Feb 8, 2022
@k8s-ci-robot
Copy link
Contributor

Welcome @jonkerj!

It looks like this is your first PR to kubernetes/kubernetes 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kubernetes has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Feb 8, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @jonkerj. Thanks for your PR.

I'm waiting for a kubernetes 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.

@k8s-ci-robot k8s-ci-robot added the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Feb 8, 2022
@k8s-ci-robot k8s-ci-robot added area/kubelet sig/node Categorizes an issue or PR as relevant to SIG Node. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Feb 8, 2022
@wzshiming
Copy link
Member

/ok-to-test
Can we have a test that this works?

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 9, 2022
@jonkerj
Copy link
Contributor Author

jonkerj commented Feb 9, 2022

/test pull-kubernetes-e2e-gce-ubuntu-containerd

@jonkerj
Copy link
Contributor Author

jonkerj commented Feb 9, 2022

Can we have a test that this works?

I'll amend my PR to expand test/e2e_node/resource_metrics_test.go to include tests for the existence of this metric. I think testing for actual OOMs getting counted (ie, launch a well crafted pod eating memory) will be very convoluted and even error prone (it should use a well known image and it should consistently trip OOM after the init phase), so I will write a check for container_oom_events_total yielding 0 .. 1e6.

@jonkerj
Copy link
Contributor Author

jonkerj commented Feb 9, 2022

/test pull-kubernetes-node-e2e-containerd

@jonkerj
Copy link
Contributor Author

jonkerj commented Mar 7, 2022

@wzshiming is there anything else I can do?

@wzshiming
Copy link
Member

#79002
#84331

if includedMetrics.Has(container.OOMMetrics) {
c.containerMetrics = append(c.containerMetrics, containerMetric{
name: "container_oom_events_total",
help: "Count of out of memory events observed for the container",
valueType: prometheus.CounterValue,
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{{value: float64(s.OOMEvents), timestamp: s.Timestamp}}
},
})
}

I looked at PR of the metric that was added last time, and also looked at the context and it does work, look be fine.

/lgtm

/assign @klueska
for kubelet approval

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 8, 2022
Copy link
Member

@wzshiming wzshiming left a comment

Choose a reason for hiding this comment

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

Can we have a test in e2e?

@jonkerj
Copy link
Contributor Author

jonkerj commented Mar 11, 2022

Can we have a test in e2e?

I think testing for actual OOMs getting counted (ie, launch a well crafted pod eating memory) will be very convoluted and even error prone (it should use a well known image and it should consistently trip OOM after the init phase), so I included a test for metric presence in e2e_node before (see earlier comment).

If more is needed, I'd like to have suggestions on what to do, because I honestly would not know where to start.

Copy link
Member

@ehashman ehashman left a comment

Choose a reason for hiding this comment

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

/priority backlog
/triage accepted
/lgtm

/assign @dashpole
does this seem reasonable?

@k8s-ci-robot k8s-ci-robot added priority/backlog Higher priority than priority/awaiting-more-evidence. triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Mar 14, 2022
@ehashman ehashman moved this from Triage to Needs Approver in SIG Node PR Triage Mar 14, 2022
@dashpole
Copy link
Contributor

/lgtm

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jonkerj, mrunalp, wzshiming

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 14, 2022
@k8s-triage-robot
Copy link

The Kubernetes project has merge-blocking tests that are currently too flaky to consistently pass.

This bot retests PRs for certain kubernetes repos according to the following rules:

  • The PR does have any do-not-merge/* labels
  • The PR does not have the needs-ok-to-test label
  • The PR is mergeable (does not have a needs-rebase label)
  • The PR is approved (has cncf-cla: yes, lgtm, approved labels)
  • The PR is failing tests required for merge

You can:

/retest

@k8s-ci-robot k8s-ci-robot merged commit 7858fc9 into kubernetes:master Mar 15, 2022
SIG Node PR Triage automation moved this from Needs Approver to Done Mar 15, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.24 milestone Mar 15, 2022
@krmayankk
Copy link

i think cadvisor exposes a ton of metrics, not all are exposed through kubelet. should we in future consider exposing cadvisor metrics using a config file passed to kubelet ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/kubelet cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/backlog Higher priority than priority/awaiting-more-evidence. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/node Categorizes an issue or PR as relevant to SIG Node. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Development

Successfully merging this pull request may close these issues.

None yet

9 participants