← Back to Pull requests

optimize kueue metadata streaming #57238

Closed
unknown closed this pull request without merging on Oct 05, 2026 16:34 UTC
View on GitHub
unknown unknown commented on Sep 30, 2026 20:55 UTC
Author

<!--Please give us some feedback on your experience writing this PR ! https://app.datadoghq.com/forms/43db4c02-6837-400c-8083-692e141b1b88 !-->

What does this PR do?

Optimize Cluster Agent metadata streaming by computing namespace and Kueue metadata changes once per workloadmeta event bundle and sharing the resulting update payloads across connected agents, instead of copying and comparing the full metadata inventory separately for each stream.

Pod-to-service mapping updates remain node-specific. Initial full-state synchronization, deletion handling, and full-state recovery on reconnect are preserved.

Motivation

Namespace and Kueue metadata are shared across agents, but the previous implementation repeated the same snapshot construction and comparisons for every connected stream. Profiling identified this repeated work as a significant source of CPU usage and allocations. Computing these changes once removes the main inventory-size × stream-count scaling cost.

Describe how you validated your changes

  • Ran the API package tests and five race-enabled repetitions.

  • Covered multiple subscribers, metadata updates and deletions, concurrent readers, updates arriving during sends, and send failures.

  • Compared the original per-agent snapshot/diff approach with shared computation using BenchmarkMetadataStreamFanout (five repetitions).
  • Approximate benchmark differences, rounded across the evaluated implementations:

    | Connected streams | Before: time/op | After: time/op | Before → after: allocated bytes/op |
    | ---: | ---: | ---: | ---: |
    | 1 | ~0.25 ms | ~0.25 ms | ~594 KB → ~595 KB |
    | 10 | ~2.45 ms | ~0.25–0.26 ms | ~5.94 MB → ~0.60 MB |
    | 100 | ~24 ms | ~0.26–0.27 ms | ~59.4 MB → ~0.60–0.62 MB |

    At 100 streams, this represents approximately 90× faster metadata-update processing and 99% fewer allocated bytes in the benchmark.

    Additional Notes

    The benchmark uses 1,000 seeded workloads, changes one workload per operation, and processes the update for every stream. Initial synchronization, gRPC serialization, and network I/O are excluded. These results demonstrate the reduction in redundant metadata processing, not an equivalent reduction in total production Cluster Agent CPU usage. Exact results depend on the final buffering implementation and workload.

    Diff: 289 lines (+216 / -73) across 3 files Reviewer: gjulianm Review duration: 6938m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 289 lines diff across 3 files
    0.40
    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.339
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #57238"
    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: 39.8% (MEDIUM) · Higher = larger blast radius
    39.8%
    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: 15.7% · Safe to merge
    15.7%