kubernetes: kubelet /stats/summary returns Zero from CPU usageNanoCores stats when more than one caller
This started as a flakey test but was identified as related to changes to the way usageNanoCores are caulcated and used by kubelet. See https://github.com/kubernetes/kubernetes/issues/122092#issuecomment-1942699262
Which jobs are flaking?
ci-kubernetes-e2e-capz-master-windows-serial-slow
Which tests are flaking?
[sig-windows] [Feature:Windows] Cpu Resources [Serial] Container limits should not be exceeded after waiting 2 minutes flaking
Since when has it been flaking?
~ November 1st
Testgrid link
https://testgrid.k8s.io/sig-windows-signal#capz-windows-master-serial-slow
Reason for failure (if possible)
STEP: Ensuring pods are still running - test/e2e/windows/cpu_limits.go:56 @ 11/27/23 02:07:27.458 STEP: Ensuring cpu doesn’t exceed limit by >5% - test/e2e/windows/cpu_limits.go:76 @ 11/27/23 02:07:27.935 STEP: Gathering node summary stats - test/e2e/windows/cpu_limits.go:78 @ 11/27/23 02:07:27.935 Nov 27 02:07:28.181: INFO: Pod cpulimittest-eb76c25b-1fa9-41e7-a2c0-446bf6db30fb usage: 0 [FAILED] Pod cpu-resources-test-windows-9879/cpulimittest-eb76c25b-1fa9-41e7-a2c0-446bf6db30fb reported usage is 0, but it should be greater than 0 In [It] at: test/e2e/windows/cpu_limits.go:96 @ 11/27/23 02:07:28.182
Anything else we need to know?
example failure: https://prow.k8s.io/view/gs/kubernetes-jenkins/logs/ci-kubernetes-e2e-capz-master-windows-serial-slow/1728940368692514816
Relevant SIG(s)
/sig windows
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 19 (14 by maintainers)
Thanks for the discussion, It sounds like we should update Containerd to collect this periodically and returned the cached value. For now, we can hard code it to 10s.
The calculation of a rate within the kubelet/cadvisor was always somewhat imprecise. Since it is already part of the CRI API, I would just always use what comes from the CRI, and add let the container runtime decide the optimal caching strategy.
we currently have something like 4 proposals:
A point that came up in SIG node: since the CRI spec allows a CRI impl to specify a timestamp for when the cpu metrics were collected, it would be quite tricky for the kubelet to have any control over usage nano seconds. point 4 couldn’t work for the same reason it doesn’t now: kubelet can’t guarantee the period is long enough to have a non-zero usageNanoCores
I think the simplest solution is to have the collection period a hardcoded or configured option in the CRI. That would mean the period is regular and likely long enough to have meaningful data about usageNanoCores.
Note: I think doing point 3 could work as well, in tandem, to allow the kubelet to normalize the needed request to the CRI. This would also mean it wouldn’t request the data more frequently than it’s being generated. if the CRI is collecting and saving the stats every 10s, and kubelet requests every 5s, then the kubelet will be needlessly collecting half of the metrics it gathers. It would be up to the CRI or admin to choose a period that matches the kubelet’s collection period
@jsturtevant thanks for bringing this to today’s SIG Node meeting. @haircommander can you summarize what you shared at today’s meeting including the pros and cons for each options here? We will follow up with it. Thanks!
cc/ @logicalhan
A fourth option is kubelet could do the calculation of usage nano cores, instead of CRI. We could deprecate and (eventually) drop the field so they’re both not calculating.
Another another option is we could hardcode the update period in the CRI similar to how it’s done in the kubelet.
The downside for .1 will be a 10s usagenanocore data delay update, but on the other hand decouples the responsibility from the caller to manage an internal containerd cache, the outcome behavior is similar to the current situation.
I like this approach of the container stats grpc endpoint being cache read-only.
After debugging some in containerd (https://github.com/containerd/containerd/issues/9531) we figured out that this is caused because previously in kubelet there was only one caller that calculated and stored the
UsageNanoCoresas per https://github.com/kubernetes/kubernetes/blob/7ec1a89a509906dad9fd6a4635d7bfc157b47790/pkg/kubelet/stats/cri_stats_provider.go#L112Even though we have still have this flag on the kubelet side (https://github.com/kubernetes/kubernetes/blob/b27670dfbd9d34bd13b3f81439289aeef8084080/pkg/kubelet/stats/cri_stats_provider.go#L607-L611 ) it is no longer honored in the way it was intended (containerd will always calculate the value and cached the latest value for every call). This means that every time getcontainer stats is called, including eviction manager or some tools going directly to the summary endpoint the values will be recalculated and stored.
At first glance this looks like a containerd issue but containerd doesn’t have the information that kubelet has (the flag from eviction manager that says to update the value consistently at 10 seconds).
A few possibilities to solve this:
updatecache boolthat can be passedThis is a problem from Windows today but not for Linux since the value is backfilled by cAdvisor still. When Moving to the CRIOnly this would likely become an issue for Linux as well.
/cc @knabben @bobbypage @haircommander