fix(metrics): prevent unbounded histogram memory growth - #850
Conversation
|
Warning Review limit reached
Next review available in: 38 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
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. Comment |
Summary
Root cause
AISIX builds
metrics-exporter-prometheuswithPrometheusBuilder::build_recorder(). That low-level API does not spawn the exporter's upkeep task. Without Prometheus scrapes, each request leaves pending histogram samples in the recorder, so RSS grows approximately linearly with request count.This is the memory issue tracked from api7/AISIX-Cloud#1199. It is independent of the allocator: local glibc and jemalloc runs both showed roughly constant retained bytes per request, and an unchanged binary stopped growing when
/metricswas scraped periodically.Benchmark
GetBusbar/benchmarking, OpenAI-to-OpenAI cell, ARM64 Colima VM, 8 vCPU / 6.8 GiB, gateway pinned to 4 cores, 300-second memory load:
A second post-fix run measured 89.67 MiB peak, 87.34 MiB recovered, and -1.66 MiB/min growth.
Independent audit
render()also drains pending samples, so it did not prove the scheduler lifecycle. Resolved by factoring the upkeep loop and testing periodic execution plus cancellation with paused Tokio time.Validation
cargo test -p aisix-obs— 147 passed, 5 ignored real-cloud smoke testscargo test -p aisix-server— 87 passedcargo clippy -p aisix-obs -p aisix-server --all-targets -- -D warningscargo fmt --all -- --check