Skip to content

Introduce Event-Driven Docker Discovery #394

Closed

Description

@RentnerKev

Analysis baseline: main @ 3ec3455 — 9 November 2026.

Priority: P2

Context / Current Behavior

Native Docker observation is already event-driven in Rust. The controller subscribes to filtered /events before taking an inventory, debounces relevant changes for 500 ms, rotates the subscription/rescans after 60 seconds and reconnects with bounded backoff. Configuration changes cancel the old observation. The client bounds event decoding and inventory work and rejects incomplete inventory as an authoritative empty result.

The remaining polling is in Bun: discovery-worker checks the registry every two seconds and, when enabled, fetches controller state and reconciles PostgreSQL-owned hosts. Even disabled discovery repeatedly reads its registry, although it correctly avoids controller/Docker requests.

Problem Statement

Rebuilding the Docker watcher would duplicate functioning infrastructure. The useful missing work is efficient, reliable controller-to-Bun change notification and avoiding repeated no-change/disabled database reconciliation, without losing database-originated changes or recovery after missed events.

Proposed Architecture / Solution

Keep native socket/API access and event observation in Rust; retain adoption rules, authorization, PostgreSQL writes, audits and proxy-apply coordination in Bun. Evaluate authenticated bounded long-poll or a revisioned invalidation endpoint for controller inventory snapshots. Use a runtime/store identity plus monotonic snapshot generation: connector configuration revision alone does not identify changed candidates.

Treat invalidations as coalesced hints. Bun always reads an authoritative complete snapshot; a low-frequency reconciliation fallback covers lost events and restarts. PostgreSQL-originated permission/configuration/ownership changes must also wake reconciliation even when Docker is unchanged.

Implementation Scope

  • Retain and verify filtering for create/remove/start/stop, relevant labels/configuration through recreate/update and applicable network changes.
  • Define inventory generation, restart/reset, endpoint replacement, acknowledgement/resync and consumer compatibility semantics.
  • Coalesce bursts into one running cycle plus a bounded dirty marker; a change during an in-flight pass must trigger one follow-up for the latest state.
  • Avoid unconditional registry queries when disabled through safe local/post-commit invalidation plus a documented bounded external-change fallback.
  • Keep a periodic complete reconciliation and reconnect/resync behavior for missed Docker or controller-to-Bun events.
  • Preserve the current 16-attempt/10-second fair reconciliation batch and idempotent no-op behavior. Do not add a durable unbounded raw Docker event queue.
  • Measure enabled-idle and disabled-idle requests/transactions and event-to-committed-host/apply latency before/after.

Security and Reliability Considerations

Docker metadata remains untrusted. Preserve the constrained GET-only client, endpoint validation, bounded bodies/deadlines and no redirect/proxy bypass. A read-only socket mount is not an API permission boundary; do not broaden socket access or put it in the web user.

Only a complete, ready, non-stale snapshot matching the active configuration revision and endpoint hash may mutate owned hosts. Revalidate the delegated actor's grants inside the transaction. Retain manual-host ownership, detached tombstones, manual disablement and the rule that missing/stopped/unavailable containers do not silently delete/disable hosts. Database and audit commit precede runtime application.

Acceptance Criteria

  • Record the existing approximately 30 two-second cycles/minute baseline; show a material measured reduction in idle controller reads/reconciliation transactions with numeric fallback/latency bounds.
  • Stable disabled discovery performs no recurring discovery database reads until a relevant invalidation or its explicitly bounded safety fallback, and makes zero controller/Docker discovery calls.
  • Bursts, continuous event floods and changes arriving during a pass keep memory and pending work bounded and eventually reconcile the latest inventory fairly.
  • Lost invalidations, daemon/controller/Bun restarts and reconnects resync from authoritative state without losing eligible updates.
  • Stale generations, old endpoints, incomplete inventories and revoked actor permissions never mutate hosts.
  • DB-originated edits and pending proxy applies still converge without waiting for a new Docker event.
  • Existing audit, rollback, no-adoption, no-destructive-absence and no-op/no-unnecessary-reload tests remain valid.

Testing Requirements

Extend existing Rust connector/event-stream tests and Bun discovery worker/database tests instead of duplicating them. Cover duplicate/out-of-order events, network/recreate bursts, EOF versus transport failure, snapshot generation reset, lost wakeup, disabled-to-enabled transition, actor revocation, config replacement mid-scan, shutdown/restore and bounded fallback. Reuse the real isolated discovery smoke and add event-burst/idle-query evidence to #397. Preserve traffic assertions for the existing #171; this issue does not resolve that separate reload defect.

Dependencies / Related Issues

#234/#235/#236 implemented the native watcher and ownership model; do not reopen or repeat them. #401 confirms the existing Rust/Bun boundary. Coordinate bounded wakeups with #400, lifecycle cancellation with #395 and focused fixtures with #397. This improvement can proceed independently of monitoring or notification migrations. No additional mandatory infrastructure is in scope.

Relevant Source Files

Activity

  1. added this to the 3.2 milestone on Nov 9, 2026
  2. added
    enhancement
    area: runtime
    area: docker
    on Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: dockerarea: runtimeenhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions