← Back to Pull requests

fix(platform-connectors): dedupe node events without full-range event LISTs #1582

Closed
unknown closed this pull request without merging on Aug 17, 2026 07:39 UTC
View on GitHub
unknown unknown commented on Aug 11, 2026 06:55 UTC
Author

Summary

K8sConnector.writeNodeEvent (platform-connectors/pkg/connectors/kubernetes/process_node_events.go) deduplicates node events by listing every event for the node:

events, err := r.clientset.CoreV1().Events(DefaultNamespace).List(ctx, metav1.ListOptions{
    FieldSelector: fmt.Sprintf("involvedObject.name=%s", nodeName),
})

involvedObject.name is not an index-served selector, and core events bypass the apiserver watch cache, so every call makes the apiserver read the entire default-namespace events range out of etcd and filter it in memory. The call fires once per unhealthy, non-fatal health event per node.

Impact

On a healthy fleet this is close to zero traffic. During a fleet-wide health-event storm every affected node's connector issues full-range etcd scans, with conflict retries on top — precisely when etcd is already under incident load and the events range is at its largest. Cost is O(nodes x events-range size), i.e. quadratic in cluster size during correlated failures.

Measured on a 1,152-node production cluster during an incident: 468–557 etcd read objects/s per apiserver instance attributable to these LISTs, roughly a 500x fetched-to-returned amplification.

Fix

Cache the name of the last event written per (node, type, reason, message) on the connector, and resolve the dedupe read with a metadata.name field selector. The apiserver resolves an exact-name selector as matchesSingle, turning it into a single-key storage lookup instead of a range scan.

  • Cache hit → LIST fieldSelector=metadata.name=<cached-name>, then bump Count + LastTimestamp via Update (unchanged from before).

  • Empty result (event deleted or TTL-expired) → drop the cache entry and Create a fresh event.

  • Cache miss → Create, and cache the returned name.
  • The cache is a 1024-entry LRU (the golang-lru/v2 dependency this module already uses), so overflow evicts one least-recently-used entry rather than flushing. retry.OnError semantics, the nodeEventOperationsCounter metrics, and the trace spans are all preserved exactly.

    Why a metadata.name LIST and not a GET

    This is the part worth flagging for review. The obvious implementation is Events().Get(ctx, name, ...), but the shipped chart's ClusterRole grants events only create, update, list — not get:

    https://github.com/NVIDIA/NVSentinel/blob/main/distros/kubernetes/nvsentinel/templates/clusterrole.yaml#L37-L44

    - apiGroups:
      - ""
      resources:
      - events
      verbs:
      - create
      - update
      - list
    

    We built a GET-based version first and it failed with 403 Forbidden on a live cluster running the chart's own RBAC. envtest does not catch this — it runs with admin credentials, so the GET version passes the whole suite. The metadata.name LIST costs the same as a GET server-side (single-key lookup, no range scan) and requires zero RBAC migration, which also means no version-skew window between chart and image during upgrade.

    If you would rather add get to the ClusterRole and use a plain GET, happy to do it that way — but the LIST form avoids the chart/image ordering problem entirely.

    Behavior change

    After a connector restart the cache is empty, so the first occurrence of a recurring fault creates a fresh event instead of incrementing the pre-restart one. Subsequent occurrences deduplicate as before. This is a bounded, one-event-per-fault-per-restart cost and is covered by a new test.

    Type of Change


  • 🐛 Bug fix

  • ✨ New feature

  • 💥 Breaking change

  • 📚 Documentation

  • 🔧 Refactoring

  • 🔨 Build/CI
  • Component(s) Affected


  • Core Services

  • Documentation/CI

  • Fault Management

  • Health Monitors

  • Janitor

  • Other: platform-connectors
  • Testing

    Existing suite, unchanged:

    $ GOTOOLCHAIN=auto go build ./...
    $ go test ./pkg/connectors/kubernetes/...
    ok  	github.com/nvidia/nvsentinel/platform-connectors/pkg/connectors/kubernetes	53.891s
    

    go vet clean, gofmt clean. The existing TestK8sConnector_WithEnvtest_EventCountIncrement already covers the dedupe-and-increment path and passes unmodified.

    New test — TestK8sConnector_WithEnvtest_EventDedupeCacheRecovery covers the two paths where the cache does not resolve to a live event: the cached event was deleted out from under the connector (must create a fresh event at Count=1, not error), and a restarted connector with an empty cache (must create a second event rather than silently doing nothing).

    === RUN   TestK8sConnector_WithEnvtest_EventCountIncrement
    --- PASS: TestK8sConnector_WithEnvtest_EventCountIncrement (3.13s)
    === RUN   TestK8sConnector_WithEnvtest_EventDedupeCacheRecovery
    --- PASS: TestK8sConnector_WithEnvtest_EventDedupeCacheRecovery (4.01s)
    PASS
    

    Live-cluster validation — the patched image has been running as a production canary. On a 3-node cluster with the real chart RBAC and synthetic non-fatal Xid injection (logger -p kern.err on the node):

  • First injection: event CREATE, no LIST.

  • Identical re-injection: Count 1 → 2, with the audited request being LIST ...?fieldSelector=metadata.name%3D<name> -> 200 — a single-key lookup.

  • Connector restart + re-injection: fresh event object created, no errors (the documented restart semantics).

  • Zero full-range involvedObject LISTs after the patch; zero ERROR log lines.
  • Note on make lint: I could not run it locally. golangci-lint v2.5.0 (pinned in .versions.yaml) is itself built with go1.25, and the modules declare go 1.26.0, so it panics with package requires newer Go version go1.26 (application built with go1.25) during type-checking. latest (v2.12.2) is also go1.25-built and panics identically. As a proxy I measured the complexity linters directly: writeNodeEvent cognitive complexity is unchanged at 16, and cyclomatic complexity drops from 10 to ≤8, so cyclop/gocognit should not regress. No line exceeds the lll limit of 120. CI will be the real check here.

    Checklist


  • Self-review completed

  • Documentation updated (if needed) — no user-facing docs affected

  • Ready for review
  • <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    Summary by CodeRabbit

  • Bug Fixes

  • - Improved Kubernetes node health event deduplication to prevent duplicate recurring events.
    - Added recovery handling so missing or deleted events are recreated correctly with accurate counts.
    - Ensured restarted connector instances create distinct events when prior deduplication state is unavailable.
    - Improved reliability when processing large numbers of node health events.
    - Prevented update races from causing errors and preserved accurate event tracking during high-volume activity.
    - Updated Kubernetes permissions to support reliable event recovery and updates.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: HarshavardhanK Review duration: 8683m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    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.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1582"
    general weight: 0.35
    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: 52% (MEDIUM) · Higher = larger blast radius
    52%
    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: 20.5% · Safe to merge
    20.5%