The Wire · Showcase
KSM CUTS ALLOCATIONS 85 PERCENT, FIXES REAPER GOROUTINE LEAK
By RepoJournal · Filed · About Kubernetes
Kube-state-metrics shipped three performance fixes that eliminate per-scrape allocations and close a goroutine leak that multiplies with every config reload.
The big win lands in header sanitization: kube-state-metrics now precomputes per-store headers once at startup instead of re-parsing them on every scrape, slashing allocations by 85 percent [1]. That same PR cuts metric generation allocations across the board through strategic reuse of buffers and objects on the per-event path. Meanwhile, a critical bug fix stops StartReaper from spawning duplicate goroutines on every config reload [2]. The reaper runs as pid 1 and has no stop path, so each reload left another blocked goroutine behind, never collected because the signal package holds a reference to it. Reproduced with five reloads yielding five goroutines [3]. A separate modernization pass replaces sort.StringSlice and math.Min with Go 1.21 standard library facilities [4], and discovery now correctly filters out non-served CRD versions [5]. Infrastructure updates push boskos to v20260730-11fb0c8 and prow to v20260810-20590a839 [6], while token endpoint handling lands in cloud armor rules to unblock registry.k8s.io work [7].
One email a day. Unsubscribe in one click.
Keep up with Kubernetes in about 3 minutes a day: what actually shipped — the commits, pull requests, releases, and security advisories that matter.
One email a day. Unsubscribe in one click. Read a past issue →
Action items
- → Upgrade kube-state-metrics to capture the 85% header allocation reduction kubernetes/kube-state-metrics [plan]
- → If running KSM as pid 1 with config reloads, patch immediately to stop goroutine leak kubernetes/kube-state-metrics [immediate]
- → Review CRD discovery changes to confirm non-served versions are properly filtered kubernetes/kube-state-metrics [monitor]
References
- [1] perf: reduce allocations in metric generation and header sanitization ↗ kubernetes/kube-state-metrics
- [2] fix(proc): start the reaper only once ↗ kubernetes/kube-state-metrics
- [3] fix(proc): start the reaper only once kubernetes/kube-state-metrics
- [4] chore: modernize using slices, min builtin, and %w error wrapping ↗ kubernetes/kube-state-metrics
- [5] fix: Ignore non-served CRD versions in discovery ↗ kubernetes/kube-state-metrics
- [6] Update boskos to v20260730-11fb0c8, prow to v20260810-20590a839 ↗ kubernetes/k8s.io
- [7] add token endpoint to archeio's cloud armor rules ↗ kubernetes/k8s.io