Repository navigation
fix(cluster-usage): parse nano/micro CPU quantities from metrics-server - #22
Conversation
parseQuantity handled milli, binary Ki..Ei and decimal k/M/G suffixes but had no branch for the decimal sub-units n (nano) and u (micro). metrics.k8s.io reports NodeMetrics.usage.cpu in nanocores (e.g. "2785315627n"), so the trailing n was ignored and the raw integer was returned as if it were cores. The Cluster Usage CPU Used value and bar inflated by ~1e9x in both the aggregate card and the per-node table. Add the n and u branches next to milli, and pin the parser plus the aggregate and per-node surfaces with nanocore fixtures. Assisted-By: Claude <noreply@anthropic.com> Signed-off-by: Aleksei Sviridkin <f@lex.la>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThis PR extends Kubernetes quantity parsing to recognize nanocore ( ChangesKubernetes Quantity Parsing Enhancement
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request adds support for parsing nano ('n') and micro ('u') decimal SI sub-units in Kubernetes resource quantities, which is particularly useful for handling nanocore CPU metrics reported by metrics-server. The changes include updates to the parseQuantity function and corresponding unit tests for aggregation, per-node rows, and quantity parsing. There are no review comments, and I have no additional feedback to provide.
Problem
The Cluster Usage admin page rendered CPU Used roughly a billion times too large (e.g.
3356778705against a CPU capacity of288), with the CPU usage bar permanently maxed out and red. Memory was correct — only CPU Used was wrong, in both the cluster-wide aggregate card and the per-node table.Cause
metrics.k8s.ioreportsNodeMetrics.usage.cpuin nanocores (e.g."2785315627n"≈ 2.79 cores).parseQuantityhandled them(milli), binaryKi–Ei, and decimalk/M/Gsuffixes, but had no branch for the decimal sub-unitsn(nano) andu(micro). A nanocore string fell through to the bare-number path and was returned as if it were whole cores, inflating the value by ~1e9×.Memory was unaffected because metrics-server reports it in
Ki, which was already handled. The other CPU columns are correct because Capacity/Allocatable come fromnode.status(plain cores) and Requested is summed from pod requests (m).Fix
Add the
n(÷1e9) andu(÷1e6) decimal sub-unit branches toparseQuantity. Bothaggregate.tsandper-node.tsroute CPU usage through this single function, so one change corrects both surfaces.Tests
The existing metrics fixtures used milli/plain CPU values, so the real nanocore path was never exercised. Added regression tests at three layers — the parser, the aggregate totals, and the per-node rows — each feeding a real nanocore value and asserting CPU comes out in cores while memory stays correct.
Summary by CodeRabbit
New Features
Tests