Skip to content
This repository was archived by the owner on Jun 26, 2026. It is now read-only.

fix(cluster-usage): parse nano/micro CPU quantities from metrics-server - #22

Merged
Aleksei Sviridkin (lexfrei) merged 1 commit into
mainfrom
fix/cpu-usage-nanocore-parse
Jun 1, 2026
Merged

Aleksei Sviridkin (lexfrei) merged 1 commit into
mainfrom
fix/cpu-usage-nanocore-parse

Conversation

@lexfrei

@lexfrei Aleksei Sviridkin (lexfrei) commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The Cluster Usage admin page rendered CPU Used roughly a billion times too large (e.g. 3356778705 against a CPU capacity of 288), 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.io reports NodeMetrics.usage.cpu in nanocores (e.g. "2785315627n" ≈ 2.79 cores). parseQuantity handled the m (milli), binary Ki–Ei, and decimal k/M/G suffixes, but had no branch for the decimal sub-units n (nano) and u (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 from node.status (plain cores) and Requested is summed from pod requests (m).

Fix

Add the n (÷1e9) and u (÷1e6) decimal sub-unit branches to parseQuantity. Both aggregate.ts and per-node.ts route 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

    • Added support for nanocore (n) and micro (u) CPU metric suffixes for accurate cluster resource calculations.
  • Tests

    • Added test coverage validating CPU and memory metric conversions.

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>
@coderabbitai

coderabbitai Bot commented Jun 1, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: be39f685-3907-429f-b262-7e72c70d19ae

📥 Commits

Reviewing files that changed from the base of the PR and between 4570d44 and 07223b1.

📒 Files selected for processing (4)
  • apps/console/src/lib/cluster-usage/aggregate.test.ts
  • apps/console/src/lib/cluster-usage/per-node.test.ts
  • apps/console/src/lib/k8s-quantity.test.ts
  • apps/console/src/lib/k8s-quantity.ts

📝 Walkthrough

Walkthrough

This PR extends Kubernetes quantity parsing to recognize nanocore (n) and micro (u) CPU metric suffixes emitted by metrics-server. The parseQuantity function now divides nanocore values by 1e9 and micro values by 1e6 to convert them to numeric base units. Unit tests and integration tests in aggregate and per-node computation layers validate the end-to-end conversion.

Changes

Kubernetes Quantity Parsing Enhancement

Layer / File(s) Summary
Nanocore and micro suffix parsing implementation
apps/console/src/lib/k8s-quantity.ts, apps/console/src/lib/k8s-quantity.test.ts
parseQuantity recognizes n (nanocores via 1e9 divisor) and u (micro via 1e6 divisor) suffixes; module docs updated; unit tests verify nanocore and micro parsing including zero-nanocores and conversion precision.
Nanocore conversion in aggregation and per-node computation
apps/console/src/lib/cluster-usage/aggregate.test.ts, apps/console/src/lib/cluster-usage/per-node.test.ts
aggregateNodeResources and derivePerNodeRows tested with nanocore-form CPU metrics and Ki memory input, verifying CPU values convert to cores and memory converts to bytes correctly.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

area/console

Suggested reviewers

  • androndo

Poem

🐰 With nano-cores dancing swift and small,
A million-fold divisor catches all,
From metrics-server's micro-measure true,
CPU cores bloom where nanocores flew. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: adding support for parsing nano and micro CPU quantity suffixes from metrics-server in the cluster-usage module.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/cpu-usage-nanocore-parse

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added size/M This PR changes 30-99 lines, ignoring generated files area/uncategorized PR auto-labeler could not map title scope to a known area/*; please review kind/bug Categorizes issue or PR as related to a bug labels Jun 1, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@lexfrei
Aleksei Sviridkin (lexfrei) marked this pull request as ready for review June 1, 2026 12:04
@lexfrei
Aleksei Sviridkin (lexfrei) merged commit fc63158 into main Jun 1, 2026
6 checks passed
@lexfrei
Aleksei Sviridkin (lexfrei) deleted the fix/cpu-usage-nanocore-parse branch June 1, 2026 12:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area/uncategorized PR auto-labeler could not map title scope to a known area/*; please review kind/bug Categorizes issue or PR as related to a bug size/M This PR changes 30-99 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants