Skip to content

feat: Summarize usage and cost per node label - #538

Open
sule26 wants to merge 2 commits into
awslabs:mainfrom
sule26:main
Open

sule26 wants to merge 2 commits into
awslabs:mainfrom
sule26:main

Conversation

@sule26

@sule26 sule26 commented Sep 23, 2026

Copy link
Copy Markdown

Motivation

The viewer shows the cluster total at the top and each node at the bottom, with nothing in
between. With 40 nodes across 4 nodepools you get 1 number and 40 numbers, and none of the 4
you want. The workaround is one terminal per nodepool.

What this adds

--group-by <label>[=v1,v2] aggregates every node sharing a value for a label, and
--groups-only hides the per-node list to leave just that summary. g toggles the list at
runtime.

6 nodes  (   98304Mi/377175Mi)  26.1% memory  ██████████░░░░  $4.608/hour | $3,363.840/month
48 pods (0 pending 48 running 48 bound)

default  4 nodes  32 pods  (65536Mi/251450Mi)  26.1% memory  ██████████░░  $3.072/hour | $2,242.560/month
gpu      2 nodes  16 pods  (32768Mi/125725Mi)  26.1% memory  ██████████░░  $1.536/hour | $1,121.280/month
eks-node-viewer --group-by karpenter.sh/nodepool
eks-node-viewer --group-by karpenter.sh/nodepool=default,gpu --groups-only
eks-node-viewer --group-by company.com/team

The label is any node label, so nodepool, zone, capacity type or your own team label are the
same flag with a different key. Values are optional and only narrow the node selection when
given, so a bare label keeps nodes without it visible in a <none> group. The percentage is
weighted by node size rather than the mean of each node's percentage, since an idle
m5.24xlarge next to a busy t3.medium should not read as half used.

Fixes along the way

  • Header pod counts ignored --node-selector. The filter looked up c.nodes by node name
    but the map is keyed by provider ID, so it never matched and the header counted every pod in
    the cluster. bound is now the pods on the nodes being displayed, which also makes it agree
    with the group totals. Unscheduled pods stay counted, as they belong to no node.
  • Memory is displayed in Mi. Kubelet reports Ki and quantities keep their scale, so a
    summed cluster read 386227344Ki.
  • computeItemsPerPage could return zero and the paginator divides by it, so a short
    terminal could panic.

Performance

A redraw was dominated by two things: sort keys rebuilt on every comparison, and
natsort.Compare, whose backtracking regexp accounted for 87% of a frame's allocations.
Keys are now built once per node, the comparison walks the strings in place, and the progress
bars are cached instead of interpolating a colour per cell every frame.

With 200 nodes and 4200 pods, against this branch's base on the same machine:

before after
frame, default sort 2.02 ms 1.19 ms
frame, sorted by a computed label 12.4 ms ~1.7 ms
Cluster.Stats() 607 µs / 416 allocs ~300 µs / 19 allocs

Testing

7 new tests, 25 in total, pkg/model coverage at 47.0%. gofmt -s, go vet, go build and
go mod tidy are clean. Reverting the pod count fix makes its test fail, which the existing
suite did not catch.

Not run against a real cluster, so the selector built from --group-by is verified at the
selector string level.

Out of scope

go test -race reports data races with or without this change, 9 on the base commit against
16 here, same root causes: the public Node.Price is written without a lock while the
renderer reads it, and IsOnDemand/IsAuto/Labels read the label map unlocked. Happy to
open a separate PR. Same for ColorTabWriter appending a byte at a time and
config.LoadDefaultConfig running twice at startup.

@sule26
sule26 requested a review from a team as a code owner September 23, 2026 20:49
@sule26

sule26 commented Sep 24, 2026

Copy link
Copy Markdown
Author

@tzneal Sorry for tagging you, but I thought nobody would see a new PR in this repo if I didn't do it.

I was really hoping this could get merged so it could help other people as well.

@karlipegomes

Copy link
Copy Markdown

This is a really valuable feature. Grouping by node labels is something that’s genuinely missing when you’re dealing with larger clusters, especially with multiple node pools. Being able to see the aggregated view instead of having to open a terminal per node pool makes the viewer much more useful in real-world environments.

Great work also on the performance improvements and the fixes along the way. This is a very solid PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants