← Back to Pull requests

feat(platform-connectors): one handler and connector set for both roles, on-change node updates and keyed inserts #1845

Closed
unknown closed this pull request without merging on Sep 17, 2026 08:12 UTC
View on GitHub
unknown unknown commented on Sep 15, 2026 10:50 UTC
Author

Summary

Part of ADR 052, the deployment platform connector. #1796 added the client library and #1814 the datastore side. This PR prepares the platform-connectors binary for its second role without adding it yet: the request handler and the connectors become one code path that both roles can use, and the connectors and pipeline stages are sized and hardened for a fleet. The deployment role itself (PC_MODE=deployment, the pkg/central package) comes in the next PR, which builds only on what is here. The wire contract is unchanged: the same PlatformConnector gRPC service, the same protobuf.

Most of this is internal, but a few changes are visible on the DaemonSet that runs today. They are listed under "What the DaemonSet sees differently" so they can be judged on their own.

What changes

  • One connector interface (pkg/connectors): Connector.ProcessBatch receives one batch. Set hands a batch to several connectors at the same time and fails with the first error, which cancels the others. BestEffort wraps a connector whose failure or timeout must not fail the batch; it is logged and counted in platform_connector_best_effort_failures_total. A ring buffer implements the interface by queueing the batch and answering at once, so the DaemonSet's handler hands each batch to a Set of its ring buffers, as before in effect.

  • One request handler (pkg/server): validate the batch, run the pipeline, hand it to the connector, answer with its result. Outcomes are counted in platform_connector_request_duration_seconds{outcome}. The handler joins the trace context a caller sends in the request metadata, and stamps an event without generatedTimestamp with the arrival time (the analyzer cannot process an event without one). The payload log level is a field, so the deployment role can log at Debug.

  • Pipeline (pkg/pipeline): ProcessBatch runs a whole batch, with an optional batch budget under which transformers that implement Prewarm prepare for the batch first (the metadata augmentor reads every node the batch names concurrently) and report what the budget cut short, so the caller can defer the batch before anything is marked. What the preparation read is kept in a per-batch scope, so the transformers use it even if the shared cache dropped it. Without a budget, the DaemonSet's case, the events are processed as they are. The pipeline construction from config.json moves into the package.

  • Store connector: InsertBatch writes one batch inside the caller's request and reports stored or duplicate; VerifyIdempotencyIndex checks the idempotency index of #1814 with its full definition. Both roles now insert with the idempotent insert: the deployment stamps keys per caller before the pipeline runs (next PR), the DaemonSet's store loop keys each queued batch itself on its first attempt and keeps the key across requeues. A duplicate on another unique index is answered with a terminal status; an empty batch is a success without a datastore call.

  • Kubernetes connector: node conditions and Events are written only when a batch changes what the node shows, Event names are derived from the fault, the Event memory is bounded per node and check, a batch is processed in timestamp order on both paths, and ProcessBatch lets the deployment role call it inside a request. NodeEventMemorySize sizes the memory for a fleet.

  • Dedup: the tracker is bounded (maxEntries, default 100000) and indexed per node and check, so a recovery visits only its own bucket, and it keys on the idempotency key so a resend of the same batch is never mistaken for a repeat of another.

  • Metadata augmentor: one read per node even when many batches name it at the same time (singleflight instead of one mutex), a read bounded to lookupTimeout (3 s) and detached from the caller, Prewarm for batches, fleet-sized client rate limit and cache through pipeline.Options, and a node label named like the reserved idempotency key field is ignored.

  • Prometheus connector and gRPC sink gain ProcessBatch, so the deployment role can call them per batch.

  • controller-runtime's logger is routed through slog, so the certificate watcher's lines appear and its "SetLogger was never called" warning is gone.

  • go.mod gains go-grpc-middleware/v2 (indirect, through the client library) and makes logr a direct requirement.
  • What the DaemonSet sees differently

    Deliberate, each small, none changes the wire contract.

  • Node updates only on change. A batch that leaves every condition's status, reason and message as they are costs no node status write (k8s_platform_connector_node_condition_update_total{status="skipped"}), and a repeat of a non-fatal fault whose Event was written less than 10 minutes ago costs no Event write. A same-fault repeat with other diagnostic text does not rewrite the message; a recovery makes the fault's next occurrence a change again. The condition's heartbeat time therefore moves only with a change (nothing in the repository reads it), and Event counts grow at most every 10 minutes instead of on every poll. On a fleet this is the largest steady-state API server load the connector produces.

  • Keyed inserts. Documents written by the DaemonSet carry metadata.idempotencyKey (instanceID#sequence#index), a batch retried after a partial write stores only the missing documents instead of the first ones twice, platform_connector_store_batches_total exists on its pods, and on PostgreSQL the insert is one row at a time. A key that arrives in an event (a derived event copied from a stored document) is overwritten instead of stored.

  • Node Event names are derived from the fault (<node>.<16 hex> of node, check, reason and message) instead of the write time, so a connector that lost its memory finds the Event it or an earlier life of the same pod wrote, and refreshes it instead of writing a second one. A batch is processed in timestamp order on both the condition and the Event path.

  • Dropped labels: node_name on k8s_platform_connector_node_event_operations_total and node on the dedup counter, because one deployment replica would carry a series per node of the fleet.

  • Smaller ones: a node metadata read is bounded to 3 s and detached from the caller (then fails open, as before); an event without generatedTimestamp is stamped with the arrival time; an empty batch is a success without a datastore call; trace context sent in the request metadata joins the trace instead of starting a new one; the per-event "Metadata augmented" line is at Debug.
  • What is not in this PR

    The deployment role itself (pkg/central: configuration, TLS listener, token validation, the idempotency-key and readiness interceptors, the no-local-node branch of pkg/auth) is the next PR. The Helm chart, the monitors' switch to publishing directly, the Tilt environment and e2e tests, and the operator documentation come after it. Reviewing this PR does not require them.

    Tests

    Unit tests, all passing, lint clean, go mod tidy clean:

  • pkg/connectors/connector_test.go: every member gets the batch, members run at the same time, the first error cancels the rest, a best-effort member's failure or timeout is counted and does not fail the batch, the caller's cancellation reaches the members.

  • pkg/server/platform_connector_server_test.go: acknowledged only when the connector accepts; a connector failure is not acknowledged; rejection happens before any side effect; a cancelled caller is reported as such; the caller's trace is joined; a retry after a failed write keeps the processing strategy; one budget covers the whole batch and a spent metadata budget defers it; queues acknowledge at once and hold the batch; a status the connector chose is passed through; defaults and timestamp stamping.

  • pkg/connectors/kubernetes (envtest): a repeat costs no status write, also when the message is saturated and compacted; a new fault joining or a partial recovery is a change; Events are written on change and refreshed after the interval; Event names are derived from the fault; a connector without memory refreshes the existing Event; the Event memory is bounded; an update racing a deletion recreates the Event.

  • pkg/connectors/store: a duplicate-only replay is success, a partial replay stores the missing events, an empty batch is terminal success, a duplicate on another index stays an error and is answered with a terminal status; the ring buffer loop keys the stored copies and keeps the key across requeues; a batch keyed by the caller keeps its keys.

  • pkg/transformers/dedup and pkg/transformers/metadata: key-aware and bounded dedup with an index that stays in step; one read per node under concurrent batches, a slow node does not block others, a spent budget starts no reads and is reported, what the preparation read outlives the shared cache for the batch.

  • pkg/pipeline, pkg/ringbuffer, pkg/connectors/prom: batch processing with and without a budget, the batch scope, queueing with the caller's trace, counting without a ring buffer.
  • Manual testing on kind with the DaemonSet role (every publisher on the socket), on Mongo and on PostgreSQL with certificate auth:

  • a repeated XID costs no status write and keeps the condition heartbeat and the node's resourceVersion, while both batches are stored under their own keys; a repeated non-fatal fault is one Event whose count grows only after a recovery;

  • an XID published during an 80 s Mongo outage is retried by the store loop and stored exactly once after Mongo returns;

  • every document written by the DaemonSet is keyed, on both datastores;

  • the upstream e2e tests for dedup, the syslog monitor (XID without metadata, cancellation uncordons the node), the gpu monitor and repeated XIDs pass through the socket; no connector pod restarted or logged an error.
  • With the deployment role PR applied on top, the same code ran the deployment scenarios (contract, fan-out, dedup, Event names across replicas, rolling restarts, Mongo outages under keyed traffic, the deployment e2e tests) on kind, and an earlier version on four dev clusters.

    Type of Change


  • 🐛 Bug fix

  • ✨ New feature

  • 💥 Breaking change

  • 📚 Documentation

  • 🔧 Refactoring

  • 🔨 Build/CI
  • Component(s) Affected


  • Health Monitor

  • Core Service

  • Fault Management

  • Janitor

  • Deployment/Config

  • API/Interface

  • Preflight

  • Plugins

  • Documentation/CI

  • New Component

  • Multiple Components

  • Other
  • Testing


  • Tests pass locally

  • Manual testing completed

  • No breaking changes (or documented)
  • Checklist


  • Self-review completed

  • Documentation updated (if needed)

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

    Summary by CodeRabbit

  • New Features

  • - Added configurable limits for deduplication memory, Kubernetes metadata caching, lookup timeouts, and client request capacity.
    - Added support for loading connector pipelines directly from raw configuration.
    - Added batch processing across connectors, Prometheus, storage, and gRPC sinks.

  • Bug Fixes

  • - Prevented duplicate Kubernetes Events and unchanged condition updates from creating unnecessary writes.
    - Preserved batch identity across retries and handled duplicate datastore submissions safely.
    - Connector processing now waits for all connectors and reports every failure.

  • Documentation

  • - Expanded metrics documentation for connector outcomes, skipped operations, and datastore batches.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: KaivalyaMDabhadkar Review duration: 2722m
    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 #1845"
    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%