Repository navigation
fix(monitor): avoid division by zero in CPU usage when no limit is found - #1633
Conversation
CPUUsage logged a failure from CPULimit and kept going with limit=0, so usage/0 became +Inf and was converted to int64, returning about -9.2e16. CPULimit also always queried the space namespace while usage uses the resolved one. Fall back to a limit of 1 (as CPULimit already does for v<=0) and pass the resolved namespace to CPULimit. Signed-off-by: Alex Castillo <alex.castillog33@gmail.com>
|
Add a CPU regression test for the workflow namespace
|
Use an evaluation request with SpaceNamespace=spaces and the workflow in namespace workflows, and assert both the usage and limit queries use workflows and that the ratio is computed from the returned limit. Signed-off-by: Alex Castillo <alex.castillog33@gmail.com>
|
Thanks for the review. Added This comment was drafted with Claude Code. |
|
Thanks for fixing the namespace lookup and adding the cross-namespace regression test. One question about the CPU chart: is the percentage meant to be relative to the configured CPU limit? If so, falling back to 1 core when the limit is unknown avoids division by zero, but a workload using 2 cores will show 100% after clamping, even when it has no configured limit. Could we distinguish a workload that is confirmed to have no CPU limit from one whose limit metric is unavailable? In the first case, show “No limit”; in the second, show “No data” for the percentage. If we still want to show CPU usage in either case, we can report it in cores. A missing metric alone shouldn't be treated as proof that the workload has no limit. |
|
Fair point, and you're right that the Telling "confirmed no limit" apart from "limit metric unavailable" needs a change to the This comment was drafted with Claude Code. |
|
Yes, let’s keep this PR scoped to the namespace fix and division-by-zero guard. Could you open a separate issue for the CPU chart contract and link it here? The follow-up should distinguish “no CPU limit configured” from “CPU limit metric unavailable,” and make sure CPU usage and its limit refer to the same container. We can settle the response shape and UI behavior there without changing the existing percentage contract in this PR. Thanks! |
|
Opened #1644 for the CPU chart contract (no-limit vs. metric-unavailable, same-container check), so this PR stays scoped to the namespace fix and the division-by-zero guard. This comment was drafted with Claude Code. |
What is this feature?
A fix for the CPU usage chart of the deploy monitor: when the CPU limit cannot be found, the returned values are no longer huge negative numbers.
Why do we need this feature?
CPUUsageincomponent/monitor.gocallsCPULimitand, on error, only logs a warning and continues withlimit == 0. The percentage is thenusage/0, which is+Inf/NaN; converting that toint64yieldsMinInt64on amd64, so the API returns about-9.2e16.CPULimitalso queriedm.k8sNameSpacewhileCPUUsageuses the namespace resolved byhasPermission, so for workloads outside the space namespace the limit was never found and this path was always taken.The change passes the resolved namespace to
CPULimitand falls back to a limit of 1 when no usable limit is returned (the same valueCPULimitalready returns forv <= 0).Who is this feature for?
Users looking at the CPU chart of a deploy/workflow in the monitor page.
Which issue(s) does this PR fix?:
No issue filed. It shows up for evaluation/finetune workflow pods (their namespace is
wf.Namespace, not the space namespace), and for any pod whose CPU limit metric is missing.Special notes for your reviewer:
Added
TestMonitor_CPUUsage_NoLimit(limit query returns no result): it failed before the change (value-9.22e16) and passes after.go test ./component -run TestMonitorpasses.This change was prepared with the help of an AI assistant (Claude Code), and the author is responsible for the change.
🤖 Generated with Claude Code