ktop Release v0.7.8
ktop v0.7.8 resolves unbounded memory growth and scrape-time heap spikes in the built-in Prometheus metrics collector (#176), fixes ~/.ktop/config.yaml Prometheus configuration loading, and updates Prometheus and CLI memory-tuning documentation.
Detailed Changes by Category
1. Prometheus Store & Ring Buffer Memory Fixes (prom)
- Lazy Ring Buffer Allocation (
prom/ring_buffer.go):RingBuffernow allocates backing storage lazily starting at 16 slots and doubles up to its configured capacity rather than pre-allocatingMaxSamples(10,000 × 24 bytes = 240 KB) immediately per series.Clear()zeroes backing elements to avoid retaining references. - Retention-Bounded Per-Series Capacity (
prom/storage.go):InMemoryStorebounds effective per-series ring buffer capacity to whatRetentionTime / ScrapeInterval(+ headroom) can produce, clamped toMaxSamples, preventing long-running active series from growing to 10,000 slots over extended uptime. - Metadata & Stale Series Reclamation (
prom/storage.go,prom/controller.go):- Removed the unbounded
stringHandlesmap and delegatedInternStringdirectly tounique.Make(s).Value()so interned strings for deleted pods, containers, and cgroup paths are eligible for garbage collection. - Rebuilt
labelNamesandlabelValuesand compacted heavily shrunk per-metric series maps duringcleanupExpiredSamples. - Capped the periodic cleanup interval to at most 2 minutes so expired series are reclaimed promptly.
- Removed the unbounded
- Reduced Query Allocations (
prom/storage.go): AddedQueryLatestPerSeriesfor single-sample lookups and batch-allocatedMetricSampleslices inQueryRangePerSeries.
2. Streaming Scrape Filtering & cAdvisor Cardinality Reduction (prom/scraper.go)
- Stream-Filtered Parsing:
scrapeTargetstreams responses viareq.Streamand filters Prometheus exposition lines againstDefaultMetricAllowlistbefore invokingexpfmt.TextParser, avoiding protobuf DTO allocation for non-allowlisted metric families. - Bounded Node Concurrency:
scrapeAllTargetscaps concurrent node scrapes at 6 to bound peak heap usage on multi-node clusters. - cAdvisor Series Filtering: Drops unqueried cAdvisor series during ingestion—including non-root/non-pod systemd and slice cgroups (
/system.slice/*,/kubepods.slice), pause containers (container="POD"), per-core pod CPU series, pod-level network series, and non-workload CFS/PSI series—while preserving all queried node (id="/", including cgroups v1 per-core CPU fallback) and pod/container series (including static-podcontainer=""memory fallback).
3. Refresh Allocation & Config Wiring Fixes (metrics/prom, k8s, views/node, cmd, docs)
- Latest-Sample Memory Lookups (
metrics/prom/prom_source.go):GetAllPodMetricsandqueryLatestSumFiltereduseQueryLatestPerSeriesfor working-set memory instead of scanning 5-minute ranges on every 3-second pod refresh. - Informer Read Without Deep Copy (
k8s/pods_controller.go):GetPodModelsreads node allocatable resources directly from the node informer lister without deep-copying fullNodeobjects. - Reusable Node Info Header (
views/node/detail.go): Reuses a singletview.TextViewindrawInfoHeaderacross refreshes. - Config File Prometheus Settings (
cmd/ktop.go): Appliedmetrics.scrape_interval,metrics.retention,metrics.max_samples, andmetrics.componentsfrom~/.ktop/config.yamlwhen not overridden by CLI flags. - Documentation (
docs/prometheus.md,docs/cli.md): Updated default--prometheus-scrape-intervaldocumentation to5sand added a Memory Tuning guide covering CLI flags,~/.ktop/config.yaml,--ksm=off,--metrics-source=metrics-server, andGOMEMLIMIT.
Upgrade & Compatibility Notes
- Backward Compatibility: Fully backward compatible with existing CLI flags,
kubectl ktopplugin usage,~/.ktop/config.yamlfiles, and--nouiJSON/JSONL output. - Deprecations & Retractions: None.
- Migration Actions: None required. Existing
~/.ktop/config.yamlfiles withmax_samples: 10000benefit automatically from lazy ring-buffer allocation and retention-bounded per-series caps.
Repository Metrics
14 files changed, 937 insertions(+), 200 deletions(-)
- Documentation: