← Back to Pull requests

feat(discovery): add lock-free EndpointSlice ready-endpoint store #9952

Open
unknown opened this pull request with 378 lines diff across 4 files
View on GitHub
unknown unknown commented on Dec 03, 2026 07:46 UTC
Author

Description

Problem

SMG's Gateway API mode needs lock-free resolution of ready Kubernetes Service endpoints from discovery.k8s.io/v1 EndpointSlice objects — covering both standard selector-backed Services and selector-less / controller-managed EndpointSlices carrying IPv4, IPv6, or FQDN addresses.

Solution

Add an isolated endpoint_slice module behind the existing kubernetes feature in smg-service-discovery providing pure slice resolution and a lock-free ArcSwap-backed EndpointSliceStore driven by kube::runtime::watcher.

Changes

  • Added crates/service_discovery/src/endpoint_slice.rs:

  • - SERVICE_NAME_LABEL (kubernetes.io/service-name), ServiceKey, EndpointAddress (Ip(IpAddr) / Fqdn(String) with bracketed IPv6 Display), ResolvedEndpoint (authority(), url(scheme)), EndpointSnapshot
    - service_key_of and resolve_endpoint_slice: parses IPv4, IPv6, and FQDN slices; filters TCP ports (skipping port 0 and non-TCP); skips unready (conditions.ready == Some(false)) and terminating (conditions.terminating == Some(true)) endpoints
    - EndpointSliceStore: lock-free ArcSwap<EndpointSnapshot> reads (snapshot(), endpoints(ns, name), endpoints_for_port(ns, name, port_name)); incremental apply/delete, full replace_all, and atomic watch Init/InitApply/InitDone relist handling
    - watch_endpoint_slices: backoff-resilient kube::runtime::watcher driver
  • Added crates/service_discovery/tests/unit/endpoint_slice/tests.rs covering IPv4, IPv6, FQDN, unready/terminating filtering, invalid ports/addresses, multi-slice merging and deduplication, slice reassignment/deletion, port lookup, relist atomicity, and watch stream error recovery

  • Wired #[cfg(feature = "kubernetes")] pub mod endpoint_slice; + re-exports in crates/service_discovery/src/lib.rs and gated existing workspace arc-swap = "1.9.1" behind the kubernetes feature in crates/service_discovery/Cargo.toml (Cargo.lock +1 dep line, 0 new crates)
  • Refs: #8616

    Test Plan

  • cargo +nightly fmt --all -- --check: passed (exit 0)

  • python3 scripts/check_unit_test_layout.py & ./scripts/branch-name-check.sh: passed (exit 0)

  • cargo clippy -p smg-service-discovery --all-targets -- -D warnings and cargo clippy -p smg-service-discovery --all-targets --all-features -- -D warnings: passed (0 errors, 0 crate warnings)

  • cargo test -p smg-service-discovery --all-features: 230 passed; 0 failed (including all endpoint_slice::tests::* cases)

  • cargo check -p smg: passed (exit 0)
  • Release note

    none (internal smg-service-discovery primitive behind the kubernetes feature for upcoming Gateway API Service backend resolution)

    <details>
    <summary>Checklist</summary>

  • cargo +nightly fmt passes

  • cargo clippy --all-targets --all-features -- -D warnings passes

  • (Optional) Documentation updated

  • (Optional) Please join us on Slack #sig-smg to discuss, review, and merge PRs
  • </details>

    Diff: 378 lines (+283 / -95) across 4 files Reviewer: claude[bot] Review duration: 14m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.43) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 378 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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.355
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #9952"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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.9% (MEDIUM) · Higher = larger blast radius
    42.9%
    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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 22.9% · Safe to merge
    22.9%