refactor: consider migrating from hashicorp/golang-lru/v2/expirable to jellydator/ttlcache/v3
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Tái cấu trúc
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- go
- Lĩnh vực
- backend, performance, testing
Hướng nghiên cứu
Start by reviewing the listed cache call sites, beginning with pkg/processtree/process_tree_manager.go and pkg/rulebindingmanager/cache/cache.go, then inspect the existing golang-lru usage and run the relevant tests. Compare golang-lru with ttlcache using the requested parallel, allocation, lifecycle, and end-to-end benchmarks. Done means the benchmark criteria are met, remaining call sites are migrated, imports are removed where applicable, and leak coverage is added for stoppable caches.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Problem Statement
Several subsystems across node-agent currently use github.com/hashicorp/golang-lru/v2/expirable for in-memory TTL/LRU caching:
- Process Tree:
pkg/processtree/process_tree_manager.go(containerProcessTreeCache) - Rule Manager & CEL Libraries:
pkg/rulemanager/rule_manager.go(alertLogDedup)pkg/rulebindingmanager/cache/cache.go(rulesForPod)pkg/rulemanager/rulecooldown/rulecooldown.go(cooldownMap)pkg/rulemanager/ruleadapters/creator.go(hashCache)pkg/rulemanager/cel/libraries/cache/function_cache.go(CEL function cache)pkg/rulemanager/cel/libraries/containerprofile/prestop_cache.go(prestop_cache)
- SBOM Manager:
pkg/sbommanager/v1/sbom_manager.go(failureRetries,crashLoopRetries,busyRetries) - Host FIM Sensor:
pkg/hostfimsensor/v1/dedup_cache.go(dedupCache)
Limitations of golang-lru/v2/expirable:
- Uncloseable Background Goroutines: In
golang-lruv2.0.7,expirable.NewLRUspawns a background ticker goroutine (deleteExpired) that runs indefinitely because the package does not provide aClose()method (explicitly noted in upstream comments inexpirable_lru.goand upstream issue #159 / PR #161). While acceptable for node-agent startup singletons, any stoppable or dynamically created component leaks goroutines on shutdown. - Release Stagnation: The upstream repository is in low-touch maintenance; the last tagged release (
v2.0.7) was published in September 2023.
Proposed Solution
Evaluate and migrate from hashicorp/golang-lru/v2/expirable to github.com/jellydator/ttlcache/v3.
Why jellydator/ttlcache/v3?
- Explicit Lifecycle Control: Exposes
Start()andStop()methods for background expiration, or can run in purely passive/lazy eviction mode without spawning any background goroutines. - Modern Go Generics: Type-safe (
ttlcache.Cache[K, V]). - Flexible Eviction & Sizing: Supports capacity bounds with LRU / FIFO eviction policies.
- Active Maintenance: Widely adopted in the Go ecosystem as a standard replacement for
go-cacheand unmaintained expirable caches.
Benchmarking & Performance Requirements
Because several of these caches sit on critical, high-frequency event processing paths (e.g. ProcessTreeManager on every event, rulesForPod on every pod evaluation), the migration must satisfy the following benchmarking criteria:
- Hot-Path Concurrency & Latency (
Benchmark*):- Implement comparative Go microbenchmarks using
testing.B.RunParallelcomparinggolang-lru/v2vsjellydator/ttlcache/v3. - Test under representative access patterns:
- Read-heavy (90% read / 10% write) hit scenarios.
- Miss-heavy and high-churn insertion scenarios.
- Measure lock contention and ensure p95/p99 operation latencies do not regress.
- Implement comparative Go microbenchmarks using
- Memory Footprint & Allocation Overhead:
- Measure
B/opandallocs/opwithgo test -benchmem. - Profile heap allocations and verify that memory usage remains stable under sustained maximum entry capacity.
- Compare performance and memory overhead between active background sweeper mode vs passive (lazy on-access) eviction mode.
- Measure
- Goroutine Lifecycle & Leak Verification:
- Automated tests must verify that stopping or discarding caches leaves zero running background goroutines (e.g. using
go.uber.org/goleakorruntime.NumGoroutine()).
- Automated tests must verify that stopping or discarding caches leaves zero running background goroutines (e.g. using
- End-to-End System Benchmark:
- Validate against the existing node-agent performance benchmark suite (
make benchmark/ CI performance workflow) to ensure no regressions in overall node-agent CPU utilization and event throughput under load.
- Validate against the existing node-agent performance benchmark suite (
Implementation Plan
- Implement comparative microbenchmarks (
golang-lruvsttlcache/v3) covering read/write contention and memory allocations. - Prototype
ttlcache/v3in one subsystem (e.g.pkg/processtreeorpkg/rulebindingmanager). - Validate microbenchmark and CI benchmark results against the baseline.
- Migrate remaining
expirable.LRUcall sites across the codebase. - Remove
github.com/hashicorp/golang-lru/v2/expirableimports where applicable. - Add goroutine leak tests for all stoppable cache instances.
- Ngôn ngữ chính
- Go
- Star
- 39
- Fork
- 42
- Merge trung bình
- 1 ngày 18 giờ
- Pull request đã merge (30 ngày)
- 40
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của kubescape/node-agent
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
kubescape/node-agent#1099 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
kubescape/node-agent#1093 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Upgrade Inspektor Gadget to v0.57.0 via kubescape fork and preserve exec/path semanticsCó thể đã có người làm @ANAMASGARD đã nhận 18 ngày trước. Đang mởenhancement
kubescape/node-agent#1050 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Scan container images for misplaced secretsCó thể làm lại được @khuswant18 đã nhận 48 ngày trước và không có pull request nào đang mở. Đang mở
kubescape/node-agent#987 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
kubescape/node-agent#963 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của kubescape/node-agent
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
-
evener-transcript-v2-upgrade tool still scans transcript files through bufio's 4 KiB default bufferĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
prime-radiant-inc/evener#6370 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
ManageSieve proxy: a backend's NO/BYE greeting is skipped as a capability line and reported as EOFĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Mend: dependency security vulnerability
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
Mend: dependency security vulnerability
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
ManageIQ/manageiq-pods#1476 ·
Maintainer thường phản hồi trong vòng 1 ngày