← Back to Pull requests

[OTELS-1029] fix(quantile): bound InsertInterpolate key iteration #51644

Closed
unknown closed this pull request without merging on Jul 02, 2026 15:13 UTC
View on GitHub
unknown unknown commented on Jun 02, 2026 12:29 UTC
Author

What does this PR do?

Fixes an unbounded loop in pkg/util/quantile/(Agent).InsertInterpolate that 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); when agentConfig.key(upper) saturated at uvinf (32767) for very large finite upper bounds, k++ wrapped to -32768 and the loop never terminated, growing the local keys slice unboundedly.

Changes:

  • Widen the loop counter to int32 so it cannot wrap around the int16 Key range.

  • Pre-size keys with the now-known range and reject ranges outside the legitimate Key space (maxInterpolateKeys = 2uvinf + 1).

  • Move the non-monotonic-bounds check ahead of allocation; add a new ErrKeyRangeTooLarge for the (currently unreachable, defense-in-depth) over-range case.

  • Add TestAgentInterpolationBoundedKeys covering 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 InsertInterpolate call held ~482 MB of live keys slice (inuse_objects == 1 with inuse_space == 481.98 MB, ~241 M int16 entries — far beyond the legitimate ~65 K-key range). The frame would never return; eventually the process OOMs.

    Reproducer: InsertInterpolate(1, 1e300, count) — 1e300 is finite but maps past maxKey, so key(upper) returns InfKey(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 new TestAgentInterpolationBoundedKeys subtests.

  • dda inv linter.go --targets=./pkg/util/quantile — 0 issues.

  • Built an otel-agent image patched with this fix (agent:7.78.3-full-fixed) and confirmed the previously-hanging ingest path now terminates normally on the local cluster.
  • Additional Notes

  • The new ErrKeyRangeTooLarge is currently unreachable given Key is int16 (max possible n equals maxInterpolateKeys); it's kept as a guard in case Key is widened later.

  • Caller side (pkg/opentelemetry-mapping-go/otlp/metrics/default_mapper.go) collapses only the +Inf / -Inf cases — it does not detect "finite but past gamma^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

    Diff: 338 lines (+253 / -85) across 4 files Reviewer: truthbk Review duration: 43364m
    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
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.2% (MEDIUM) · Higher = larger blast radius
    42.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.7% · Safe to merge
    16.7%