fix(platform-connectors): dedupe node events without full-range event LISTs #1582
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
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.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1582"
general
weight: 0.35
HarshavardhanK
Summary
K8sConnector.writeNodeEvent(platform-connectors/pkg/connectors/kubernetes/process_node_events.go) deduplicates node events by listing every event for the node:involvedObject.nameis 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 ametadata.namefield selector. The apiserver resolves an exact-name selector asmatchesSingle, turning it into a single-key storage lookup instead of a range scan.LIST fieldSelector=metadata.name=<cached-name>, then bumpCount+LastTimestampviaUpdate(unchanged from before).Createa fresh event.Create, and cache the returned name.The cache is a 1024-entry LRU (the
golang-lru/v2dependency this module already uses), so overflow evicts one least-recently-used entry rather than flushing.retry.OnErrorsemantics, thenodeEventOperationsCountermetrics, and the trace spans are all preserved exactly.Why a
metadata.nameLIST and not a GETThis is the part worth flagging for review. The obvious implementation is
Events().Get(ctx, name, ...), but the shipped chart's ClusterRole grantseventsonlycreate,update,list— notget:https://github.com/NVIDIA/NVSentinel/blob/main/distros/kubernetes/nvsentinel/templates/clusterrole.yaml#L37-L44
We built a GET-based version first and it failed with
403 Forbiddenon 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. Themetadata.nameLIST 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
getto 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
Component(s) Affected
Testing
Existing suite, unchanged:
go vetclean,gofmtclean. The existingTestK8sConnector_WithEnvtest_EventCountIncrementalready covers the dedupe-and-increment path and passes unmodified.New test —
TestK8sConnector_WithEnvtest_EventDedupeCacheRecoverycovers 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 atCount=1, not error), and a restarted connector with an empty cache (must create a second event rather than silently doing nothing).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.erron the node):CREATE, no LIST.Count1 → 2, with the audited request beingLIST ...?fieldSelector=metadata.name%3D<name> -> 200— a single-key lookup.involvedObjectLISTs after the patch; zeroERRORlog 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 declarego 1.26.0, so it panics withpackage 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:writeNodeEventcognitive complexity is unchanged at 16, and cyclomatic complexity drops from 10 to ≤8, socyclop/gocognitshould not regress. No line exceeds thellllimit of 120. CI will be the real check here.Checklist
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
Summary by CodeRabbit
- 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 -->