[OTELS-1029] fix(quantile): bound InsertInterpolate key iteration #51644
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.42 · 338 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.349
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #51644"
general
weight: 0.35
truthbk
What does this PR do?
Fixes an unbounded loop in
pkg/util/quantile/(Agent).InsertInterpolatethat can drive the otel-agent process into OOM when it ingests an OTel explicit-bucket histogram with a very large finite upper bound.The loop counter was a
Key(int16); whenagentConfig.key(upper)saturated atuvinf(32767) for very large finite upper bounds,k++wrapped to-32768and the loop never terminated, growing the localkeysslice unboundedly.Changes:
int32so it cannot wrap around theint16Keyrange.keyswith the now-known range and reject ranges outside the legitimateKeyspace (maxInterpolateKeys = 2uvinf + 1).ErrKeyRangeTooLargefor the (currently unreachable, defense-in-depth) over-range case.TestAgentInterpolationBoundedKeyscovering the saturating-upper-bound case (the original infinite-loop repro), non-monotonic bounds, and equal bounds.Motivation
Captured in a heap profile from a production-like otel-agent: a single in-flight
InsertInterpolatecall held ~482 MB of livekeysslice (inuse_objects == 1withinuse_space == 481.98 MB, ~241 Mint16entries — far beyond the legitimate ~65 K-key range). The frame would never return; eventually the process OOMs.Reproducer:
InsertInterpolate(1, 1e300, count)—1e300is finite but maps pastmaxKey, sokey(upper)returnsInfKey(1) == uvinf, and the pre-fix loop wraps forever.Linked ticket: OTELS-1029.
Describe how you validated your changes
dda inv test --targets=./pkg/util/quantile— 88/88 pass, including the newTestAgentInterpolationBoundedKeyssubtests.dda inv linter.go --targets=./pkg/util/quantile— 0 issues.agent:7.78.3-full-fixed) and confirmed the previously-hanging ingest path now terminates normally on the local cluster.Additional Notes
ErrKeyRangeTooLargeis currently unreachable givenKeyisint16(max possiblenequalsmaxInterpolateKeys); it's kept as a guard in caseKeyis widened later.pkg/opentelemetry-mapping-go/otlp/metrics/default_mapper.go) collapses only the+Inf/-Infcases — it does not detect "finite but pastgamma^maxKey". A follow-up to collapse the saturating case at the caller could be a nice-to-have, but the loop-side fix in this PR is the necessary safety net.[OTELS-1029]: https://datadoghq.atlassian.net/browse/OTELS-1029?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ