Skip to content

Kubelet Swap metrics are missing #131915

@yuanwang04

Description

@yuanwang04

What happened?

Kubelet's swap related metrics were introduced in #118865. However, these swap-related metrics are missing from /metrics/resource endpoint. Only node-level swap usage metrics are visible. The pod-level and container-level swap usage are available from /stats/summary endpoint, but no metrics are visible from /metrics/resource.

kubectl get --raw "/api/v1/nodes/<node>/proxy/metrics/resource" | grep -i swap
                    
# HELP node_swap_usage_bytes [ALPHA] Current swap usage of the node in bytes. Reported only on non-windows systems
# TYPE node_swap_usage_bytes gauge
node_swap_usage_bytes 3.4340864e+07 1747937814848

kubectl get --raw "/api/v1/nodes/<node>//proxy/stats/summary" | jq ".pods[] | select(.swap.swapUsageBytes > 0)"       

{
  "podRef": {
    "name": "oom-test-pod-stress-ng",
    "namespace": "default",
    "uid": "4bc5b67c-d750-47d4-a36a-5cec6190d752"
  },
  "containers": [
    {
      "name": "memory-eater",
      # ... omitted
      "swap": {
        "time": "2025-05-22T18:19:01Z",
        "swapAvailableBytes": 0,
        "swapUsageBytes": 33554432
      }
    }
  ],
  # omitted...
  "swap": {
    "time": "2025-05-22T18:18:50Z",
    "swapUsageBytes": 33554432
  }
}

What did you expect to happen?

Container-level swap usage container_swap_usage_bytes and pod-level swap usage pod_swap_usage_bytes metrics should be available from /metrics/resource endpoint.

How can we reproduce it (as minimally and precisely as possible)?

Create a node with swap enabled (https://kubernetes.io/blog/2025/03/25/swap-linux-improvements/#install-a-swap-enabled-cluster-with-kubeadm)

Get the swap metrics `kubectl get --raw "/api/v1/nodes//proxy/metrics/resource"

Anything else we need to know?

The node is using cadvisor CRI for resource metrics.

Also happened for kind: kubernetes-sigs/kind#3834

Kubernetes version

$ kubectl version
Client Version: v1.33.1
Kustomize Version: v5.6.0
Server Version: v1.33.1

$ kubelet --version
Kubernetes v1.33.1

Cloud provider

GKE: v1.33.1 Node: n4-standard-4

OS version

# On Linux:
$ cat /etc/os-release
NAME="Container-Optimized OS"
ID=cos
PRETTY_NAME="Container-Optimized OS from Google"
HOME_URL="https://cloud.google.com/container-optimized-os/docs"
BUG_REPORT_URL="https://cloud.google.com/container-optimized-os/docs/resources/support-policy#contact_us"
GOOGLE_METRICS_PRODUCT_ID=26
KERNEL_COMMIT_ID=ce1882ff887f9f692176e3431dc39f7f79bf8c72
GOOGLE_CRASH_ID=Lakitu
VERSION=121
VERSION_ID=121
BUILD_ID=18867.90.23

$ uname -a
Linux gke-yuanwangyw-test-dev-pool-4756ad32-v354 6.6.87+ #1 SMP Sat May 10 09:40:07 UTC 2025 x86_64 INTEL(R) XEON(R) PLATINUM 8581C CPU @ 2.10GHz GenuineIntel GNU/Linux

</details>


### Install tools

<details>

</details>


### Container runtime (CRI) and version (if applicable)

<details>
containerd://2.0.4
</details>


### Related plugins (CNI, CSI, ...) and versions (if applicable)

<details>

</details>

Metadata

Metadata

Assignees

Labels

kind/bugCategorizes issue or PR as related to a bug.priority/important-soonMust be staffed and worked on either currently, or very soon, ideally in time for the next release.sig/nodeCategorizes an issue or PR as relevant to SIG Node.triage/acceptedIndicates an issue or PR is ready to be actively worked on.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions